For which operating system?
NEW 2-----------------
Oh, okay. I'm sorry, but I don't program using Borland's or Microsoft's OOP libraries. You need to look for some kind of class that gets location of a mouse click.
I don't really know how to get window messages (such as mouse clicks) with OOP though. I program Windows directly with the Windows API functions. If you create a window with some kind of class, the class should have some subclasses that can report certain events which effect that window.
The input processing procedures looks something like this:
void CMainWindow::OnLButtonDown (UINT nFlags, CPoint point)
{
//do something
}
void CMainWindow::OnLButtonUp (UINT nFlags, CPoint point)
{
// do something
}
These procedures processes the left mouse click events from the CMainWindow class. When you use a class like CMainWindow, which can report window event messages, you create procedures for them. The ones you create depend on the particular event that the class can report, and the particular events that you wish to process. I don't have the code for initializing the CMainWindow class here. I got this example from an old Microsoft Visual C++ help file.
This is Microsoft MFC OOP.
for what you want to do, you would make a procedure to process a left mouse click.
That procedure then gets the mouse coordinates of the click, and then compares it to a bounding rectangle of the shape. If the coordinates are within the bounding rectange, you change the color of the shape.
I don't think that there is any kind of input loops with OOP though - just seperate procedures to handle each event.
Try posting this question again, but specify which OOP library that you're using.
Someone around here that programs with the OOP libraries should be able to help you.
Good luck.
NEW---------------------
I'll just point out the basic things you'll need to know. (The message would be too long and take too much time if I had to post a small program and explain it all.)
Do you have the Platform SDK? If you don't you'll need either that, or the old Windows API .hlp files to reference the Windows functions you'll be using.
I'm assuming that you already know how to create buttons in a dialog box with a resource editor and also in a regular window, using CreateWindow().
Everything I mention here can be looked up in the Platform SDK or the Win API SDK .hlp files.
So there's 4 things you need to do:
1) Create a custom button. When you create a custom button (for a dialog box or regular window), you must specify the BS_OWNERDRAW button style in addition to the common WS_ styles like WS_VISIBLE.
2) Drawing the button. There's different ways to draw in Windows. You can use a bitmap, use one of the drawing functions (like elipse), or draw an icon. Unless you want an icon, you should use a bitmap for your button. To change the colour of the bitmap, you could have two different coloured bitmaps. When you use a custom button, Windows issues the WM_DRAWITEM message to tell you when the button needs to be drawn. This is where you put your button drawing code. If you don't know how to draw bitmaps, then use a simple function like DrawIcon() for now.
3) You need to process WM_SIZE if the user is allowed to change the window size. When you process this message, you must get the changed window size, and draw the button in the proper position. Use the MoveWindow() function for moving the repositioning the button.
4) Button input processing is the same as with a regular button - by processing the WM_COMMAND message. Get the button status (up, down, selected) and then call the code that draws the bitmap.
There you go. Remember these:
BS_OWNERDRAW, WM_SIZE, WM_DRAWITEM, MoveWindow(), WM_COMMAND, and whatever functions you'll be using to draw the button.
2006-09-24 06:00:54
·
answer #1
·
answered by Balk 6
·
0⤊
1⤋
I assume you already have a shape, if not you may have to create one.
Anyhow, Win32 provides a HBRUSH which is a handle for a brush. Used as HBRUSH CreateSolidBrush(COLORREF Color) [1]
Create a callback function, or similar, for the shape to be able to call a function when it is pressed.
The callback function should be the one in another answer of how to loop.
Basically, you want that function to be called when the shape is pressed, and to change to the appropriate colour.
Knowing when someone has pressed on the shape will require listening to the mouse clicks, and getting the mouse location.
2006-09-28 03:30:44
·
answer #2
·
answered by Mark aka jack573 7
·
0⤊
0⤋
Just use a bit to keep track of the last shape color.
BOOL color;
YourSubroutine()
{
if (color)
Shape1->Brush->Color=clTeal;
else
Shape1->Brush->Color=clRed;
color = !color;
}
2006-09-25 02:27:18
·
answer #3
·
answered by justme 7
·
0⤊
0⤋
Are you kidding me. in this loopy international who cares. Boys want to be females , females want to be boys, and a few want to be the two. Take what you have and smile . Now in case you have undesirable enamel, smile alongside with your mouth closed. yet smile
2016-12-15 13:29:56
·
answer #4
·
answered by ? 4
·
0⤊
0⤋