-
buttons
this may sound stupid but im new at this so when yoiu make a button how do you make a function to use it preferably not in a class
Code:
CreateWindowEx(0,
"BUTTON",
"DEFAULT PUSH BUTTON",
WS_CHILD|WS_VISIBLE|BS_DEFPUSHBUTTON, 10,
10,
200,
30,
NULL,
hInst,
NULL);
-
Hmm, by function to use it i am assuming you are asking how do you handle it when its pressed...
For starters you havnt assigned your button with an ID which you need to do to handle it.
Correct Way:
Code:
#define ID_BUTTON 2556
HWND hWndButton = CreateWindow("BUTTON", "My Button", BS_PUSHBUTTON | WS_CHILD | WS_VISIBLE,
10, 10, 65, 15, hWnd, (HMENU)ID_BUTTON, hInstance, 0);
Ok your button now has an ID, now you handle a message when its pressed, more specifically WM_COMMAND.
Do this in your main message loop:
Code:
case WM_COMMAND:
{
switch(wParam)
{
case ID_BUTTON:
{
//executed when your butttons pressed
MessageBox(hWnd, "Button was clicked!!!", "Event...", MB_OK);
}
}
}
Hope that helps,
TNT
-
#define ID_BUTTON 2556
HWND hWndButton = CreateWindow
ok 2 things
1)were do i put this
2)the tutorials i read didnt say anything about #define or
HWND hWndButton = CreateWindow
so what does it do/what is it used for
(HWND hWndButton = CreateWindow...)
thanx in advanced
-
hey,
the #define should go at the top of your code just under the headers.
The HWND hWndButton simply defines a handle to your button, in this case hWndButton.
Also you can put this code in WM_CREATE message or just under where you create your main window.
I think thats all you need
Also maybe you should invest in a book....
Hope that helps
TNT
-
Place
HWND hWndButton = CreateWindow("BUTTON", "My Button", BS_PUSHBUTTON | WS_CHILD | WS_VISIBLE,
10, 10, 65, 15, hWnd, (HMENU)ID_BUTTON, hInstance, 0);
into WM_CREATE of your window.