gpt4 book ai didi

c++ - 我的关于窗口打不开

转载 作者:行者123 更新时间:2023-11-28 00:46:04 25 4
gpt4 key购买 nike

信不信由你,我已经在这里工作了 5 个小时。我压力很大,因为它看起来很基础,当我真正掌握所有这些资源时,制作程序会容易得多。

这是我的代码:

#include <windows.h>
#include "resource.h"

LRESULT CALLBACK WndProc (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam);
BOOL CALLBACK AboutDlgProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam );

int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance,
PSTR lpszCmdParam, int nCmdShow)
{
static char szAppName[] = "ErrorSample";
HWND hwnd;
MSG msg; // Look how this struct is defined-see help/class notes NOW
WNDCLASSEX wndclass;
HWND hwndDialogBox = NULL;
HMENU hMenu;

wndclass.cbSize = sizeof(wndclass);
wndclass.style = CS_HREDRAW | CS_VREDRAW;
wndclass.lpfnWndProc = WndProc;
wndclass.cbClsExtra = 0;
wndclass.cbWndExtra = 0;
wndclass.hInstance = hInstance;
wndclass.hIcon = LoadIcon (NULL, IDC_ICON);

wndclass.hCursor = LoadCursor (NULL, IDC_ARROW);
wndclass.hbrBackground = static_cast<HBRUSH>(GetStockObject (WHITE_BRUSH));
wndclass.lpszMenuName = NULL;
wndclass.lpszClassName = szAppName;
wndclass.hIconSm = LoadIcon(NULL, MAKEINTRESOURCE(IDI_ERROR));

RegisterClassEx (&wndclass);

hMenu = LoadMenu(hInstance, MAKEINTRESOURCE(102));

hwnd = CreateWindow (szAppName, // window class name
"Trying my damndest", // window caption
WS_OVERLAPPEDWINDOW, // window style
CW_USEDEFAULT, // initial x position
CW_USEDEFAULT, // initial y position
CW_USEDEFAULT, // initial x size
CW_USEDEFAULT, // initial y size
NULL, // parent window handle
hMenu, // window menu handle
hInstance, // program instance handle
NULL); // creation parameters


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

while (GetMessage (&msg, NULL, 0, 0))
{
TranslateMessage (&msg);
DispatchMessage (&msg);
}
return (int) msg.wParam;
}

LRESULT CALLBACK WndProc (HWND hwnd, UINT message,
WPARAM wParam, LPARAM lParam)
{
static HINSTANCE hInstance;

switch (message)
{

case WM_CREATE:
hInstance = ((LPCREATESTRUCT) lParam) ->hInstance;
return 0;

case WM_COMMAND:
switch(LOWORD(wParam))
{
case ID_HELP_ABOUT:
DialogBox( hInstance, "AboutBox", hwnd, AboutDlgProc);
break;
}

return 0;

case WM_DESTROY:
PostQuitMessage(0);
return 0;
}

return DefWindowProc (hwnd, message, wParam, lParam);
}

BOOL CALLBACK AboutDlgProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
{
switch(message)
{
case WM_INITDIALOG:
return TRUE;

case WM_COMMAND:
switch(LOWORD(wParam))
{
case IDOK:
case IDCANCEL:
EndDialog(hDlg, 0);
return TRUE;
}
break;
}
return FALSE;
}

当我在 WndProc 的 WM_COMMAND 中单击我的 ID_HELP_ABOUT 案例语句时,没有任何反应。它甚至没有进入我的 AboutDlgProc 函数。

资源.h

//{{NO_DEPENDENCIES}}
// Microsoft Visual C++ generated include file.
// Used by Practice.rc
//
#define DIALOG_BOX 9
#define IDR_MENU1 102
#define ID_HELP_ABOUT 40001

// Next default values for new objects
//
#ifdef APSTUDIO_INVOKED
#ifndef APSTUDIO_READONLY_SYMBOLS
#define _APS_NEXT_RESOURCE_VALUE 103
#define _APS_NEXT_COMMAND_VALUE 40002
#define _APS_NEXT_CONTROL_VALUE 1001
#define _APS_NEXT_SYMED_VALUE 101
#endif
#endif

.rc文件

// Microsoft Visual C++ generated resource script.
//
#include "resource.h"

#define APSTUDIO_READONLY_SYMBOLS
/////////////////////////////////////////////////////////////////////////////
//
// Generated from the TEXTINCLUDE 2 resource.
//
#include "afxres.h"

/////////////////////////////////////////////////////////////////////////////
#undef APSTUDIO_READONLY_SYMBOLS

/////////////////////////////////////////////////////////////////////////////
// English (United States) resources

#if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_ENU)
LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_US

#ifdef APSTUDIO_INVOKED
/////////////////////////////////////////////////////////////////////////////
//
// TEXTINCLUDE
//

1 TEXTINCLUDE
BEGIN
"resource.h\0"
END

2 TEXTINCLUDE
BEGIN
"#include ""afxres.h""\r\n"
"\0"
END

3 TEXTINCLUDE
BEGIN
"\r\n"
"\0"
END

#endif // APSTUDIO_INVOKED


/////////////////////////////////////////////////////////////////////////////
//
// Dialog
//

DIALOG_BOX DIALOGEX 32, 32, 309, 178
STYLE DS_SETFONT | DS_MODALFRAME | DS_FIXEDSYS | WS_POPUP | WS_SYSMENU
FONT 8, "MS Shell Dlg", 400, 0, 0x1
BEGIN
DEFPUSHBUTTON "OK",IDOK,198,157,50,14
END


/////////////////////////////////////////////////////////////////////////////
//
// DESIGNINFO
//

#ifdef APSTUDIO_INVOKED
GUIDELINES DESIGNINFO
BEGIN
DIALOG_BOX, DIALOG
BEGIN
LEFTMARGIN, 7
RIGHTMARGIN, 302
TOPMARGIN, 7
BOTTOMMARGIN, 171
END
END
#endif // APSTUDIO_INVOKED


/////////////////////////////////////////////////////////////////////////////
//
// Menu
//

IDR_MENU1 MENU
BEGIN
MENUITEM "&File", 0
POPUP "&Help"
BEGIN
MENUITEM "&About", ID_HELP_ABOUT
END
END

#endif // English (United States) resources
/////////////////////////////////////////////////////////////////////////////



#ifndef APSTUDIO_INVOKED
/////////////////////////////////////////////////////////////////////////////
//
// Generated from the TEXTINCLUDE 3 resource.
//


/////////////////////////////////////////////////////////////////////////////
#endif // not APSTUDIO_INVOKED

请帮忙! =)

最佳答案

将对话框调用更改为此:

DialogBox( hInstance, MAKEINTRESOURCE(DIALOG_BOX), hwnd, AboutDlgProc);

关于c++ - 我的关于窗口打不开,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16204966/

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