Hello psychopath,
I know of a few implementation to get the job done:
Code:
#include <windows.h>
// Make sure this is setup in your Win32 initialization and stuff...
HINSTANCE hInstance;
// Default font for button
void SetDefaultFont( HWND hWnd, int identifier ){
SendDlgItemMessage(hWnd, identifier, WM_SETFONT,
(WPARAM)GetStockObject(DEFAULT_GUI_FONT), MAKELPARAM(TRUE, 0));
}
// Push button
HWND CreateButtonEx( HWND hWnd, int identifier, int x, int y,
int width, int height, char* tempText, unsigned long WS_CUSTOM ) {
HWND hButtonTemp;
hButtonTemp = CreateWindowEx(0, "BUTTON", tempText,
WS_CHILD | WS_CUSTOM | WS_VISIBLE, x, y, width, height, hWnd,
(HMENU)identifier, hInstance, NULL);
SetDefaultFont(hWnd, identifier);
return hButtonTemp;
}
Code 1.1: Setting up variables/functions for push button
Now on WM_CREATE all you have to do is:
Code:
#define IDBTN 10
HWND BTN;
BTN = CreateButtonEx( hWnd, IDBTN, 0, 0, 80, 23, "My Push Btton", WS_VISIBLE );
Now to explain all of this, I'll sum it up. IDBTN will be a handle to your button in case you cant use the HWND handle BTN. Also, the last argument in CreateButtonEx is there in case you want to add some other Window Styles that arent in the functions. I used WS_VISIBLE even though it was already in the implementation because I didn't need any special styles.
Now hWnd, is your window (dialog) handle. Which you will see in your Procedure, example:
LRESULT CALLBACK DlgProc(
HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam ) {
Of course, if your dialog procedure is not hWnd in your code, just change CreateButtonEx's first argument to the corresponding variable name. Now if you'd like, I can set up a whole code to display all of this in use instead of throwing little tid bits here and there.
In fact here is a link to a code I just wrote: Win32 Button Control
If you have any further questions, please let me know.
Hope this helps,
Stack Overflow