I’ve created my dialog as a resource using the resource editor (dialog editor?)
It’s nothing special, just two groupboxes, two buttons, a split button, two pictureboxes, 3 static labels, 3 edit boxes, 3 spin controls, 3 syslinks, and a progressbar.
When I press Ctrl+T to test the dialog, it appears to work fine, but when I press F5 to debug the program, the dialog never appears and the program exits with code -1 (0xffffffff)
Here is the code I’m using to call the dialog:
#include <Windows.h>
#include "resource.h"
BOOL CALLBACK DlgProc(HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam)
{
switch (Msg)
{
case (WM_COMMAND):
switch (LOWORD(wParam))
{
default:
break;
}
break;
default:
return FALSE;
}
return FALSE;
}
int WINAPI WinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR lpCmdLine,
int nCmdShow)
{
int ret = DialogBox(hInstance, MAKEINTRESOURCE(IDD_MAINWINDOW), NULL, DlgProc);
int err = GetLastErro(); // This gives 0
return ret; // This gives -1
}
I don’t have anything yet in the DlgProc yet because I just wanted the dialog to show to begin with.
If I set a breakpoint in DlgProc then these are the messages it receives:
48, 85, 297, 273, 273, 144, 2, and 130.
I’ve looked these up and they translate to:
WM_SETFONT
WM_NOTIFYFORMAT
???
WM_COMMAND
WM_COMMAND
???
WM_DESTROY
WM_NCDESTROY
Anybody know what I’m doing wrong?
Edit::
I found a solution to the problem! We originally thought it was a corrupted RC file but I realised the the test RC file I made has every type of control except a SysLink. When I added a SysLink the same thing happened. I tried including ComCtl32.lib in the linker, and I also tried including the common controls header and calling InitCommonControls but that did nothing.
I put everything back the way it originally was, and added this pre-processor directive which fixed it:
#pragma comment(linker,"/manifestdependency:\"type='win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' processorArchitecture='*' publicKeyToken='6595b64144ccf1df' language='*'\"")
That was the problem. Without that directive, the dialog won’t initialise because of the SysLinks!
You don’t need to call
DefWindowProcfor Dialog procs. They are done for you by the OS. simplyreturn FALSE;