
Moving windows without visible caption
Quote:
>I'm trying to implement a frame window/dialog which is completely filled by
>a bitmap like a splash window BUT can be dragged over the screen like any
>other top level window.
>I have played around with a thin border window and tried to handle the mouse
>events in a suggested caption region but with no satisfactory result.
Let's take the easy case first: Suppose that you want the window to be
draggable by any point within it. In other words, the user can put the
cursor anywhere within the window and drag to move the window.
To do this, you just need to override OnNcHitTest; your handler should
look like this:
afx_msg UINT CMyWindowClass::OnNcHitTest(CPoint point)
{
UINT nArea = CWnd::OnNcHitTest(point);
// This assumes that your window class derives from CWnd; if it derives
// from CDialog or some other class, you should call that class's
// OnNcHitTest instead
if (nArea == HTCLIENT) {
nArea = HTCAPTION;
}
return nArea;
Quote:
}
Basically, this handler will make Windows' mouse-handling logic believe
that your entire window is a gigantic caption bar; and when the user drags on
a caption bar, Windows' default handler moves the window. So with this code,
you don't have to implement your own mouse-handling or window-moving logic at
all; Windows will take care of all of it for you, just as it normally does
when a window is dragged by its caption bar.
If you want your window to only be draggable by some parts of its area,
your OnNcHitTest handler will need to be a bit more picky; it will need to
check that "point" value passed in (which is the coordinates of the cursor,
in screen coordinates), and see whether or not HTCAPTION should be returned.
For example, the following handler makes the window draggable, but only if
the cursor is within ten pixels of the top of the window:
afx_msg UINT CMyWindowClass::OnNcHitTest(CPoint point)
{
UINT nArea = CWnd::OnNcHitTest(point);
// This assumes that your window class derives from CWnd; if it derives
// from CDialog or some other class, you should call that class's
// OnNcHitTest instead
if (nArea == HTCLIENT) {
CPoint clientPoint = point;
ScreenToClient(clientPoint);
if (clientPoint.x < 10) {
nArea = HTCAPTION;
}
}
return nArea;
Quote:
}
--
\o\ If you're interested in books and stories with transformation themes, \o\
/o/ please have a look at <URL: http://www.*-*-*.com/ ;. Thanks! /o/
\o\ FC1.21:FC(W/C)p6arw A- C->++ D>++ H+ M>+ P R T++++ W** Z+ Sm RLCT \o\
/o/ a cmn++++$ d e++ f+++ h- i++wf p-- sm# /o/