Sign in to follow this  

Making a child window act like a title bar?

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

If you intended to correct an error in the post then please contact us.

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 this post


Link to post
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 window
bool 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 this post


Link to post
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 this post


Link to post
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 this post


Link to post
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 this post


Link to post
Share on other sites

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

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this