-
June 15th, 2025, 06:15 PM
#1
How to add a button in win32 app
Hi, this is my first win32 program and I'm making changes while I learn. I have a win32 window that needs functionality and I started looking into how to add buttons to your win32 program from here,
Code:
#include <windows.h>
LRESULT CALLBACK WindowProcessMessages(HWND hwnd, UINT msg, WPARAM param, LPARAM lparam);
int WINAPI WinMain(HINSTANCE currentInstance, HINSTANCE previousInstance, PSTR cmdLine, int cmdCount)
{
// Register the window class
const char* CLASS_NAME = "m0nst3r";
WNDCLASS wc{};
wc.hInstance = currentInstance;
wc.lpszClassName = CLASS_NAME;
wc.hCursor = LoadCursor(0, IDC_ARROW);
wc.hbrBackground = (HBRUSH)COLOR_WINDOW;
wc.lpfnWndProc = WindowProcessMessages;
RegisterClass(&wc);
// Create the window
CreateWindow(CLASS_NAME, "Windows Look e-Tr0n",
WS_OVERLAPPEDWINDOW | WS_VISIBLE, // Window style
CW_USEDEFAULT, CW_USEDEFAULT, // Window initial position
800, 600, // Window size
0, 0, 0, 0);
// Window loop
MSG msg{};
while (GetMessage(&msg, 0, 0, 0)) {
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return 0;
}
LRESULT CALLBACK WindowProcessMessages(HWND hwnd, UINT msg, WPARAM param, LPARAM lparam) {
switch (msg) {
case WM_DESTROY:
PostQuitMessage(0);
return 0;
default:
return DefWindowProc(hwnd, msg, param, lparam);
}
}
This is the first window I have I need a little advice as to how to add a button to start making it a program.
-
June 25th, 2025, 10:26 AM
#2
Re: How to add a button in win32 app
A button is usually placed in a dialog box, which is created by calling CreateDialog or DialogBox and is based on a dialog box template resource.
Code:
DialogBox(hInstance, MAKEINTRESOURCE(IDD_DIALOG_TEMPLATE_ID), hWndOwner, DialogProcedure);
Attached here is a simple example which can show an "About" dialog box, containing an "OK" button.
DemoWin32App.zip
-
June 25th, 2025, 02:03 PM
#3
Re: How to add a button in win32 app
 Originally Posted by dellthinker
I have a win32 window that needs functionality
If the primary purpose isn't to learn Win32, it may be easier to use a GUI framework. There are many available, but I tried Win32++ some time ago and liked it very much.
https://win32-framework.sourceforge.net/
I started with one of the supplied demo applications and modified it to fit my needs.
-
June 25th, 2025, 02:08 PM
#4
Re: How to add a button in win32 app
 Originally Posted by ovidiucucu
A button is usually placed in a dialog box, which is created by calling CreateDialog or DialogBox and is based on a dialog box template resource.
Code:
DialogBox(hInstance, MAKEINTRESOURCE(IDD_DIALOG_TEMPLATE_ID), hWndOwner, DialogProcedure);
Attached here is a simple example which can show an "About" dialog box, containing an "OK" button.
DemoWin32App.zip
Excellent, now I just need to know how to edit this. How would someone begin programming this solution?
Last edited by dellthinker; June 25th, 2025 at 02:27 PM.
-
June 26th, 2025, 01:14 AM
#5
Re: How to add a button in win32 app
 Originally Posted by dellthinker
Excellent, now I just need to know how to edit this. How would someone begin programming this solution?
First, install an IDE, as for example Visual Studio (Community edition is complete and free for your purpose). Then, keep ahead!
Visual Studio Community
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|