我是WinApi的新手,我希望在我的程序中创建一个简单的窗口,其中包含一个空白父窗口和两个较小的子按钮“button1”和“button2”。使用此按钮,我希望将 bool 值从 false 更改为 true,反之亦然,但是我所看到的几乎所有示例都很难理解,似乎您必须返回某种我不知道的MSG值不知道怎么处理。
我在下面有一个我正在尝试做的伪代码,我留下了评论来解释我在每一刻想要做什么,我是否以正确的方式去做?:
#include <windows.h>
static int buildwindow(){
MSG msg;
//create parent window
HWND hWnd = CreateWindow(TEXT("scrollbar"), TEXT("Parent"), WS_VISIBLE | WS_POPUP,
10, 10, 800, 500, NULL, NULL, NULL, NULL);
//create child window
HWND hWnd1 = CreateWindow(TEXT("button"), TEXT("button1"), WS_CHILD|WS_VISIBLE | WS_POPUP,
10, 10, 80, 25, hWnd, NULL, NULL, NULL);
//create child window2
HWND hWnd2 = CreateWindow(TEXT("button"), TEXT("button2"), WS_CHILD|WS_VISIBLE | WS_POPUP,
100, 100, 80, 25, hWnd, NULL, NULL, NULL);
ShowWindow(hWnd, SW_SHOW);
UpdateWindow(hWnd);
ShowWindow(hWnd1, SW_SHOW);
UpdateWindow(hWnd1);
ShowWindow(hWnd2, SW_SHOW);
UpdateWindow(hWnd2);
//wait for buttonpress
while (GetMessage(&msg, NULL, 0, 0))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
//return the buttonpress
return (int) msg.wParam;
}
int main(void)
{
//create window inside the buttonpress method
int buttonpress = buildwindow();
//check which button was pressed
if(buttonpress = button1){
//do something
}
elseif(buttonpress = button2){
//do something else
}
//finish
return(0);
}