CreateDialogParam never calls WM_INITDIALOG
I have a dialog defined in the .rc file as:
IDD_DIALOG_AUTHENTICATION DIALOGEX 0, 0, 214, 138
STYLE DS_SETFONT | DS_MODALFRAME | DS_SETFOREGROUND | DS_3DLOOK | DS_FIXEDSYS | WS_POPUP | WS_VISIBLE | WS_CAPTION
CAPTION "Dialog"
FONT 8, "MS Shell Dlg", 400, 0, 0x1
BEGIN
DEFPUSHBUTTON "Validate",ID_BTN_VALIDATE,102,117,50,14
PUSHBUTTON "Exit",ID_BTN_EXIT,157,117,50,14
LTEXT "Username",IDC_STATIC,7,9,45,8
CONTROL "<a>SysLink</a>",IDC_SYSLINK,"SysLink",WS_TABSTOP,7,99,60,14
LTEXT "Password",IDC_STATIC,7,25,45,8
LTEXT "messages",IDC_MESSAGE,7,39,197,55
EDITTEXT IDC_USERNAME,44,7,140,14,ES_AUTOHSCROLL
EDITTEXT IDC_PASSWORD,44,22,140,14,ES_PASSWORD | ES_AUTOHSCROLL
END
and the ID is "IDD_DIALOG_AUTHENTICATION". CreateDialogParam is cal开发者_开发知识库led as:
HWND hDlgWnd = CreateDialogParamW(GetModuleHandle(NULL),L"IDD_DIALOG_AUTHENTICATION", (DLGPROC)dialogProc, (LPARAM)this);
but it returns a null HWND and NO error code (GetLastError() == 0).
There are several messages sent to my dialogProc function, but never WM_INITDIALOG (the messages are WM_SETFONT, 0x0090 (??), WM_DESTROY and WM_NCDESTROY)
OS is Vista 32 bit (no SP).
Any ideas ??
Edited: Ok, the culprit was the SysLink control. Without it I get the WM_INITDIALOG message, and the dialog comes up fine.
But, having the need for a SysLink control I: 1. Link the executable with the comctl32.lib 2. Call InitCommonControlsEx with ICC_LINK_CLASS
However, InitCommonControlsEx fails i.e. returns FALSE, so the question now is how to get the SysLink control to show... :)
All that you need is
#if defined _M_IX86
#pragma comment(linker, "/manifestdependency:\"type='win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' processorArchitecture='x86' publicKeyToken='6595b64144ccf1df' language='*'\"")
#elif defined _M_X64
#pragma comment(linker, "/manifestdependency:\"type='win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' processorArchitecture='amd64' publicKeyToken='6595b64144ccf1df' language='*'\"")
#else
#pragma comment(linker, "/manifestdependency:\"type='win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' processorArchitecture='*' publicKeyToken='6595b64144ccf1df' language='*'\"")
#endif
in your stdafx.h file. Or just add manifest with dependency of 'Microsoft.Windows.Common-Controls' to the your project.
Change:
HWND hDlgWnd = CreateDialogParamW(GetModuleHandle(NULL),L"IDD_DIALOG_AUTHENTICATION", (DLGPROC)dialogProc, (LPARAM)this);
To:
HWND hDlgWnd = CreateDialogParam(GetModuleHandle(NULL), MAKEINTRESOURCE(IDD_DIALOG_AUTHENTICATION), (DLGPROC)dialogProc, (LPARAM)this);
精彩评论