novel method of dragging

This is a discussion on novel method of dragging within the Windows Programming forums, part of the Platform Specific Boards category; Hello again, so I saw this novel method to initiate dragging of a window: Code: SendMessage(hWnd, WM_NCLBUTTONDOWN, HTCAPTION,0); It tricks ...

  1. #1
    Registered User
    Join Date
    Jan 2005
    Posts
    108

    novel method of dragging

    Hello again,

    so I saw this novel method to initiate dragging of a window:

    Code:
       SendMessage(hWnd, WM_NCLBUTTONDOWN, HTCAPTION,0);
    It tricks window into thinking that the title bar is mousedown'ed. The problem is I need to know when the user has finished dragging (i.e mouseupped), but the message for that seems to be intercepted by windows somehow.

    Is anyone familiar with the trick and know how to get the mouse-up of this thing? Otherwise, I'll actually have to implement an actual dragging routine, and that will probably be annoying..

    Cheers, and thanks in advance!

  2. #2
    erstwhile
    Join Date
    Jan 2002
    Posts
    2,227
    >>I saw this novel method to initiate dragging of a window<<

    It's a variation on a theme; another is:
    Code:
    SendMessage(hwnd,WM_SYSCOMMAND,HTCAPTION|SC_MOVE, lParam);
    (search this board for that one). Ultimately, all that's happening is something like:
    Code:
    case WM_NCHITTEST:
      if (GetAsyncKeyState(VK_LBUTTON)&0x8000)
        {
        return HT_CAPTION;
        }
      else
        {
        /*return default handling (DefWindowProc,CallWindowProc etc.)*/
        }
    (check out WM_NCHITTEST).

    From what I understand, WM_NCHITTEST effectively synthesises the other mouse messages so, when you skew its behaviour by telling it it's left-clicked on the caption, this is responsible for the loss of the other mouse messages.

    So, you can either

    1. synthesise the mouse message of interest yourself, eg for WM_LBUTTONUP, something like:
    Code:
    case WM_NCHITTEST:
      {
      static BOOL bIsLButtonDown;
      if (GetAsyncKeyState(VK_LBUTTON)&0x8000)
        {
        bIsLButtonDown=TRUE;
        return HTCAPTION;
        }
      else
        {
        if (bIsLButtonDown==TRUE)
          {
          POINT pt={LOWORD(lParam),HIWORD(lParam)};
          UINT uFlags=0;
          
          bIsLButtonDown=FALSE;
          /*need to convert mouse coords*/
          ScreenToClient(hwnd,&pt);
          /*synthesise mouse up event*/
          /*first get state of other mouse buttons; should, ideally get 
            key states of SHIFT and CTRL buttons on keyboard, too.*/ 
          if (GetAsyncKeyState(VK_MBUTTON)&0x8000)
            {
            uFlags|=MK_MBUTTON;
            }
          if (GetAsyncKeyState(VK_RBUTTON)&0x8000)
            {
            uFlags|=MK_RBUTTON;
            }
        SendMessage(hwnd,WM_LBUTTONUP,uFlags,MAKELPARAM( pt.x,pt.y));
        }
      /*return DefWindowProc,CallWindowProc etc*/
      }
    or,

    2. much simpler, you could just handle the WM_EXITSIZEMOVE message, ie.
    Code:
    case WM_EXITSIZEMOVE:
      {
      if (!GetAsyncKeyState(VK_LBUTTON)&0x8000)
        {
        /*mouse L-button is up*/
        }
      return 0;
      }
    Please note that GetAsyncKeyState works with physical mouse buttons so may not necessarily correspond to the way a user may have configured their mouse (GetSystemMetrics will resolve any uncertainty here).
    Last edited by Ken Fitlike; 02-05-2005 at 03:49 PM. Reason: typos
    CProgramming FAQ
    Caution: this person may be a carrier of the misinformation virus.

  3. #3
    Registered User
    Join Date
    Jan 2005
    Posts
    108
    thanks, that really clears it up

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. on method pointers and inheritance
    By BrownB in forum C++ Programming
    Replies: 2
    Last Post: 03-02-2009, 07:50 PM
  2. stuck on display method
    By shintaro in forum C++ Programming
    Replies: 2
    Last Post: 02-01-2009, 05:17 PM
  3. Best communication method to thousand childs?
    By Ironic in forum C Programming
    Replies: 8
    Last Post: 11-08-2008, 12:30 AM
  4. C# method
    By siten0308 in forum C# Programming
    Replies: 6
    Last Post: 07-15-2008, 08:01 AM
  5. Replies: 2
    Last Post: 01-22-2008, 04:22 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21