Untitled
unknown
plain_text
3 years ago
1.3 kB
9
Indexable
#include <windows.h>
// Declare the callback function for handling button clicks
LRESULT CALLBACK ButtonClickHandler(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) {
if (msg == WM_COMMAND && LOWORD(wParam) == 1) {
MessageBox(NULL, "Button clicked!", "Message", MB_OK);
}
return DefWindowProc(hwnd, msg, wParam, lParam);
}
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) {
// Register the window class
WNDCLASS wc = {0};
wc.lpfnWndProc = ButtonClickHandler;
wc.hInstance = hInstance;
wc.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);
wc.lpszClassName = "myWindowClass";
RegisterClass(&wc);
// Create the window
HWND hwnd = CreateWindowEx(0, "myWindowClass", "My Window", WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT, 500, 500, NULL, NULL, hInstance, NULL);
// Create a button and add it to the window
HWND button = CreateWindow("BUTTON", "Click me!", WS_TABSTOP|WS_VISIBLE|WS_CHILD|BS_DEFPUSHBUTTON, 200, 200, 100, 30, hwnd, (HMENU)1, hInstance, NULL);
// Show the window and start the message loop
ShowWindow(hwnd, nCmdShow);
MSG msg = {0};
while (GetMessage(&msg, NULL, 0, 0)) {
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return 0;
}
Editor is loading...