Thread: buttons

  1. #1
    Registered User
    Join Date
    Apr 2002
    Posts
    77

    buttons

    can i make a custom button for VC++ MFC
    like use a picture as a button.

  2. #2
    Used Registerer jdinger's Avatar
    Join Date
    Feb 2002
    Posts
    1,065
    You coud define a RECT and blt (whichever blt method you prefer) your button pic there. Then on WM_LBUTTONDOWN assign the current mouse coord's to a POINT and if the user clicks, use PtInRect to check to see if they clicked on your button. To add "realism" to it, you can have a pic of multiple stages of your button. So for instance when the mouse moves over your button but they haven't clicked, a highlighted button pic will be displayed (reset if the mouse isn't over the button), and another pic to blt when they click to show a "pushed" state.

  3. #3
    Registered User
    Join Date
    Apr 2002
    Posts
    77
    wa
    thats chim
    is there any webby that can help in that ?????
    or is there any guide to do that ?

  4. #4
    Used Registerer jdinger's Avatar
    Join Date
    Feb 2002
    Posts
    1,065
    thats chim
    What's "chim"?

    Let me know what part you don't understand and I'll go into more detail.

  5. #5
    Registered User
    Join Date
    Apr 2002
    Posts
    77
    becoz i dont even know how to create a button
    im using the MFC all the way
    so i dunno how to create a custom on

  6. #6
    Used Registerer jdinger's Avatar
    Join Date
    Feb 2002
    Posts
    1,065
    I haven't messed with MFC very much, but here's a way to create a simple button:

    Code:
    //in your global declares
    HWND Btn1=NULL;
    
    //in your message handler
    
     //Create the Button
     //in this case "hwnd" is the HWND param passed to your
     //message handler, and "hInstMain" is the hInstance of your
     //parent window.
    case WM_CREATE:
     Btn1=CreateWindow(0,"Button","Button 1",WS_CHILD |
    WS_VISIBLE | BS_DEFPUSHBUTTON,10,10,100,30,hwnd,NULL,
    hInstMain,NULL);
    
    //See if the button was pushed
    case WM_COMMAND:
     if((HWND)lParam==Btn1)
      { 
          //your function goes here
       }
    This will create a standard Window's push button.

    To do it the
    way that I described earlier, you would define a RECT that would
    cover the area that your button covers. Then in your message
    handler check for cursor movement (WM_MOUSEMOVE). Then use
    the cursor coords ((LOWORD)lParam=x,(HIWORD)lParam=y) and
    put these into your POINT structure. Then use PtInRect to see if
    the POINT structure is within the RECT structure. If so, highlight
    the button.

    To check for mouse clicks use the same method except instead
    of checking with WM_MOUSEMOVE you'd check with
    WM_LBUTTONDOWN, etc..

  7. #7
    It's full of stars adrianxw's Avatar
    Join Date
    Aug 2001
    Posts
    4,829
    Also a non MFC jockey, but I do know MFC provides a CBitmapButton class which may well do what you want.
    Wave upon wave of demented avengers march cheerfully out of obscurity unto the dream.

  8. #8
    Used Registerer jdinger's Avatar
    Join Date
    Feb 2002
    Posts
    1,065
    Thanks for the back-up, Adrian.

    :: hides in shame at my lack of MFC knowledge ::

    monkeymon, sorry if my examples don't help. As I said I have
    very little experience with MFC. If either of my examples aren't
    what you're looking for I'll search for some good MFC
    CBitmapButton tutorials/articles and post the links.

  9. #9
    It's full of stars adrianxw's Avatar
    Join Date
    Aug 2001
    Posts
    4,829
    >>> :: hides in shame at my lack of MFC knowledge ::

    Nothing to be ashamed of. I bought Jeff Prosise's MFC bible as a little gift to myself the Christmas before last, and have read the first three chapters!
    Wave upon wave of demented avengers march cheerfully out of obscurity unto the dream.

  10. #10
    Registered User
    Join Date
    Apr 2002
    Posts
    77
    Originally posted by adrianxw
    >>> :: hides in shame at my lack of MFC knowledge ::

    Nothing to be ashamed of. I bought Jeff Prosise's MFC bible as a little gift to myself the Christmas before last, and have read the first three chapters!
    is the book gd ???
    becoz i have bought the microsoft's one but not very good.
    can i have the title of your book, so i can make a search at my school libery

  11. #11
    It's full of stars adrianxw's Avatar
    Join Date
    Aug 2001
    Posts
    4,829
    It is supposedly the definitive work, but it is an MS book. "Programming Windows with MFC" make sure you have the second edition.

    http://www.amazon.co.uk/exec/obidos/...530542-7359833
    Wave upon wave of demented avengers march cheerfully out of obscurity unto the dream.

  12. #12
    Registered User
    Join Date
    Feb 2002
    Posts
    589
    I recently finished that book and I liked it alot. Although I dont think it is a great book if you are a beginer in Mfc. I would rather recomend "Teach yourself VC++ in 21 days" because in that book you write apps from the first page. The Prosise's book is the true Mfc bible and it is open on my desk 90% of the time I program, a great reference.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 1
    Last Post: 04-09-2009, 02:31 AM
  2. Ownerdraw buttons (2)
    By maes in forum Windows Programming
    Replies: 7
    Last Post: 09-11-2003, 05:50 AM
  3. Radio Buttons in Visual C++ 6
    By Ripper1 in forum Windows Programming
    Replies: 22
    Last Post: 05-16-2003, 07:54 AM
  4. (Ken Fitlike) buttons
    By jdinger in forum C++ Programming
    Replies: 4
    Last Post: 03-15-2002, 01:21 PM
  5. Grouping radio buttons
    By Bazz in forum Windows Programming
    Replies: 1
    Last Post: 08-28-2001, 07:15 AM