WINAPI创建窗口+子窗口,处理一个按钮preSS? [英] WinAPI create window + child windows, process a button press?
问题描述
我是新来的 WINAPI ,我希望创建一个包含一个空白的父窗口和两个较小的孩子按钮按钮1&我的程序里面放一个简单的窗口; 按钮2。使用此按钮,我希望能够从false更改一个布尔值设置为true,反之亦然,但几乎所有我见过的例子是挺难理解的,好像你必须返回一个味精某种价值,我不知道如何处理。
我有一个伪code 低于我想要做的,我已经离开注释解释什么,我想在每一刻的事情,我要对正确的方式?
的#include<&WINDOWS.H GT;静态INT buildwindow(){ 味精味精; //创建父窗口
HWND的hWnd = CreateWindow的(TEXT(滚动条),TEXT(母公司),WS_VISIBLE | WS_POPUP,
10,10,800,500,NULL,NULL,NULL,NULL); //创建子窗口
HWND hWnd1 = CreateWindow的(TEXT(按钮),TEXT(按钮1),WS_CHILD | WS_VISIBLE | WS_POPUP,
10,10,80,25,的hWnd,NULL,NULL,NULL); //创建子窗口2
HWND hWnd2 = CreateWindow的(TEXT(按钮),TEXT(按钮2),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); //等待按钮preSS
而(的GetMessage(安培;味精,NULL,0,0))
{
的TranslateMessage(安培;味精);
在DispatchMessage(安培;味精);
} //返回按钮preSS
回报(INT)msg.wParam;
}INT主要(无效)
{ //按钮preSS方法中创建窗口
INT按钮preSS = buildwindow(); //检查哪个按钮是pressed
如果(按钮preSS =按钮1){
//做一点事
}
ELSEIF(按钮preSS =按钮2){
//做别的事情
}
//完
返回(0);}
消息循环(GetMessage函数)将不会结束,直到WM_QUIT消息到达。
您需要实现回调函数的按钮单击事件。
我建议您阅读更多的按钮,在这里的消息:结果
的https://msdn.microsoft.com/en-us/library/windows/desktop/bb775941(v=vs.85).aspx
I'm new to WinApi and I'm looking to create a simple window inside my program containing a blank parent window and two smaller child buttons "button1" & "button2". with this button I'm hoping to change a bool value from false to true and visa versa, but nearly all the examples I have seen are quite hard to understand, it seems like you have to return an MSG value of some kind which I don't know how to process.
I have a pseudocode below of what I'm trying to do, I have left comments explaining what I want to do at each moment, am I going about it the right way?:
#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);
}
The message loop (GetMessage) won't end until a WM_QUIT message arrives.
You need to implement callback functions for the button click events.
I suggest reading more on button messages here:
https://msdn.microsoft.com/en-us/library/windows/desktop/bb775941(v=vs.85).aspx
这篇关于WINAPI创建窗口+子窗口,处理一个按钮preSS?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!