: I want to have a window that has no title bar so you can't move it around. I've tried this but something is wrong because it disappears when using it:
:
:
void CMoveagainDlg::OnMouseMove(UINT nFlags, CPoint point)
: {
: if((nFlags & MK_LBUTTON) == MK_LBUTTON)
: {
: cpPos.x = point.x;
: cpPos.y = point.y;
:
: MoveWindow(cpPos.x,cpPos.y,0,0,TRUE);
: }
:
: CDialog::OnMouseMove(nFlags, point);
: }
:
: Do I have to handle a WM_LBUTTONDON message to? if so, for what!
I wrote a little routine for that a long time ago...
//------------------------------------------------------------------------------
// HandleClientAreaDragMsg() - Eric Tetz 7/13/99
//
// If you pass WM_LBUTTONDOWN, WM_LBUTTONUP, and WM_MOUSEMOVE messages to this
// function, it will enable "client area drag" for the window.
//------------------------------------------------------------------------------
static void HandleClientAreaDragMsg (HWND hwnd, UINT msg, int mouseX, int mouseY)
{
static int captureX = 0;
static int captureY = 0;
switch (msg)
{
case WM_LBUTTONDOWN:
captureX = mouseX;
captureY = mouseY;
SetCapture (hwnd);
break;
case WM_LBUTTONUP:
ReleaseCapture();
break;
case WM_MOUSEMOVE:
if (GetCapture() == hwnd)
{
RECT rc;
GetWindowRect (hwnd, &rc);
int newX = rc.left + mouseX - captureX;
int newY = rc.top + mouseY - captureY;
int width = rc.right - rc.left;
int height = rc.bottom - rc.top;
UINT flags = SWP_NOZORDER | SWP_NOACTIVATE;
SetWindowPos (hwnd, NULL, newX, newY, width, height, flags);
}
break;
}
}It's written using the raw API, but you can easily use it in your MFC app like this:
void CMoveagainDlg::OnLButtonDown(UINT nFlags, CPoint point)
{
HandleClientAreaDrag(m_hWnd, WM_LBUTTONDOWN, point.x, point.y);
CDialog::OnLButtonDown(nFlags, point);
}
void CMoveagainDlg::OnLButtonUp(UINT nFlags, CPoint point)
{
HandleClientAreaDrag(m_hWnd, WM_LBUTTONUP, point.x, point.y);
CDialog::OnLButtonUp(nFlags, point);
}
void CMoveagainDlg::OnMouseMove(UINT nFlags, CPoint point)
{
HandleClientAreaDrag(m_hWnd, WM_MOUSEMOVE, point.x, point.y);
CDialog::OnMouseMove(nFlags, point);
}Cheers,
Eric