CreateDialog失败,但为什么GetLastError返回0?

时间:2011-09-04 06:20:17

标签: c++ dialog scintilla win32gui comctl32

我正在使用scintilla editor component为我的项目编写一个编辑器。编辑器是一种内部脚本语言,具有剪切,复制,粘贴等所有基本功能。作为功能之一,我还提供搜索功能。当用户按下 Ctrl + F 时,理想情况下应显示此对话框:

Search

但由于某些原因 CreateDialog API失败,但GetLastError返回0。另请注意我使用的是 Windows公共控件

>>创建对话框的代码

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;
}

>>对话框的资源条目

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

唯一讨论同一问题的网页是:CreateDialog Failed, but GetLastError return 0。我检查了那里提到的解决方案但在我的项目中我链接到 comctl32.lib 。我还检查了我的资源文件和资源头。对话框条目似乎是正确的。

<小时/> &gt;&gt;公共控件初始化

 INITCOMMONCONTROLSEX iccx;
 iccx.dwSize = sizeof(INITCOMMONCONTROLSEX);
 iccx.dwICC = ICC_WIN95_CLASSES|ICC_COOL_CLASSES|ICC_BAR_CLASSES|ICC_USEREX_CLASSES;
 if (!InitCommonControlsEx(&iccx))
    return;

任何建议/想法都会有所帮助。感谢。

1 个答案:

答案 0 :(得分:3)

SysLink控件需要v6的comctl32,如documentation所述。您正在链接到v5 comctl32,我怀疑这是您的错误的原因。您需要包含v6 comctl32 application manifest