Hi there,
I finally got this to work. I bought the book John recommended and read through the code in one of the Dialog Box examples. I couldn't see too much difference in the way the DB was called. It helped me understand how to call it within the windows procedure function though as up to that point I'd been struggling to find a way to pass the hInstance into the DB call.
It still failed however. I wondered then if it was a setting issue rather than a code issue and ultimately it was. When I checked the settings in the template for Charles Petzold's DB there were two settings that were different. One was I think Disabled being True in the Behaviour tab and the other (which was what ultimately fixed it) was the Style setting in the Appearance tab. It was set to Child and when I changed it to Popup that was it.
Here's the code for the WinProc function:
Code:
LRESULT CALLBACK WindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
static HINSTANCE hInstance;
switch (uMsg)
{
case WM_CREATE:
hInstance = ((LPCREATESTRUCT) lParam)->hInstance;
return 0;
case WM_LBUTTONDOWN:
DialogBoxW(hInstance, (LPCWSTR)102, hwnd, DlgProc);
return 0;
case WM_DESTROY:
PostQuitMessage(0);
return 0;
case WM_PAINT:
{
PAINTSTRUCT ps;
HDC hdc = BeginPaint(hwnd, &ps);
// All painting occurs here, between BeginPaint and EndPaint.
FillRect(hdc, &ps.rcPaint, (HBRUSH)(COLOR_WINDOW + 1));
EndPaint(hwnd, &ps);
}
return 0;
}
return DefWindowProc(hwnd, uMsg, wParam, lParam);
}
And here's the DlgProc function:
Code:
LRESULT CALLBACK DlgProc(HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
switch (uMsg)
{
case WM_INITDIALOG:
return TRUE;
case WM_COMMAND:
switch (LOWORD(wParam))
{
// Button1 Pressed
case IDC_BUTTON1:
EndDialog(hDlg, 0);
return TRUE;
}
break;
} // switch [uMsg]
return FALSE;
}
And that makes a nice simple DB which opens with a left mouse click and has just one button on it named Button1 which closes the DB. If you wish you can keep opening and closing the DB in that fashion.