gpt4 book ai didi

c++ - WinApi CreateDialog 返回错误 715

转载 作者:太空宇宙 更新时间:2023-11-04 12:13:03 26 4
gpt4 key购买 nike

我正在尝试生成这个简单的 Windows 对话框,但是一旦我启动它,它就会报告“错误 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"

关于c++ - WinApi CreateDialog 返回错误 715,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9022553/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com