I have a main menu for a game, but I can't find anywhere that says how to make a Button. I just want to place a few buttons on the screen for the player to click on and go to that. How would I make them?
By the way I am coding it in C++.
Printable View
I have a main menu for a game, but I can't find anywhere that says how to make a Button. I just want to place a few buttons on the screen for the player to click on and go to that. How would I make them?
By the way I am coding it in C++.
Umm, if your making a game i dunno if you using directx, but heres how you do it just for normal window proggies.
#define ID_BUTTON 4563 //define ID at the top of ur code
//create the button in winmain
HWND hWndButton = CreateWindow("BUTTON", "Click Me", BS_PUSHBUTTON | WS_CHILD | WS_VISIBLE,
10, 10, 65, 15, hWnd, (HMENU)ID_BUTTON, hInstance, 0);
Hope that helps,
TNT
Yea, just regular windows. A couple questions on that. That would go in this part of my code right:
how exactly would i put that in there then? And what is the (HMENU) for? ThanksCode:hwnd = CreateWindow ("Window Class 1",
"TiloSite by Tazar",
WS_OVERLAPPEDWINDOW,
10,
10,
700,
700,
NULL,
NULL,
hInstance,
NULL);
Nope. Just define it at the top, and then do the other stuff that
( TNT ) said.
And just for clarities sake Tazar, each and every button is a "window", so you would'nt have just one CreateWindowEx() call, but several: one for the main window, and one for EACH button. BTW all Windows controls are separate "window"s, and each recieves it's own message loop, etc....
yay! The button is working. So now I have 2 more questions. My bitmap for the main menu has fancy text for where the player clicks to go to the option, so if i lined up the button exactly where the Text were, and took off the WS_VISIBLE, the player could click the text and go to the action of the button? That is pretty wordy... and one more question.
How do i detect if the player hit the button? So I would detect if they hit it, and then do the code for that option right? Thanks again
to detect if it is pressed it will send an ID_BUTTON (from first example) in your wndproc as wParam of a WM_COMMAND message
hope that helps
I got the reading it done. But taking off WS_VISIBLE doesn't work... Anyway i could make that text there and still go to that function?
you coud try ShowWindow(button_window,SW_HIDE);
I put that under the button's code, and it said button_window undeclared identifier, and if i changed it to BUTTON1 or button1 it still didn't work. What now?
when you are making your CreateWindow for the button what are you putting "here"=CreateWindow(...
put that in the 1st parameter of ShowWindow
ex
HWND hWndButton = CreateWindow("BUTTON", "Click Me", BS_PUSHBUTTON | WS_CHILD,
10, 10, 65, 15, hWnd, (HMENU)ID_BUTTON, hInstance, 0);
ShowWindow(hWndButton,SW_HIDE);
hope that helps
Stubborn game! It hides it, but you cant click on the text. I'll be darned...
In a word: no. If you hide the button then you no longer can recieve a click signal from it. Here's one solution, though: forget the button! That is, instead of relying on the button for input, simply find the coordinates of that area, store it in a RECT structure, then after testing for a mouseclick, (say, WM_LBUTTONUP) take the LOWORD of lParam, which will contain the x( or maybe its y) coord of the click, and the HIWORD of lparam, which will contain the other coord, and place those two in a POINT structure. Then it's as simple as saying "if(PtInRect(ptClick, rctArea))...blah blah blah...(again, the params may be backwords...)
Happy Coding :)
Stubborn game! It hides it, but you cant click on the text. I'll be darned...
Just make a bitmap, load it in, and do all of the stuff to make it work*hope that works*