Anyone can help me with the SDI ?

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
#include <windows.h>
#include <commctrl.h>
#include "resources.h"
#define ID_CHARACTERS     1
#define ID_CLOSE          8
#define IDC_STATUS      103
#define IDCH_BOX1       201
#define IDCH_BOX2       202
#define IDCH_BOX3       203
#define IDCH_BOX4       204
#define IDCH_BOX5       205
#define IDCH_BOX6       206
#define IDCH_BOX7       207

LRESULT CALLBACK WindowProcedure(HWND, UINT, WPARAM, LPARAM);

void AddControls(HWND);
void loadImages();
void CheckBox1(HWND);

HWND hMainWindow, hStatic, hChBox, hChBox1, hChBox2, hChBox3, hChBox4, hChBox5, hChBox6, hChBox7;
HBITMAP hButtonImage1, hButtonImage2, hButtonImage3, hButtonImage4, hButtonImage5, hButtonImage6, hButtonImage7, hButtonImage8;
HBRUSH hbrBkgnd;

int WINAPI WinMain(HINSTANCE hInst, HINSTANCE hPrevInst, LPSTR args, int nCmdShow)
{
    InitCommonControls();
    WNDCLASSW wc = {0}; /* Data structure for the window class */
    wc.hbrBackground    = (HBRUSH)(COLOR_WINDOW);
    wc.hCursor          = LoadCursor(NULL, IDC_ARROW);
    wc.hIcon            = (HICON)LoadImage(GetModuleHandle(NULL), MAKEINTRESOURCE(IDI_ICON), IMAGE_ICON, 32, 32, 0);
    wc.hInstance        = hInst;
    wc.lpfnWndProc      = WindowProcedure;
    wc.lpszClassName    = L"myWindowClass";
    wc.style            = 0;
    if(!RegisterClassW(&wc))
    {
        MessageBox(NULL, "Window registration failed !", "Error",
                   MB_OK | MB_ICONERROR);
        return 0;
    }
    hMainWindow = CreateWindowW(L"myWindowClass", L"D2",
                  WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX,
                  110, 33, 1159, 700,
                  NULL, NULL, NULL, NULL);
    MSG msg = {0};
    ShowWindow(hMainWindow, nCmdShow);
    UpdateWindow(hMainWindow);
    while(GetMessage(&msg, NULL, 0, 0) > 0)
    {
        TranslateMessage(&msg);
        DispatchMessage(&msg);
    }
    return 0;
}
LRESULT CALLBACK WindowProcedure(HWND hWnd, UINT msg, WPARAM wp, LPARAM lp)
{
    switch(msg) /* handle the messages */
        {
        case WM_PAINT: // D2Ency background image
            {
                PAINTSTRUCT ps;
                HDC hdc = BeginPaint(hWnd, &ps);
                HDC hdc_x = CreateCompatibleDC(NULL);
                HBITMAP hBitmap = (HBITMAP)LoadImage(NULL, "", IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE);
                SelectObject(hdc_x, hBitmap);
                RECT rect;
                GetWindowRect(hWnd, &rect);
                BitBlt(hdc, 0, 0, rect.right - rect.left, 650, hdc_x, 0, 0, SRCCOPY);
                EndPaint(hWnd, &ps);
                break;
            }
        case WM_CTLCOLORSTATIC: // Text and background of the static control
            {
                HDC hdcStatic = (HDC)wp;
                SetTextColor(hdcStatic, RGB(0, 0, 0));
                SetBkMode(hdcStatic, TRANSPARENT);
                if(hbrBkgnd == NULL)
                {
                    hbrBkgnd = CreateSolidBrush(RGB(0, 0, 0));
                }
                return (INT_PTR)(HBRUSH)GetStockObject(NULL_BRUSH);
            }
        case WM_CREATE:
            {
            loadImages();
            AddControls(hWnd);
            HWND hStatus;
            int statwidths[] = {150, 600, -1};
            hStatus = CreateWindowW(STATUSCLASSNAMEW, NULL, WS_CHILD | WS_VISIBLE | SBARS_SIZEGRIP,
                                    0, 0, 0, 0, hWnd, (HMENU)IDC_STATUS, GetModuleHandle(NULL), NULL);
            SendMessageW(hStatus, SB_SETPARTS, sizeof(statwidths)/sizeof(int), (LPARAM)statwidths);
            SendMessageW(hStatus, SB_SETTEXT, 0, (LPARAM)" Author:      Me");
            SendMessageW(hStatus, SB_SETTEXT, 1, (LPARAM)" - D2 - ");
            SendMessageW(hStatus, SB_SETTEXT, 2, (LPARAM)" May 2020");
            }
            break;
        case WM_COMMAND:
            switch(wp)
            {
            case ID_CHARACTERS:
                switch(wp)
                {
                case WM_CREATE:
                    CheckBox1(hWnd);
                    EnableWindow(hWnd, true);
                    return DefWindowProcW(hWnd, msg, wp, lp);
                }
            default:
                return DefWindowProcW(hWnd, msg, wp, lp);
            }
        case WM_DESTROY:
            PostQuitMessage(0); /* send a WM_QUIT to the message queue */
            break;
        default:
           return DefWindowProcW(hWnd, msg, wp, lp);
        }
    return 0;
}
void AddControls(HWND hWnd)
{
    hStatic = CreateWindowW(L"Static", L"Here will be the description",
                  WS_VISIBLE | WS_CHILD | WS_HSCROLL | WS_VSCROLL,
                          706, 123, 355, 411, hWnd, NULL, NULL, NULL);
    HWND hBut1 = CreateWindowW(L"Button", NULL, WS_CHILD | WS_VISIBLE | BS_BITMAP, // Quests
                  83, 320, 114, 22, hWnd, NULL, NULL, NULL);
    SendMessageW(hBut1, BM_SETIMAGE, IMAGE_BITMAP, (LPARAM)hButtonImage1);
    HWND hBut2 = CreateWindowW(L"Button", NULL, WS_CHILD | WS_VISIBLE | BS_BITMAP, // Towns
                  83, 358, 114, 22, hWnd, NULL, NULL, NULL);
    SendMessageW(hBut2, BM_SETIMAGE, IMAGE_BITMAP, (LPARAM)hButtonImage2);
    HWND hBut3 = CreateWindowW(L"Button", NULL, WS_CHILD | WS_VISIBLE | BS_BITMAP, // Waypoints
                  83, 396, 114, 22, hWnd, NULL, NULL, NULL);
    SendMessageW(hBut3, BM_SETIMAGE, IMAGE_BITMAP, (LPARAM)hButtonImage3);
    HWND hBut4 = CreateWindowW(L"Button", NULL, WS_CHILD | WS_VISIBLE | BS_BITMAP, // Monsters
                  83, 434, 114, 22, hWnd, NULL, NULL, NULL);
    SendMessageW(hBut4, BM_SETIMAGE, IMAGE_BITMAP, (LPARAM)hButtonImage4);
    HWND hBut5 = CreateWindowW(L"Button", NULL, WS_CHILD | WS_VISIBLE | BS_BITMAP, // Items
                  83, 471, 114, 22, hWnd, NULL, NULL, NULL);
    SendMessageW(hBut5, BM_SETIMAGE, IMAGE_BITMAP, (LPARAM)hButtonImage5);
    HWND hBut6 = CreateWindowW(L"Button", NULL, WS_CHILD | WS_VISIBLE | BS_BITMAP, // Auras
                  83, 508, 114, 22, hWnd, NULL, NULL, NULL);
    SendMessageW(hBut6, BM_SETIMAGE, IMAGE_BITMAP, (LPARAM)hButtonImage6);
    HWND hBut7 = CreateWindowW(L"Button", L"Characters", WS_CHILD | WS_VISIBLE, // Characters
                  83, 545, 114, 22, hWnd, (HMENU)ID_CHARACTERS, NULL, NULL);
    SendMessageW(hBut7, BM_SETIMAGE, IMAGE_BITMAP, (LPARAM)hButtonImage7);
}
void loadImages()
{
    hButtonImage1 = (HBITMAP)LoadImageW(NULL, L"", IMAGE_BITMAP, 114, 22, LR_LOADFROMFILE);
    hButtonImage2 = (HBITMAP)LoadImageW(NULL, L"", IMAGE_BITMAP, 114, 22, LR_LOADFROMFILE);
    hButtonImage3 = (HBITMAP)LoadImageW(NULL, L"", IMAGE_BITMAP, 114, 22, LR_LOADFROMFILE);
    hButtonImage4 = (HBITMAP)LoadImageW(NULL, L"", IMAGE_BITMAP, 114, 22, LR_LOADFROMFILE);
    hButtonImage5 = (HBITMAP)LoadImageW(NULL, L"", IMAGE_BITMAP, 114, 22, LR_LOADFROMFILE);
    hButtonImage6 = (HBITMAP)LoadImageW(NULL, L"", IMAGE_BITMAP, 114, 22, LR_LOADFROMFILE);
    hButtonImage7 = (HBITMAP)LoadImageW(NULL, L"", IMAGE_BITMAP, 114, 22, LR_LOADFROMFILE);
    hButtonImage8 = (HBITMAP)LoadImageW(NULL, L"", IMAGE_BITMAP, 114, 35, LR_LOADFROMFILE);
}
void CheckBox1(HWND hWnd)
{
    hChBox  = CreateWindowW(L"button", L"Characters", WS_CHILD | WS_VISIBLE | BS_GROUPBOX | BS_CENTER,
                  510, 100, 140, 460, hWnd, NULL, NULL, NULL);
    hChBox1 = CreateWindowW(L"button", L" Amazon", WS_CHILD | WS_VISIBLE | BS_AUTOCHECKBOX,
                  530, 160, 75, 15, hWnd, (HMENU)IDCH_BOX1, NULL, NULL);
    hChBox2 = CreateWindowW(L"button", L" Assassin", WS_CHILD | WS_VISIBLE | BS_AUTOCHECKBOX,
                  530, 210, 85, 15, hWnd, (HMENU)IDCH_BOX2, NULL, NULL);
    hChBox3 = CreateWindowW(L"button", L" Necromancer", WS_CHILD | WS_VISIBLE | BS_AUTOCHECKBOX,
                  530, 260, 110, 15, hWnd, (HMENU)IDCH_BOX3, NULL, NULL);
    hChBox4 = CreateWindowW(L"button", L" Barbarian", WS_CHILD | WS_VISIBLE | BS_AUTOCHECKBOX,
                  530, 310, 90, 15, hWnd, (HMENU)IDCH_BOX4, NULL, NULL);
    hChBox5 = CreateWindowW(L"button", L" Paladin", WS_CHILD | WS_VISIBLE | BS_AUTOCHECKBOX,
                  530, 360, 75, 15, hWnd, (HMENU)IDCH_BOX5, NULL, NULL);
    hChBox6 = CreateWindowW(L"button", L" Sorceress", WS_CHILD | WS_VISIBLE | BS_AUTOCHECKBOX,
                  530, 410, 90, 15, hWnd, (HMENU)IDCH_BOX6, NULL, NULL);
    hChBox7 = CreateWindowW(L"button", L" Druid", WS_CHILD | WS_VISIBLE | BS_AUTOCHECKBOX,
                  530, 460, 70, 15, hWnd, (HMENU)IDCH_BOX7, NULL, NULL);
    HWND hButClose = CreateWindowW(L"Button", L"Close", WS_CHILD | WS_VISIBLE,
                  530, 510, 90, 30, hWnd, (HMENU)ID_CLOSE, NULL, NULL);
    SendMessageW(hButClose, BM_SETIMAGE, IMAGE_BITMAP, (LPARAM)hButtonImage8);

    EnableWindow(hWnd, false);
}
Okay so.. I have this SDI and I know even is not a good design, but I want to understand how do I close the function 'Void CheckBox1()' after I enable it in WM_COMMAND, cause I tried different things like WM_DESTROY, or WM_CLOSE but without success.. I know that these cases take no action for static controls but how do I do that?
I put the entire code here and no worry about the resources is only the background I change it.. it should work fine.
Ohh forgot to say the function void CheckBox1() should be close from the button Close.. that will appear when you click on the Characters button..
Last edited on
Try DestroyWindow(hChBox) on the Close button message.
I am not 100% if this is the best way.
Is there a reason why you don't use a normal Windows dialog?
Yahh.. I done it with this:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
        case WM_COMMAND:
            switch(wp)
            {
            case ID_CHARACTERS:
                {
                    CheckBox1(hWnd);
                    EnableWindow(hWnd, true);
                    return DefWindowProcW(hWnd, msg, wp, lp);
                }
            case ID_CLOSE:
                {
                    SendMessageW((HWND)hChBox, WM_CLOSE, 0, 0);
                    SendMessageW((HWND)hChBox1, WM_CLOSE, 0, 0);
                    SendMessageW((HWND)hChBox2, WM_CLOSE, 0, 0);
                    SendMessageW((HWND)hChBox3, WM_CLOSE, 0, 0);
                    SendMessageW((HWND)hChBox4, WM_CLOSE, 0, 0);
                    SendMessageW((HWND)hChBox5, WM_CLOSE, 0, 0);
                    SendMessageW((HWND)hChBox6, WM_CLOSE, 0, 0);
                    SendMessageW((HWND)hChBox7, WM_CLOSE, 0, 0);
                    SendMessageW((HWND)hButClose, WM_CLOSE, 0, 0);
                    return DefWindowProcW(hWnd, msg, wp, lp);
                }
            default:
                return DefWindowProcW(hWnd, msg, wp, lp);
            }


The Problem is I had to send message to all the static that is in the function void hCheckBox()...
Anyone knows a better method to do this, maybe not that long.. ?
Or maybe is there a way to press again the same Button Characters to destroy the void function? Like this I could get rid of the Close button..
to destroy the void function

What on earth do you mean by that? What even is destroying a function?
I meant to disable it like you do with

 
EnableWindow(hWnd, false);
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
void CheckBox1(HWND hWnd)
{
    hChBox  = CreateWindowW(L"button", L"Characters", WS_CHILD | WS_VISIBLE | BS_GROUPBOX | BS_CENTER,
                  510, 100, 140, 460, hWnd, NULL, NULL, NULL);
    hChBox1 = CreateWindowW(L"button", L" Amazon", WS_CHILD | WS_VISIBLE | BS_AUTOCHECKBOX,
                  530, 160, 75, 15, hWnd, (HMENU)IDCH_BOX1, NULL, NULL);
    hChBox2 = CreateWindowW(L"button", L" Assassin", WS_CHILD | WS_VISIBLE | BS_AUTOCHECKBOX,
                  530, 210, 85, 15, hWnd, (HMENU)IDCH_BOX2, NULL, NULL);
    hChBox3 = CreateWindowW(L"button", L" Necromancer", WS_CHILD | WS_VISIBLE | BS_AUTOCHECKBOX,
                  530, 260, 110, 15, hWnd, (HMENU)IDCH_BOX3, NULL, NULL);
    hChBox4 = CreateWindowW(L"button", L" Barbarian", WS_CHILD | WS_VISIBLE | BS_AUTOCHECKBOX,
                  530, 310, 90, 15, hWnd, (HMENU)IDCH_BOX4, NULL, NULL);
    hChBox5 = CreateWindowW(L"button", L" Paladin", WS_CHILD | WS_VISIBLE | BS_AUTOCHECKBOX,
                  530, 360, 75, 15, hWnd, (HMENU)IDCH_BOX5, NULL, NULL);
    hChBox6 = CreateWindowW(L"button", L" Sorceress", WS_CHILD | WS_VISIBLE | BS_AUTOCHECKBOX,
                  530, 410, 90, 15, hWnd, (HMENU)IDCH_BOX6, NULL, NULL);
    hChBox7 = CreateWindowW(L"button", L" Druid", WS_CHILD | WS_VISIBLE | BS_AUTOCHECKBOX,
                  530, 460, 70, 15, hWnd, (HMENU)IDCH_BOX7, NULL, NULL);
    HWND hButClose = CreateWindowW(L"Button", L"Close", WS_CHILD | WS_VISIBLE,
                  530, 510, 90, 30, hWnd, (HMENU)ID_CLOSE, NULL, NULL);
    SendMessageW(hButClose, BM_SETIMAGE, IMAGE_BITMAP, (LPARAM)hButtonImage8);

    EnableWindow(hWnd, false);
}


I enable this here:

1
2
3
4
5
6
7
8
9
case WM_COMMAND:
            switch(wp)
            {
            case ID_CHARACTERS:
                {
                    CheckBox1(hWnd);
                    EnableWindow(hWnd, true);
                    return DefWindowProcW(hWnd, msg, wp, lp);
                }


Well sorry if I didn't made my self understood for the first time..
It's only an expression saying destroy a function.. :)
and I solved with this:

1
2
3
4
5
6
7
8
9
10
11
12
13
case ID_CLOSE:
                {
                    SendMessageW((HWND)hChBox, WM_CLOSE, 0, 0);
                    SendMessageW((HWND)hChBox1, WM_CLOSE, 0, 0);
                    SendMessageW((HWND)hChBox2, WM_CLOSE, 0, 0);
                    SendMessageW((HWND)hChBox3, WM_CLOSE, 0, 0);
                    SendMessageW((HWND)hChBox4, WM_CLOSE, 0, 0);
                    SendMessageW((HWND)hChBox5, WM_CLOSE, 0, 0);
                    SendMessageW((HWND)hChBox6, WM_CLOSE, 0, 0);
                    SendMessageW((HWND)hChBox7, WM_CLOSE, 0, 0);
                    SendMessageW((HWND)hButClose, WM_CLOSE, 0, 0);
                    return DefWindowProcW(hWnd, msg, wp, lp);
                }
This is where I asked if there's another way do this (destroy the void)meaning by using a WM_DESTROY .. :)
It's only an expression saying destroy a function

But... what do you mean by that? You can't destroy a function! Can you explain more clearly what it is you think you mean by that expression?
Last edited on
Topic archived. No new replies allowed.