Need help with a custom Dialog Box..

Hello.. I created a custom Dialog Box that has a message and 2 buttons
typically to the a quit message The "Yes" message is closing the application but the "No" button instead to close the Dialog Box is either closing the app. Now this is the code:

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
#include <windows.h>
#include <commctrl.h>
#include <cstdio>
#include <mmsystem.h>
#include "resources.h"

#define IDC_STATUS  50
#define ID_SYES     51
#define ID_SNO      52

///////////////////////
LRESULT CALLBACK MainWndProc(HWND, UINT, WPARAM, LPARAM);
//Global Variables/////
//HWND
HWND hMainWindow, hClose, hStaticClose, hStaticYes, hStaticNo, hStaticGroup;
//HCURSOR
HCURSOR gauntlet = (HCURSOR)LoadImage(GetModuleHandle(NULL),
                    MAKEINTRESOURCE(IDC_SWORD), IMAGE_CURSOR, 32, 32, 0);
//HBITMAP
HBITMAP hBckground;
//Close window (Dialog Box) loop
LRESULT CALLBACK CloseWndProc(HWND hWnd, UINT msg, WPARAM wp, LPARAM lp)
{
    switch(msg)
    {
    case WM_COMMAND:
        switch(wp)
        {
        case ID_SYES:
            {
                DestroyWindow(hWnd);
                break;
            }
        case ID_SNO:
            {
                EnableWindow(hMainWindow, true);
                SendMessage((HWND)hClose, WM_CLOSE, 0, 0);
                break;
            }
        }
    case WM_SETCURSOR:
        {
            SetCursor(gauntlet);
            return 1;
        }
    case WM_DESTROY:
        PostQuitMessage(0);
        break;
    default:
        return DefWindowProcW(hWnd, msg, wp, lp);
    }
    return 0;
}
//Dialog Box/////////////////
void registerCloseClass(HINSTANCE hInst)
{
    WNDCLASSW close = {0};

    close.hbrBackground    = (HBRUSH)COLOR_WINDOW;
    close.hInstance        = hInst;
    close.lpfnWndProc      = CloseWndProc;
    close.lpszClassName    = L"myCloseClass";

    RegisterClassW(&close);
}
void displayClose(HWND hWnd)
{
    hClose = CreateWindowW(L"myCloseClass", L"Warning !", WS_VISIBLE | WS_CAPTION,
                           555, 280, 280, 140, hWnd, NULL, NULL, NULL);
    EnableWindow(hWnd, false);

    hStaticClose = CreateWindowW(L"static", L"This will close the program. Are you sure ?",
                                 WS_CHILD | WS_VISIBLE | SS_CENTER, 37, 20, 200, 50, hClose, NULL, NULL, NULL);
    hStaticYes = CreateWindowW(L"button", L"Yes",
                                 WS_CHILD | WS_VISIBLE | BS_CENTER, 33, 70, 80, 25, hClose, (HMENU)ID_SYES, NULL, NULL);
    hStaticNo = CreateWindowW(L"button", L"No",
                                 WS_CHILD | WS_VISIBLE | BS_CENTER, 160, 70, 80, 25, hClose, (HMENU)ID_SNO, NULL, NULL);
    hStaticGroup = CreateWindowW(L"button", NULL,
                                 WS_CHILD | WS_VISIBLE | BS_GROUPBOX, 7, 0, 261, 107, hClose, NULL, NULL, NULL);
}
//Main Loop////////////
LRESULT CALLBACK MainWndProc(HWND hWnd, UINT msg, WPARAM wp, LPARAM lp)
{
    switch(msg)
    {
    case WM_PAINT:
        {
            BITMAP bm;
                PAINTSTRUCT ps;

                HDC hdc = BeginPaint(hWnd, &ps);

                HDC hdcMem = CreateCompatibleDC(hdc);
                HBITMAP hbmOld = (HBITMAP)SelectObject(hdcMem, hBckground);

                GetObject(hBckground, sizeof(bm), &bm);

                BitBlt(hdc, 0, 0, bm.bmWidth, bm.bmHeight, hdcMem, 0, 0, SRCCOPY);

                SelectObject(hdcMem, hbmOld);
                DeleteDC(hdcMem);
                EndPaint(hWnd, &ps);
        }
    case WM_CREATE:
        {
            hBckground = LoadBitmap(GetModuleHandle(NULL), MAKEINTRESOURCE(IDC_MAINBMP));

            // Create status bar
                HWND hStatus;
                int statwidths[] = {150, 450, -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)" Ver. 1.00 ");
                SendMessageW(hStatus, SB_SETTEXT, 2, (LPARAM)" e-mail & other stuff");
        }
    case WM_SETCURSOR:
        SetCursor(gauntlet);
        return 1;
    case WM_CLOSE:
        {
            PlaySound(MAKEINTRESOURCE(IDW_CLICK), NULL, SND_RESOURCE | SND_ASYNC);
            displayClose(hWnd);
        }
        break;
    case WM_DESTROY:
        DeleteObject(hBckground);
        PostQuitMessage(0);
        break;
    default:
        return DefWindowProcW(hWnd, msg, wp, lp);
    }
    return 0;
}
//SDI Creation//////////////////
int WINAPI WinMain(HINSTANCE hInst, HINSTANCE hPrevInst, LPSTR args, int nCmdShow)
{
    InitCommonControls();

    WNDCLASSW wc = {0};

    wc.hbrBackground = (HBRUSH)COLOR_WINDOW + 1;
    wc.hIcon         = (HICON)LoadImage(GetModuleHandle(NULL),
                        MAKEINTRESOURCE(IDI_MAIN), IMAGE_ICON, 32, 32, 0);
    wc.hInstance     = hInst;
    wc.lpfnWndProc   = MainWndProc;
    wc.lpszClassName = L"myMainClass";
    wc.style         = 0;
    wc.lpszMenuName  = MAKEINTRESOURCEW(IDR_MENU);

    if(!RegisterClassW(&wc))
        return -1;

    registerCloseClass(hInst);

    hMainWindow = CreateWindowW(L"myMainClass", L"Application",
                                WS_SYSMENU | WS_MINIMIZEBOX | WS_CAPTION,
                                300, 100, 800, 550, NULL, NULL, NULL, NULL);

    ShowWindow(hMainWindow, nCmdShow);
    UpdateWindow(hMainWindow);

    MSG msg = {0};

    while(GetMessage(&msg, NULL, 0, 0) > 0)
    {
        TranslateMessage(&msg);
        DispatchMessage(&msg);
    }
    return 0;
}


Does anyone has the idea how to do that ? Probably some of you will ask why didn't I just use a system dialog box.. Just because I have a custom cursor and when I pass over a dialog box it change to the default one in the system.
Thank you !
Last edited on
Got it.. deleted the WM_Destroy case and the SendMessage((HWND)hClose, WM_CLOSE, 0, 0); from the case ID_SNO and added PostQuitMessage(0); to the case ID_SYES

Works fine thanks..
Topic archived. No new replies allowed.