手动编程的WinForm对话框编译错误 [英] Manually programmed WinForm dialog box compile error
问题描述
嘿,伙计们.我对于手动编程Windows还是很陌生的,但我一直陷在这个问题上.我正在尝试遵循本教程: http://www.winprog.org/tutorial/dialogs.html [^ ]
直到我尝试添加对话框之前,程序窗口都可以正常显示.该对话框使用"menures.rc和menures.h".我在主文件中包含menures标头,并停止了未声明的"错误.我想现在我需要在主要函数中声明"IDD_ABOUT"和"ID_HELP_ABOUT".但是,我不知道如何.预先感谢您的帮助.
错误是:"[在这里符号]"之前的预期主表达式
我在发生错误的地方旁边放置了注释.
MAIN.CPP(不是完整的代码,所以如果需要更多代码,请告诉我)
Hey, guys. I''m VERY new to programming windows manually and I''m stuck on this problem. I''m trying to follow this tutorial: http://www.winprog.org/tutorial/dialogs.html[^]
The program window came up fine until I tried to add the dialog box. The dialog box uses "menures.rc and menures.h". I included the menures header in the main file, and that stopped the "undeclared" errors. I guess now I need to declare the "IDD_ABOUT" and "ID_HELP_ABOUT" in my main function, or something. But, I have no idea how. Thanks in advance for the help.
The error is: expected primary-expression before ''[symbol here]''
I put notes next to where the error occurs.
MAIN.CPP (Not the full code, so let me know if more is required)
// Step 4: the Window Procedure
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"); //ERROR HERE: expected primary-expression before '',''
AppendMenu(hMenu, MF_STRING | MF_POPUP, (UINT)hSubMenu, "&File");
hSubMenu = CreatePopupMenu();
AppendMenu(hSubMenu, MF_STRING, ID_STUFF_GO, "&Go"); //SAME ERROR AS ABOVE HERE
AppendMenu(hMenu, MF_STRING | MF_POPUP, (UINT)hSubMenu, "&Stuff");
SetMenu(hwnd, hMenu);
hIcon = (HICON)LoadImage(NULL, "Ufo.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, "Ufo.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_HELP_ABOUT: //ERROR HERE: expected primary-expression before '':''
{
int ret = DialogBox(GetModuleHandle(NULL), //ERROR HERE: expected primary-expression before '')''
MAKEINTRESOURCE(IDD_ABOUT), hwnd, AboutDlgProc);
if(ret == IDOK){
MessageBox(hwnd, "Dialog exited with IDOK.", "Notice",
MB_OK | MB_ICONINFORMATION);
}
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;
case ID_FILE_EXIT: //SAME ERROR AS ABOVE HERE
break;
case ID_STUFF_GO: //ERROR HERE: expected primary-expression before '':''
DialogBox(GetModuleHandle(NULL), MAKEINTRESOURCE(IDD_ABOUT), hwnd, AboutDlgProc); //ERROR HERE: expected primary-expression before '')''
break;
}
case WM_LBUTTONDOWN:
{
char szFileName[MAX_PATH];
HINSTANCE hInstance = GetModuleHandle(NULL);
GetModuleFileName(hInstance, szFileName, MAX_PATH);
MessageBox(hwnd, szFileName, "This program is:", MB_OK | MB_ICONINFORMATION);
}
case WM_CLOSE:
DestroyWindow(hwnd);
break;
case WM_DESTROY:
PostQuitMessage(0);
break;
default:
return DefWindowProc(hwnd, msg, wParam, lParam);
}
return 0;
}
RESOURCES.H
RESOURCES.H
#define IDR_MYMENU
#define IDI_MYICON
#define ID_FILE_EXIT
#define ID_STUFF_GO
RESOURCES.RC
RESOURCES.RC
#include "resources.h"
IDR_MYMENU MENU
BEGIN
POPUP "&File"
BEGIN
MENUITEM "E&xit", ID_FILE_EXIT
END
POPUP "&Stuff"
BEGIN
MENUITEM "&Go", ID_STUFF_GO
MENUITEM "G&o somewhere else", 0, GRAYED
END
END
IDI_MYICON ICON "menu_one.ico"
MENURES.H
MENURES.H
#define IDD_ABOUT
#define ID_HELP_ABOUT
MENURES.RC
MENURES.RC
#include "menures.h"
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
推荐答案
您可能需要在文件顶部#include "resources.h"
.
下载 Thinking in C ++ 2nd Edition by Bruce Eckel [
You probably need to#include "resources.h"
at the top of the file.
Download Thinking in C++ 2nd Edition by Bruce Eckel[^], it will explain some things you''ll probably need to know.
Good luck :)
Best regards
Espen Harlinn
这篇关于手动编程的WinForm对话框编译错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!