Thread: A little GDI/Msg type problemo

  1. #1

    A little GDI/Msg type problemo

    [edit:]

    Code:
    case WM_LBUTTONDBLCLK:
            {
             cCLRBTN *clrbtn = (cCLRBTN*)GetWindowLong ( hwnd, GWL_USERDATA );
             clrbtn->down = true;
             InvalidateRect ( hwnd, NULL, TRUE );
             UpdateWindow ( hwnd );
             clrbtn->down = false;
             InvalidateRect ( hwnd, NULL, TRUE );
             UpdateWindow ( hwnd );
             SendMessage ( GetParent ( hwnd ), WM_COMMAND,
                (WPARAM)MAKEWPARAM((int)GetWindowLong ( hwnd, GWL_ID ),0 ), (LPARAM)hwnd  );
            }
            case WM_LBUTTONDOWN:
            {
             SetCapture ( hwnd );
             cCLRBTN *clrbtn = (cCLRBTN*)GetWindowLong ( hwnd, GWL_USERDATA );
             clrbtn->down = true;
             InvalidateRect ( hwnd, NULL, TRUE );
             UpdateWindow ( hwnd );
             return 0;
            }
            case WM_LBUTTONUP:
            {
             cCLRBTN *clrbtn = (cCLRBTN*)GetWindowLong ( hwnd, GWL_USERDATA );
             if ( clrbtn->down )
             {
              clrbtn->down = false;
              InvalidateRect ( hwnd, NULL, TRUE );
              UpdateWindow ( hwnd );
              SendMessage ( GetParent ( hwnd ), WM_COMMAND,
                (WPARAM)MAKEWPARAM((int)GetWindowLong ( hwnd, GWL_ID ),0 ), (LPARAM)hwnd  );
             }
             ReleaseCapture ( );
             return 0;
            }
    As you can see from that exerpt from my switch ( msg ) thingy I capture the mouse when it's down and release it when it's up, this way if you click and drag outside of my control (which is a button) it will still reset it's down status to false.

    However I'd rather that if you moved outside the control it popped up and it's down status was returned to false, just like other buttons.. This way you can drag outside of it and let go and you won't execute it's action.
    Last edited by Mithoric; 02-21-2004 at 08:16 AM.

  2. #2
    erstwhile
    Join Date
    Jan 2002
    Posts
    2,227
    Here's a way:
    Code:
    case WM_LBUTTONUP:
    {
      RECT rc;
      POINT pt={LOWORD(lParam),HIWORD(lParam)};
      GetClientRect(hwnd,&rc);
      if (PtInRect(&rc,pt))
      {
        /*do stuff*/
      }
    }
    CProgramming FAQ
    Caution: this person may be a carrier of the misinformation virus.

  3. #3
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,895
    There's a function called TrackMouseEvent that you can call to receive a mouseout message.
    All the buzzt!
    CornedBee

    "There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
    - Flon's Law

  4. #4
    Oh goody, both of your posts are very helpful indeed..

    Cheers!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 0
    Last Post: 03-20-2008, 07:59 AM
  2. Little Array Difficulty
    By G4B3 in forum C Programming
    Replies: 16
    Last Post: 03-19-2008, 12:59 AM
  3. Replies: 28
    Last Post: 07-16-2006, 11:35 PM
  4. Errors
    By Rhidian in forum C Programming
    Replies: 10
    Last Post: 04-04-2005, 12:22 PM
  5. gcc problem
    By bjdea1 in forum Linux Programming
    Replies: 13
    Last Post: 04-29-2002, 06:51 PM