每个人 !我试图在 C++ 应用程序中同时拥有 2 个按钮,并且彼此执行 2 个不同的操作。代码 :
MSG msg;
HWND m_hwnd = GetConsoleWindow();
HWND hwndButton1 = CreateWindow(TEXT("button"), TEXT("B1"), WS_TABSTOP | WS_VISIBLE | WS_CHILD | BS_DEFPUSHBUTTON | BS_FLAT, 100, 100, 100, 30, m_hwnd, NULL, (HINSTANCE)GetWindowLong(m_hwnd, GWL_HINSTANCE), NULL);
HWND hwndButton2 = CreateWindow(TEXT("button"), TEXT("B2"), WS_TABSTOP | WS_VISIBLE | WS_CHILD | BS_DEFPUSHBUTTON | BS_FLAT, 200, 100, 100, 30, m_hwnd, NULL, (HINSTANCE)GetWindowLong(m_hwnd, GWL_HINSTANCE), NULL);
ShowWindow(hwndButton2, SW_SHOW);
ShowWindow(hwndButton1, SW_SHOW);
UpdateWindow(hwndButton2);
UpdateWindow(hwndButton1);
while(1)
{
GetMessage(&msg, NULL, 0, 0);
TranslateMessage(&msg);
DispatchMessage(&msg);
if((HIWORD(WPARAM)) == BN_CLICKED and ((HWND)LPARAM) == hwndButton1)
{
printf("1st clicked");
}
if((HIWORD(WPARAM)) == BN_CLICKED and ((HWND)LPARAM) == hwndButton2)
{
printf("2nd clicked");
}
}
但它在'if'中给了我一个CE:“预期的主要表达式beore')'令牌”(x2,对于每个'if')。你能帮助我吗 ?