WinApi CreateDialog返回错误715

WinApi CreateDialog returns error 715

本文关键字:错误 返回 CreateDialog WinApi      更新时间:2023-10-16

我正试图生成这个简单的窗口对话框,但一旦启动它,它就会报告"错误x715",这意味着hDialog没有在int WINAPI WinMain()函数中正确生成。它编译得很好。

我在Visual Studio 2010中工作,它是一个"Visual C++->Empty Project"项目。

这是完整的main.cpp文件,是项目中唯一的文件:

#include "windows.h"
#define DLG_MAIN 200 // ID for dialog
#define DLG_ICON 30000 // IDs for icons
#define DLG_ICON_S 30000
#define IDC_QUIT 1011 // ID for "quit"-button
#define IDC_INFO 2000 // ID for "info"-button
#define ID_TIMER 1 // ID for timer
#define IDC_STATIC -1 // ID for all labels
#define TIMER_INTERRUPT 500 // timer msg interval in msec 
HINSTANCE TheInstance = 0; // instance handle of this program
// Our main function
void lalala(HWND hwnd)
{
    /*Doesn't do anything yet.*/
}
// Windows passes messages to application windows to indicate "something"
// needs to be done
BOOL CALLBACK DialogProc (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
    switch (message)
    {
        case WM_INITDIALOG:
        // set the time to generate a timer message (WM_TIMER)
        SetTimer(hwnd, ID_TIMER, TIMER_INTERRUPT, NULL);
        return TRUE;
        case WM_TIMER:
        // a timer msg was received so call our main function!
        lalala(hwnd);
        return TRUE;
        case WM_COMMAND:
        switch (LOWORD(wParam)) 
        {
            case IDC_INFO:
            // the info button on the window was pressed
            MessageBox(hwnd, "<show some info>", "The Jonas Brothers are way better than Nick Cave ever was.", MB_OK);
            return TRUE;
            case IDC_QUIT:
            // the quit button on the window was pressed
            PostQuitMessage(0);
            return TRUE;
        }
        return TRUE;
        case WM_DESTROY:
        // this app is about to be closed so kill the timer
        KillTimer(hwnd, ID_TIMER);
        PostQuitMessage(0);
        return TRUE;
        case WM_CLOSE:
        // destroy the window
        DestroyWindow (hwnd);
        return TRUE;
    }
return FALSE;
} 
int WINAPI WinMain(HINSTANCE hInst, HINSTANCE hPrevInst, char * cmdParam, int cmdShow)
{
    TheInstance = hInst;
    HWND hDialog = 0;
    hDialog = CreateDialog (hInst, MAKEINTRESOURCE (DLG_MAIN), 0, (DLGPROC)DialogProc);
    if (!hDialog)
    {
        char buf [100];
        wsprintf (buf, "Error x%x", GetLastError ());
        MessageBox (0, buf, "CreateDialog", MB_ICONEXCLAMATION | MB_OK);
        return 1;
    }
    HICON hIcon = LoadIcon (TheInstance, MAKEINTRESOURCE (DLG_ICON));
    SendMessage (hDialog, WM_SETICON, WPARAM (TRUE), LPARAM (hIcon));
    hIcon = LoadIcon (TheInstance, MAKEINTRESOURCE (DLG_ICON_S));
    SendMessage (hDialog, WM_SETICON, WPARAM (FALSE), LPARAM (hIcon));
    MSG msg;
    int status;
    while ((status = GetMessage (&msg, 0, 0, 0)) != 0)
    {
        if (status == -1) return -1;
        if (!IsDialogMessage (hDialog, &msg))
        {
            TranslateMessage ( &msg );
            DispatchMessage ( &msg );
        }
    }
    return msg.wParam;
}

有人能告诉我为什么它在hDialog = CreateDialog (hInst, MAKEINTRESOURCE (DLG_MAIN), 0, (DLGPROC)DialogProc);失败吗?

错误0x715为Error_RESOURCE_NAME_NOT_FOUND,当它在资源部分中找不到具有您提供的名称的对话框时,会得到该错误。不必为每个资源声明宏,只需使用#include "resource.h"