Making a child window act like a title bar?

This topic is 5031 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

Recommended Posts

How do I make a child window act like a titlebar? , what I want is that if I click on the child window I can drag the parent around like a title bar, it doesnt have to be a child actually , I looked into GetWindowPlacement I think it was but theres more data than I need , I need to be able to get the window position , and then change it according to the mmouse drag movement.. I think

Share on other sites
I don't know of an automatic way to do this but it shouldn't be hard to do it manually. Handle WM_LBUTTONDOWN/LBUTTONUP and WM_MOUSEMOVE. When you get a WM_LBUTTONDOWN message, set a flag somewhere indicating that. When you get WM_LBUTTONUP, clear that flag. When you get WM_MOUSEMOVE, do something like this:
int OldX, OldY;HWND FrameWnd; // main windowbool lButtonDown; // flag for left mouse button pressed...case WM_MOUSEMOVE:   {      int x = LOWORD(lParam);       int y = HIWORD(lParam);      int dx = x - OldX;      int dy = y - OldY;      // edit: forgot this ;)      OldX = x;      OldY = y;            if(lButtonDown)      {         RECT WindowRect;         GetWindowRect(FrameWnd, &WindowRect);               int Width = WindowRect.right - WindowRect.left;         int Height = WindowRect.bottom - WindowRect.top;         WindowRect.left += dx;         WindowRect.top += dy;         MoveWindow(FrameWnd, WindowRect.left, WindowRect.top, Width, height, TRUE);      }   }   break;

Share on other sites
Doing MoveWindow or the like constantly would annoy those people such as myself that have 'show window contents while dragging' set to off. You'll need to figure out how to initiate the standard 'drag border of window' thingy so it will work properly for everybody.

Sorry, I don't know how to do that.

As far as getting the window position, I believe GetWindowRect will work for you.

Share on other sites
hmm thats interesting kibble , I tried something similar but it was pretty ugly , I thort someone might have a different approach , thanks for the help I'll try something more like ur idea

Share on other sites
You'd have to intercept WM_NCHITTEST (of the parent) and if the mouse is over the child window return HTCAPTION. Otherwise let the defwindowproc handle it.

Share on other sites
oh , and how would I go about that?

Share on other sites
In your WM_NCHITTEST lParam is the mouse pos (in screen coordinates), you'd just return HTCAPTION if the pos is inside the child window. Windows will handle the rest. Like this:

case WM_NCHITTEST:  {    POINT pt;    pt.x = LOWORD( lParam );    pt.y = HIWORD( lParam );        // retrieve HWND of Client Window    HWND  hwndClientWindow = GetDlgItem( ID_OF_CLIENT_WINDOW );    // get Window rect (provided in screen coordinates too)    RECT   rc;    ::GetWindowRect( hwndClientWindow, &rc );    if ( PtInRect( &rc, pt ) )    {      // Point is inside the child window      return HTCAPTION;    }    // other cases, let Windows handle the rest  }  break;

This assumes that not handled cases are passed to the base class' windowproc or to DefWindowProc.

Share on other sites
oh i think I sorta get it now , I'll mess with it a lil

• 11
• 20
• 12
• 10
• 34
• Forum Statistics

• Total Topics
631399
• Total Posts
2999853
×