CreateDialog Failed, but why GetLastError returns 0?
I am writ开发者_开发百科ing an editor for my project by using scintilla editor component. The editor is for an internal scripting language, having all the basic functionalities like cut,copy, paste etc. As one of the feature I am also providing searching functionality. When a user presses the Ctrl+F ideally it should show this dialog:
But because of some reason CreateDialog API is failing, but the GetLastError returns 0. Also please note that I am using Windows Common Controls.
>>Code for creating dialog
HWND CreateFindDialog(HINSTANCE hInstance, HWND hWnd, UINT id)
{
HWND dlgHwnd = ::CreateDialog(hInstance, MAKEINTRESOURCE(id), hWnd, FindDlgProc);
if(dlgHwnd == NULL)
{
wchar_t buf [100];
wsprintf (buf, L"Error x%x", GetLastError ());
MessageBox (0, buf, L"CreateDialog", MB_ICONEXCLAMATION | MB_OK);
}
return(dlgHwnd);
}
BOOL CALLBACK FindDlgProc(HWND hWndDlg, UINT Msg, WPARAM wParam, LPARAM lParam)
{
switch(Msg)
{
case WM_INITDIALOG:
MessageBox (0, L"in", L"CreateDialog", MB_ICONEXCLAMATION | MB_OK);
return TRUE;
case WM_COMMAND:
switch(wParam)
{
case IDOK:
EndDialog(hWndDlg, 0);
return TRUE;
}
break;
}
return FALSE;
}
>>Resource entry for the dialog
IDD_FIND DIALOGEX 0, 0, 304, 90
STYLE DS_SETFONT | DS_MODALFRAME | DS_FIXEDSYS | DS_CENTER | WS_POPUP | WS_VISIBLE | WS_CAPTION | WS_SYSMENU
CAPTION "Find Text"
FONT 8, "MS Shell Dlg", 400, 0, 0x1
BEGIN
LTEXT "Search String",IDC_STATIC,7,7,44,8
EDITTEXT IDC_FIND_TEXT,7,20,217,14,ES_AUTOHSCROLL
DEFPUSHBUTTON "Find Next",IDC_FIND_NEXT,243,7,54,16,WS_DISABLED
PUSHBUTTON "Find Previous",IDC_FIND_PREVIOUS,243,26,54,16,WS_DISABLED
PUSHBUTTON "Close",IDCANCEL,243,45,54,16
CONTROL "Match case",IDC_FIND_CASE,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,7,42,52,10
CONTROL "Match whole word",IDC_FIND_WHOLE,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,7,55,74,10
CONTROL "Wrap around",IDC_FIND_WRAP,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,116,42,58,10
CONTROL "<a>Goto Replace (Ctrl+H)</a>",IDC_FIND_OPENREPLACE,
"SysLink",WS_TABSTOP,218,70,79,13
END
The only page talking about the same problem is this: CreateDialog Failed, but GetLastError return 0. I have checked the solution mentioned there but in my project I am linking to comctl32.lib. I have also checked my resource file and the resource header. The dialog entry seems to be proper.
>>Common control initialization
INITCOMMONCONTROLSEX iccx;
iccx.dwSize = sizeof(INITCOMMONCONTROLSEX);
iccx.dwICC = ICC_WIN95_CLASSES|ICC_COOL_CLASSES|ICC_BAR_CLASSES|ICC_USEREX_CLASSES;
if (!InitCommonControlsEx(&iccx))
return;
Any suggestion/idea would be helpful. Thanks.
The SysLink control requires v6 of comctl32 as explained by the documentation. You are linking to v5 comctl32 and I suspect this is the cause of your error. You need to include the v6 comctl32 application manifest.
精彩评论