好的,在这个程序中,我使用Code :: Blocks IDE和GNU GCC编译器来编译可执行文件。这是一个Win32 GUI项目。我的问题是虽然它一切正常,但我最近试图实现点击按钮来编码它们。让他们工作。但是,我收到一个奇怪的错误,因为那个人告诉我代码应该工作/
错误:|| ===构建文件:在Agsploit中发布(编译器:GNU GCC 编译器)=== | C:\ Users \ PC \ Desktop \ Agsploit \ main.cpp ||在函数'int中 WinMain(HINSTANCE,HINSTANCE,LPSTR,int)':| C:\ Users \ PC \ Desktop \ Agsploit \ main.cpp | 14 |错误:预期 数字常量前的非限定id | C:\ Users \ PC \ Desktop \ Agsploit \ main.cpp | 55 |注意:在扩展宏时 “执行” | || ===构建失败:1个错误,0个警告(0分钟, 1秒(s))=== |
代码(对不起,不知道如何在这里格式化,所以粘贴它): http://pastebin.com/raw/r6b5NcXK
#if defined(UNICODE) && !defined(_UNICODE)
#define _UNICODE
#elif defined(_UNICODE) && !defined(UNICODE)
#define UNICODE
#endif
#include <tchar.h>
#include <windows.h>
LRESULT CALLBACK WindowProcedure(HWND, UINT, WPARAM, LPARAM);
TCHAR szClassName[] = _T("WindowClass");
#define Execute 0
#define RunScript 1
#define Clear 2
#define Help 3
#define Credits 4
#define Commands 5
#define Exit 6
int WINAPI WinMain(HINSTANCE hThisInstance, HINSTANCE hPrevInstance, LPSTR lpszArgument, int nCmdShow) {
HWND hwnd;
MSG messages;
WNDCLASSEX wincl;
wincl.hInstance = hThisInstance;
wincl.lpszClassName = szClassName;
wincl.lpfnWndProc = WindowProcedure;
wincl.style = CS_DBLCLKS;
wincl.cbSize = sizeof (WNDCLASSEX);
wincl.hIcon = LoadIcon (NULL, IDI_APPLICATION);
wincl.hIconSm = LoadIcon (NULL, IDI_APPLICATION);
wincl.hCursor = LoadCursor (NULL, IDC_ARROW);
wincl.lpszMenuName = NULL;
wincl.cbClsExtra = 0;
wincl.cbWndExtra = 0;
wincl.hbrBackground = (HBRUSH) COLOR_BACKGROUND;
if (!RegisterClassEx (&wincl)) {
return 0;
};
hwnd = CreateWindowEx(
0,
szClassName,
_T("LightNinG || v1 || By: [Team AzuL]"),
WS_OVERLAPPEDWINDOW ^ WS_THICKFRAME,
400,
200,
740,
390,
HWND_DESKTOP,
NULL,
hThisInstance,
NULL
);
HWND Execute = CreateWindow(
"BUTTON",
"Execute",
WS_TABSTOP | WS_VISIBLE | WS_CHILD | BS_DEFPUSHBUTTON,
250,
315,
235,
50,
hwnd,
(HMENU)Execute,
(HINSTANCE)GetWindowLong(hwnd, GWL_HINSTANCE),
NULL
);
HWND ScriptButton = CreateWindow(
"BUTTON",
"Run script",
WS_TABSTOP | WS_VISIBLE | WS_CHILD | BS_DEFPUSHBUTTON,
485,
315,
250,
50,
hwnd,
(HMENU)RunScript,
(HINSTANCE)GetWindowLong(hwnd, GWL_HINSTANCE),
NULL
);
HWND Clear = CreateWindow(
"BUTTON",
"Clear",
WS_TABSTOP | WS_VISIBLE | WS_CHILD | BS_DEFPUSHBUTTON,
0,
315,
250,
50,
hwnd,
(HMENU)Clear,
(HINSTANCE)GetWindowLong(hwnd, GWL_HINSTANCE),
NULL
);
HWND Help = CreateWindow(
"BUTTON",
"Help",
WS_TABSTOP | WS_VISIBLE | WS_CHILD | BS_DEFPUSHBUTTON,
400,
0,
85,
84,
hwnd,
(HMENU)Help,
(HINSTANCE)GetWindowLong(hwnd, GWL_HINSTANCE),
NULL
);
HWND Credits = CreateWindow(
"BUTTON",
"Credits",
WS_TABSTOP | WS_VISIBLE | WS_CHILD | BS_DEFPUSHBUTTON,
400,
84,
85,
84,
hwnd,
(HMENU)Credits,
(HINSTANCE)GetWindowLong(hwnd, GWL_HINSTANCE),
NULL
);
HWND Commands = CreateWindow(
"BUTTON",
"Commands",
WS_TABSTOP | WS_VISIBLE | WS_CHILD | BS_DEFPUSHBUTTON,
400,
168,
85,
84,
hwnd,
(HMENU)Commands,
(HINSTANCE)GetWindowLong(hwnd, GWL_HINSTANCE),
NULL
);
HWND Exit = CreateWindow(
"BUTTON",
"Exit",
WS_TABSTOP | WS_VISIBLE | WS_CHILD | BS_DEFPUSHBUTTON,
400,
252,
85,
64,
hwnd,
(HMENU)Exit,
(HINSTANCE)GetWindowLong(hwnd, GWL_HINSTANCE),
NULL
);
HWND OutputWindow = CreateWindow("Edit", "Hello, and welcome to LightNinG by Team AzuL.\r\nCurrent version: 1\r\nCurrent # of commands: 0", WS_CHILD | WS_VISIBLE | WS_BORDER | WS_HSCROLL | WS_VSCROLL | ES_AUTOHSCROLL | ES_MULTILINE | ES_READONLY, 0, 0, 400, 290, hwnd, NULL, NULL, NULL);
HWND InputBar = CreateWindow("Edit", "Input commands here.", WS_CHILD | WS_VISIBLE | WS_BORDER, 0, 290, 400, 25, hwnd, NULL, NULL, NULL);
HWND ScriptBox = CreateWindow("Edit", "Script(s) go here {client-sided}.", WS_CHILD | WS_VISIBLE | WS_BORDER | WS_HSCROLL | WS_VSCROLL | ES_AUTOHSCROLL | ES_MULTILINE, 485, 0, 250, 314, hwnd, NULL, NULL, NULL);
ShowWindow (hwnd, nCmdShow);
while (GetMessage(&messages, NULL, 0, 0)) {
TranslateMessage(&messages);
DispatchMessage(&messages);
};
return messages.wParam;
};
LRESULT CALLBACK WindowProcedure(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) {
switch (message) {
case WM_COMMAND:
switch(LOWORD(wParam)) {
case Execute:
break;
case RunScript:
break;
case Clear:
break;
case Help:
break;
case Credits:
MessageBox(NULL, (LPCWSTR)L"Created by team AzuL.", (LPCWSTR)L"Credits", MB_OK);
break;
case Commands:
break;
case Exit:
break;
}
break;
case WM_DESTROY:
PostQuitMessage(0);
break;
default:
return DefWindowProc(hwnd, message, wParam, lParam);
};
return 0;
};
答案 0 :(得分:2)
第14行(在您的错误消息中指出)是
#define Execute 0
第55行(在您的错误消息中也指出)是:
HWND Execute = CreateWindow(
扩展到:
HWND 0 = CreateWindow(
...这是无效的C ++。
有专家强烈建议:
首选解决方案如下:
enum class Command : int
{
Execute = 1, // I'd always reserve 0 for "no such command".
RunScript,
Clear,
Help,
Credits,
Commands,
Exit,
};
然后您可以使用(HMENU)Command::Execute
创建按钮。