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++.
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++.
Language: C++
Compiler: Visual C++ 6.0
Currently Working On: Simple OpenGL aspects
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
TNT
You Can Stop Me, But You Cant Stop Us All
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);
Language: C++
Compiler: Visual C++ 6.0
Currently Working On: Simple OpenGL aspects
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....
Code:#include <cmath> #include <complex> bool euler_flip(bool value) { return std::pow ( std::complex<float>(std::exp(1.0)), std::complex<float>(0, 1) * std::complex<float>(std::atan(1.0) *(1 << (value + 2))) ).real() < 0; }
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
Language: C++
Compiler: Visual C++ 6.0
Currently Working On: Simple OpenGL aspects
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
In a perfect world every dog would have a home and every home would have a dog.
Visit My Web Site, Canine Programming
I use Win32 API
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?
Language: C++
Compiler: Visual C++ 6.0
Currently Working On: Simple OpenGL aspects
you coud try ShowWindow(button_window,SW_HIDE);
In a perfect world every dog would have a home and every home would have a dog.
Visit My Web Site, Canine Programming
I use Win32 API
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?
Language: C++
Compiler: Visual C++ 6.0
Currently Working On: Simple OpenGL aspects
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
In a perfect world every dog would have a home and every home would have a dog.
Visit My Web Site, Canine Programming
I use Win32 API
Stubborn game! It hides it, but you cant click on the text. I'll be darned...
Language: C++
Compiler: Visual C++ 6.0
Currently Working On: Simple OpenGL aspects
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
Code:#include <cmath> #include <complex> bool euler_flip(bool value) { return std::pow ( std::complex<float>(std::exp(1.0)), std::complex<float>(0, 1) * std::complex<float>(std::atan(1.0) *(1 << (value + 2))) ).real() < 0; }
Stubborn game! It hides it, but you cant click on the text. I'll be darned...
Language: C++
Compiler: Visual C++ 6.0
Currently Working On: Simple OpenGL aspects
Just make a bitmap, load it in, and do all of the stuff to make it work*hope that works*