-
1 Attachment(s)
Dialog Double Up
I'm diving into the WinAPI and have completed a simple dialog. When I run the application the dialog is drawn twice and mostly on top of itself. I can't determine what is causing this duplication.
Code:
#include <Windows.h>
#include "resource.h"
const char g_szClassName[] = "myWindowClass";
BOOL CALLBACK AboutDlgProc(HWND hwnd, UINT dMsg,
WPARAM wParam, LPARAM lParam)
{
switch (dMsg)
{
/*Dialog preprocessing*/
case WM_INITDIALOG:
return TRUE; //set keyboard focus to default control
break;
case WM_COMMAND:
switch (wParam)
{
case IDD_HELP_ABOUT_OK:
EndDialog(hwnd, IDD_HELP_ABOUT_OK);
break;
}
break;
default:
return TRUE;
}
return TRUE;
}
LRESULT CALLBACK WndProc(HWND hwnd, UINT wMsg, WPARAM wParam, LPARAM lParam)
{
switch (wMsg)
{
/*Window Preprocessing*/
case WM_CREATE:
break;
case WM_COMMAND:
switch (wParam)
{
case IDMI_FILE_EXIT:
DestroyWindow(hwnd);
break;
case IDMI_HELP_ABOUT:
DialogBox(GetModuleHandle(NULL), MAKEINTRESOURCE(IDD_HELP_ABOUT),
hwnd, (DLGPROC)AboutDlgProc);
break;
}
/*Clean up and call destroy*/
case WM_CLOSE:
DestroyWindow(hwnd);
break;
/*Destroy Window*/
case WM_DESTROY:
PostQuitMessage(0);
break;
default:
return DefWindowProc(hwnd, wMsg, wParam, lParam);
break;
}
return 0;
}
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE HPrevInstance,
LPSTR lpCmdLine, int nCmdShow)
{
WNDCLASSEX wc;
HWND hwnd;
MSG wMsg;
//Register the Window Class
wc.cbSize = sizeof(WNDCLASSEX);
wc.style = 0;
wc.lpfnWndProc = WndProc;
wc.cbClsExtra = 0;
wc.cbWndExtra = 0;
wc.hInstance = hInstance;
wc.hIcon = LoadIcon(NULL, IDI_APPLICATION);
wc.hCursor = LoadCursor(NULL, IDC_ARROW);
wc.hbrBackground = (HBRUSH)(COLOR_WINDOW + 1);
wc.lpszMenuName = MAKEINTRESOURCE(IDM_FILE_MENU);
wc.lpszClassName = g_szClassName;
wc.hIconSm = LoadIcon(NULL, IDI_APPLICATION);
//Check that the registration was successful
if (!RegisterClassEx(&wc))
{
MessageBox(NULL, "Window Registration Failed!", "Error!",
MB_ICONEXCLAMATION | MB_OK);
return 0;
}
//Create Window
hwnd = CreateWindowEx(
WS_EX_CLIENTEDGE,
g_szClassName,
"Toolboxie",
WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT, CW_USEDEFAULT, 256, 128,
NULL, NULL, hInstance, NULL);
//Check Window Creation
if (hwnd == NULL)
{
MessageBox(NULL, "Window Creation Failed!", "Error!",
MB_ICONEXCLAMATION | MB_OK);
return 0;
}
//Draw Window
ShowWindow(hwnd, nCmdShow);
UpdateWindow(hwnd);
//Message Loop
while (GetMessage(&wMsg, NULL, 0, 0) > 0)
{
TranslateMessage(&wMsg);
DispatchMessage(&wMsg);
}
//End
return wMsg.wParam;
}
Code:
IDD_HELP_ABOUT DIALOGEX 0, 0, 202, 60
STYLE DS_SETFONT | DS_MODALFRAME | DS_FIXEDSYS | WS_CAPTION
CAPTION "About Toolboxie"
FONT 8, "MS Shell Dlg", 400, 0, 0x1
BEGIN
DEFPUSHBUTTON "OK",IDD_HELP_ABOUT_OK,76,39,50,14
CTEXT "Toolboxie was created for FUNctionality and edutainment.",IDD_HELP_ABOUT_TEXT,7,15,187,8,NOT WS_GROUP
END
Attachment 15083