каждый !
Я пытаюсь иметь 2 кнопки одновременно в приложении C ++, и каждая из них выполняет 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");
}
}
но он дает мне CE в ‘if’: «ожидаемый канал первичного выражения») «token» (x2, для каждого «if»). Вы можете мне помочь ?
WPARAM
а также LPARAM
типы. Вы должны использовать msg.wParam
а также msg.lParam
вместо:
if((HIWORD(msg.wParam)) == BN_CLICKED and ((HWND)msg.lParam) == hwndButton1)
Других решений пока нет …