[英]How do I use a button in a windows API program
我正在嘗試制作一個按鈕,當我單擊它時會發生一些事情。 我使用了一個while循環來制作按鈕,但是當我點擊它時我試圖讓一些事情發生。 我正在使用 c++ 控制台應用程序。
#define VK_LBUTTON 0x01
#define VK_RBUTTON 0x02
#include <Windows.h>
#include "tchar.h"
#include <iostream>
#include <fstream>
using namespace std;
int _tmain(int argc, _TCHAR* argv[])
{
MSG msg;
//if you add WS_CHILD flag,CreateWindow will fail because there is no parent window.
HWND hWnd = CreateWindow(TEXT("button"), TEXT("Easy"), WS_VISIBLE | WS_POPUP,
500, 500, 80, 25, NULL, NULL, NULL, NULL);
ShowWindow(hWnd, SW_SHOW);
UpdateWindow(hWnd);
while (GetMessage(&msg, NULL, 0, 0)) {
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return (int)msg.wParam;
}
BUTTON
控件需要父 window,但您沒有創建一個。 而父 window 需要一個 window 過程來處理發送給它的消息。 單擊按鈕時,它會向其父 window 發送BN_CLICKED
通知。 您的消息循環永遠不會看到它。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.