gpt4 book ai didi

c++ - IDD_ABOUT : undeclared identifier

转载 作者:太空宇宙 更新时间:2023-11-03 10:30:07 25 4
gpt4 key购买 nike

我是 c/c++ 编程语言的新手,正在学习有关 Win32 的在线教程。当我构建和编译我的项目(MS VS C++ 2010 Express)时,出现此错误:'IDD_ABOUT':未声明的标识符。我不确定如何解决这个问题。 :(

主要.cpp:

#include <Windows.h>

#define ID_FILE_EXIT 9001
#define ID_HELP_ABOUT 9002

const char g_szClassName[] = "myWindowClass";

BOOL CALLBACK AboutDlgProc( HWND hwnd, UINT Message, WPARAM wParam, LPARAM lParam )
{
switch( Message )
{
case WM_INITDIALOG:

return TRUE;

case WM_COMMAND:
switch( LOWORD( wParam ) )
{
case IDOK:
EndDialog( hwnd, IDOK );
break;

case IDCANCEL:
EndDialog( hwnd, IDCANCEL );
break;
}
break;

default:
return FALSE;
}
return TRUE;
}

LRESULT CALLBACK WndProc( HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam )
{
switch( msg )
{
case WM_CREATE:
{
HMENU hMenu, hSubMenu;
HICON hIcon, hIconSm;

hMenu = CreateMenu();

hSubMenu = CreatePopupMenu();
AppendMenu( hSubMenu, MF_STRING, ID_FILE_EXIT, "E&xit" );
AppendMenu( hMenu, MF_STRING | MF_POPUP, ( UINT )hSubMenu, "&File" );

hSubMenu = CreatePopupMenu();
AppendMenu( hSubMenu, MF_STRING, ID_HELP_ABOUT, "&About" );
AppendMenu( hMenu, MF_STRING | MF_POPUP, ( UINT )hSubMenu, "&Help" );

SetMenu( hwnd, hMenu );

hIcon = ( HICON )LoadImage( NULL, "menu_one.ico", IMAGE_ICON, 32, 32, LR_LOADFROMFILE );
if( hIcon )
SendMessage( hwnd, WM_SETICON, ICON_BIG, ( LPARAM )hIcon );
else
MessageBox( hwnd, "Could not load large icon!", "ERROR!", MB_OK | MB_ICONERROR );

hIconSm = ( HICON )LoadImage( NULL, "menu_one.ico", IMAGE_ICON, 16, 16, LR_LOADFROMFILE );
if( hIconSm )
SendMessage( hwnd, WM_SETICON, ICON_SMALL, ( LPARAM )hIconSm );
else
MessageBox( hwnd, "Could not load small icon!", "ERROR!", MB_OK | MB_ICONERROR );
}
break;

case WM_COMMAND:
switch( LOWORD( wParam ) )
{
case ID_FILE_EXIT:
PostMessage( hwnd, WM_CLOSE, 0, 0 );
break;

case ID_HELP_ABOUT:
{
int ret = DialogBox( GetModuleHandle( NULL ), MAKEINTRESOURCE( IDD_ABOUT ), hwnd, AboutDlgProc );
if( ret == IDOK )
MessageBox( hwnd, "Dialog exited with IDOK.", "Notice", MB_OK | MB_ICONINFORMATION );
else if( ret == IDCANCEL )
MessageBox( hwnd, "Dialog exited with IDCANCEL.", "Notice", MB_OK | MB_ICONINFORMATION );
else if( ret == -1 )
MessageBox( hwnd, "Dialog failed!", "Error", MB_OK | MB_ICONINFORMATION );
}
break;
}
break;

case WM_LBUTTONDOWN:

break;

case WM_CLOSE:
DestroyWindow( hwnd );
break;

case WM_DESTROY:
PostQuitMessage( 0 );
break;

default:
return DefWindowProc( hwnd, msg, wParam, lParam );
}
return 0;
}

int WINAPI WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow )
{
WNDCLASSEX wc;
HWND hwnd;
MSG msg;

// Step 1: Registering the Window Class
wc.cbSize = sizeof( WNDCLASSEX );
wc.style = 1;
wc.lpfnWndProc = WndProc;
wc.cbClsExtra = 0;
wc.cbWndExtra = 0;
wc.hInstance = hInstance;
wc.hIcon = NULL;
wc.hCursor = LoadCursor( NULL, IDC_ARROW );
wc.hbrBackground = ( HBRUSH )( COLOR_WINDOW + 1 );
wc.lpszMenuName = NULL;
wc.lpszClassName = g_szClassName;
wc.hIconSm = NULL;

if( !RegisterClassEx( &wc ) )
{
MessageBox( NULL, "Window Registration Failed!", "Error!", MB_ICONEXCLAMATION | MB_OK );
return 0;
}

hwnd = CreateWindowEx(
WS_EX_CLIENTEDGE,
g_szClassName,
"The title of my window",
WS_OVERLAPPEDWINDOW,
500, 200, 800, 600,
NULL, NULL, hInstance, NULL );

if( hwnd == NULL )
{
MessageBox( NULL, "Window Creation Failed!", "Error!", MB_ICONEXCLAMATION | MB_OK );
return 0;
}

ShowWindow( hwnd, nCmdShow );
UpdateWindow( hwnd );

while( GetMessage( &msg, NULL, 0, 0 ) > 0 )
{
TranslateMessage( &msg );
DispatchMessage( &msg );
}

return msg.wParam;
}

资源.rc:

#include <Windows.h>

#ifndef IDC_STATIC
#define IDC_STATIC -1
#endif

IDD_ABOUT DIALOG DISCARDABLE 0, 0, 239, 66
STYLE DS_MODALFRAME | WS_POPUP | WS_CAPTION | WS_SYSMENU
CAPTION "My About Box"
FONT 8, "MS Sans Serif"
BEGIN
DEFPUSHBUTTON "&OK",IDOK,174,18,50,14
PUSHBUTTON "&Cancel",IDCANCEL,174,35,50,14
GROUPBOX "About this program...",IDC_STATIC,7,7,225,52
CTEXT "An example program showing how to use Dialog Boxes\r\n\r\nby theForger",IDC_STATIC,16,18,144,33
END

最佳答案

我感觉 Visual Studio Express 没有包含自动生成资源包含的适当资源编辑器,所以我猜您已经手动创建了 .rc 文件。如果是这样,您可能只需要定义符号。创建一个名为 resource.h 的包含文件并向其中添加以下行:

#define IDD_ABOUT   100

然后将其包含在 .cpp 和 .rc 文件的顶部:

#include <Windows.h>
#include "resource.h" // add this line

Windows header 定义了通用的某些资源 ID(IDOKIDCANCELIDC_STATIC 等),但对于其他任何您需要添加您自己的符号。这些值并不重要——任何不超过 65534 的数字都可以,只要它不与同一“范围”中使用的任何其他 ID 冲突(例如,一个对话框中的两个控件应该具有不同的 ID,但你可以在另一个对话框中重复使用相同的 ID)。

关于c++ - IDD_ABOUT : undeclared identifier,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19174690/

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