VC里移动无标题窗口

自己处理WM_NCHITTEST消息,将如果鼠标点击在客户区则置换为标题栏:

LRESULT CMainDlg::OnNchitTest( UINT /*uMsg*/, WPARAM wParam, LPARAM lParam, BOOL& /*bHandled*/ )

{
UINT nHitTest;
nHitTest = ::DefWindowProc(m_hWnd,WM_NCHITTEST,wParam,lParam);
if(nHitTest == HTCLIENT && ::GetAsyncKeyState(MK_LBUTTON) < 0)
{
nHitTest = HTCAPTION;
}
return nHitTest;

}

顺便粘贴下WM_NCHITEST消息的MSDN:

Sent to a window in order to determine what part of the window corresponds to a particular screen coordinate. This can happen, for example, when the cursor moves, when a mouse button is pressed or released, or in response to a call to a function such as WindowFromPoint. If the mouse is not captured, the message is sent to the window beneath the cursor. Otherwise, the message is sent to the window that has captured the mouse.

A window receives this message through its WindowProc function.

#define WM_NCHITTEST                    0x0084
#define WM_NCHITTEST                    0x0084

Parameters

wParam

This parameter is not used.

lParam

The low-order word specifies the x-coordinate of the cursor. The coordinate is relative to the upper-left corner of the screen.

The high-order word specifies the y-coordinate of the cursor. The coordinate is relative to the upper-left corner of the screen.

Return Value

The return value of the DefWindowProc function is one of the following values, indicating the position of the cursor hot spot.

Return code/valueDescription
HTBORDER 18

In the border of a window that does not have a sizing border.

HTBOTTOM 15

In the lower-horizontal border of a resizable window (the user can click the mouse to resize the window vertically).

HTBOTTOMLEFT 16

In the lower-left corner of a border of a resizable window (the user can click the mouse to resize the window diagonally).

HTBOTTOMRIGHT 17

In the lower-right corner of a border of a resizable window (the user can click the mouse to resize the window diagonally).

HTCAPTION 2

In a title bar.

HTCLIENT 1

In a client area.

HTCLOSE 20

In a Close button.

HTERROR -2

On the screen background or on a dividing line between windows (same as HTNOWHERE, except that the DefWindowProc function produces a system beep to indicate an error).

HTGROWBOX 4

In a size box (same as HTSIZE).

HTHELP 21

In a Help button.

HTHSCROLL 6

In a horizontal scroll bar.

HTLEFT 10

In the left border of a resizable window (the user can click the mouse to resize the window horizontally).

HTMENU 5

In a menu.

HTMAXBUTTON 9

In a Maximize button.

HTMINBUTTON 8

In a Minimize button.

HTNOWHERE 0

On the screen background or on a dividing line between windows.

HTREDUCE 8

In a Minimize button.

HTRIGHT 11

In the right border of a resizable window (the user can click the mouse to resize the window horizontally).

HTSIZE 4

In a size box (same as HTGROWBOX).

HTSYSMENU 3

In a window menu or in a Close button in a child window.

HTTOP 12

In the upper-horizontal border of a window.

HTTOPLEFT 13

In the upper-left corner of a window border.

HTTOPRIGHT 14

In the upper-right corner of a window border.

HTTRANSPARENT -1

In a window currently covered by another window in the same thread (the message will be sent to underlying windows in the same thread until one of them returns a code that is not HTTRANSPARENT).

HTVSCROLL 7

In the vertical scroll bar.

HTZOOM 9

In a Maximize button.

Remarks

Use the following code to obtain the horizontal and vertical position:

xPos = GET_X_LPARAM(lParam); 
  yPos = GET_Y_LPARAM(lParam);
  
xPos = GET_X_LPARAM(lParam); 
yPos = GET_Y_LPARAM(lParam);

You can also use the MAKEPOINTS macro to convert the lParam parameter to a POINTS structure.

Windows Vista: When creating custom frames that include the standard caption buttons, this message should first be passed to the DwmDefWindowProc function. This enables the Desktop Window Manager (DWM) to provide hit-testing for the captions buttons. If DwmDefWindowProc does not handle the message, further processing of WM_NCHITTEST may be needed. 


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值