views:

87

answers:

2

I have an MFC application running in Win7 with no Titlebar (i.e. My title bar is home-cooked, with custom buttons for restore, maximize and close). In Win7 it responds to the maximize event generated by the Win 7 API when a user drags the window to the top of the screen. However, once it's maximized, I can't capture the restore event that occurs when a user drags the window off the top.

I handle the restore on double click, I handle the restore on a click of the restore button, but the drag I can't detect.

I would imagine that it would look similar to:

if (message == WM_WINDOWPOSCHANGING)
{
    // DETECT RESTORE MSG HERE.
}

But that doesn't seem to catch it. It's as if somewhere I've disabled moving the window when it's been maximized.

Is there a way perhaps that I'm preventing the WM_RESIZE? How do I handle the drag event to enable the auto-resize?

A: 

I discovered that since the app doesn't have a Titlebar, win7 doesn't handle the window drag and therefore doesn't send the WM_SYSCOMMAND at all. In other words, the application was blocking the Titlebar drag because there was no Titlebar to drag.

The solution is in part to detect a drag on our mocked up titlebar. After that the window must be restored in SIZE only, not in position. The position needs to be dynamic to the cursor, just like Win7 does it. Thoughts, people?

Mike Caron
+1  A: 

Have you tried handling the WM_NCHITTEST message returning HTCAPTION (titlebar) when the mouse is over your custom title bar thus allowing normal windows processing to occur without any further customization?

Ruddy
I'll try that! Thanks!
Mike Caron
That doesn't work because our false titlebar is actually a ribbon (from CWnd). When I capture the hit test and return that it's an HTCaption, then the ribbon is dragged around the main frame and clipped at the edges of the window. :(
Mike Caron
well that's unfortunate. my only other thought would be to change the UI some to allow a "drag area" to show through from the main window - then the WM_NCHITTEST would work -- similar to how Chrome works perhaps.
Ruddy
Yeah, I was wondering how Chrome managed to get the drag-to-restore functionality.
Mike Caron
Looks like Google has created their own WS_CAPTION style.
Mike Caron
check out http://www.codeguru.com/cpp/frameworks/advancedui/article.php/c3215/ - specifically (imo) CMultiLineCaption - effectively you want that in reverse i suspect to make a smaller caption...
Ruddy