Thread: Stupid buttons...

  1. #16
    Registered User
    Join Date
    Dec 2001
    Posts
    421
    instantiate a button.. and create your own WndProc that will handle the messages for that button

    then prevProc = SetWindowLong(hButtn, GWL_WNDPROC, (long)NewWndProc);

    this will let you capture the messages..

    inside your new window procedure make sure you pass the messages onto the control when you have done your handling by using CallWindowProc() (or something like that).

    make sure you set the window proc back to what it was before destroying the control!

    this is just to give you the idea... i can't remember all the function names and parameters.. but they should be pretty close.

    hope this helps
    U.
    Quidquid latine dictum sit, altum sonatur.
    Whatever is said in Latin sounds profound.

  2. #17
    erstwhile
    Join Date
    Jan 2002
    Posts
    2,227
    To add to Uraldor's info:

    1. Create the control normally.
    2. Create your own DIY wndproc for the button control eg BtnProc.
    3. Declare a WNDPROC variable to store the original wndproc eg

    WNDPROC OldCntrlProc=(WNDPROC)SetWindowLong(hBtn,GWL_WNDPR OC,(LONG)BtnProc);
    The return value cast may not be necessary in 'C'. Also there is a new fn, SetWindowLongPtr, that
    supercedes SetWindowLong (get ready for 64bit...) that you may also wish to look at.
    4. Then in BtnProc:
    Code:
    LRESULT CALLBACK BtnProc(HWND hwnd,UINT uMsg,WPARAM wParam,LPARAM lParam)
    {
    switch (uMsg)
        {
        case WM_LBUTTONDBLCLK:   //optional
        case WM_LBUTTONDOWN:
            {
             SendMessage(hwnd,WM_SYSCOMMAND,0xF012,0);	/*0xF012=SC_MOVE+HTCAPTION*/
             return 0; 
            }
        default: /*pass unhandled msgs to system for default handling*/
            return CallWindowProc(OldCntrlProc,hwnd,uMsg,wParam,lParam);
        }
    }
    Same as any other wndproc, except for the default handling fn. When you are done with the control, restore the original wndproc:

    SetWindowLong(hBtn,GWL_WNDPROC,(LONG)OldCntrlProc) ;

    Hope that's of some use to you.
    Last edited by Ken Fitlike; 02-19-2002 at 12:54 AM.

  3. #18
    Just one more wrong move. -KEN-'s Avatar
    Join Date
    Aug 2001
    Posts
    3,227
    I love you all!

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