Hello,
I'm doing some owner draw for a button created with the CreateWindow function. In my WM_PAINT message I would like to check for the buttons state (normal, highlighted or clicked) to paint the correct look so I'm wondering if there is a function for that?
class Button
{
public:
bool Clicked;
bool IsOver;
int x;
int y;
int height;
int width;
bool Checkbutton();
void ChangeButtonImage();
}
void Button::Checkbutton()
{
CURSOR cursorpos;
if (curspos.x>=button.x && cursorpos.x<=button.x+width && cursorpos.y>=button.y && cursorpos.y<=button.y+height)
{
Button.IsOver=true;
Button::ChangeButtonImage();
//put whatever code you want executed when they click the button.
return button.IsOver;
}
}
void Button::ChangeButtonImage()
{
//switch the image for your button then redraw the screen.
the idea is you check every loop whether your cursorpos is over the location of each button. If it is change the image to a slightly different one so it becomes visible to user. On mouseclicks call CheckButton and if it is over the button then call whatever code you want called when they click the button.
Lol why did you ask if you've done it already lol. Anywho for multiple types of buttons just make an array of values and an int called NumberOfButtons containing the number of buttons you have. In the CheckButton() function that i put above just make a for loop and check the cursorpos against the location of each button.
To discrimate against the type of call pass an integer parameter to the funtion. Then for highlighting you will just call the function and pass it a "1" or whatever by calling it after the WM_MOUSEMOVE: message handler. For clicks pass it a "2" by calling the function after the WM_LEFTCLICK: message handler...or whatever it is.
Also using this method you can use regular images as buttons. using this allows you to have much more functionality and better looking buttons then using the stock Win32 API buttons.
You could also make a custom UI class. Which is what i have been thinking of doing instead of trying to use already developed API's because it is hard to learn them. Plus alot of them look outdated. Just set background images then have a border and table class draw custom pixels for borders and textboxes.
What I meant with I've done it already was your example. My question was if there was a built in function for that ; )
Just a bad formulated sentence from my side.