Thread: Custom button using bitmaps

  1. #1
    Registered User
    Join Date
    Oct 2008
    Posts
    34

    Custom button using bitmaps

    Hello,

    I have made a function for drawing a custom button using bitmaps. I'm drawing it when recieving WM_PAINT message (is this OK?). Now I want to detect when the user clicks the LMB in the client area. I do this using the WM_LBUTTONUP message. What I am thinking to do is whenever I recieve a WM_LBUTTONUP, I have to loop through the coordinates and sizes of all buttons created in my window and check if the mouse pointer is within one of those. If it is, I'll redraw the button to a pressed state, and send a user specified message to my window. Does this sound like a good idea?

    The way I think I want to accomplish this is to use a structure that goes something like this;

    Code:
    struct myButton
    {
        int messageID;
        int xPos;
        int yPos;
        int width;
        int height;
    };
    Then in my function for creating the button I'll do something like this:

    Code:
    myButton *myButtonPnt;
    myButtonPnt = new myButton;
    To make a new pointer to my button structure, and then fill in the appropriate values. Then I'll have to store it somewhere so that my function for checking if the user clicked it can use it again. Any suggestions on how to accomplish this in the most smart and efficient way?

    Any comments or suggestions on any of the above is greatly appreciated.

    Thanks,
    Eirik

  2. #2
    Registered User
    Join Date
    Jul 2008
    Posts
    67
    You better should create a custom control and not just a Bitmap.
    In the window procedure of the cunstom control you can simply handle the behaviour of a button.

    http://www.catch22.net/tuts/custctrl


    Greetz
    Greenhorn

  3. #3
    Registered User
    Join Date
    Nov 2002
    Posts
    319
    use WindowFromPoint , this will get the handle to the window where the mouse cursor is over

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. elliptical button
    By geek@02 in forum Windows Programming
    Replies: 0
    Last Post: 11-21-2006, 02:15 AM
  2. Pressing a button works sometimes
    By johny145 in forum Windows Programming
    Replies: 14
    Last Post: 05-18-2005, 11:53 AM
  3. writing text over a deleted button
    By algi in forum Windows Programming
    Replies: 4
    Last Post: 05-02-2005, 11:32 AM
  4. Window won't display on button command!?
    By psychopath in forum Windows Programming
    Replies: 6
    Last Post: 06-22-2004, 08:12 PM
  5. Replies: 1
    Last Post: 05-23-2002, 11:19 PM