谁能给我详解一下 WM_NCHITTEST?(100分)

  • 主题发起人 主题发起人 omvm
  • 开始时间 开始时间
O

omvm

Unregistered / Unconfirmed
GUEST, unregistred user!
谁能给我详解一下 WM_NCHITTEST?
别叫我看帮助,我e文不好,看了半天,还是不很明白。
 
该消息主要是告诉一个窗口的鼠标移动、按下、释放。

SendMessage(Form1,WM_NCHITTEST,lParam,WParam);
其中
xPos = LOWORD(lParam); // 低位字节为鼠标的横坐标
yPos = HIWORD(lParam); //高位字节为鼠标的纵坐标。
你可以用MAKEPOINTS 函数将lParam参数转化为点结构


 
这个我知道,只是不明白它的返回值是什么意思?比如说返回 HTNOWHERE 代表什么?
下面这段程序中这句是什么意思。
procedure TDongComboBox.WMNCHitTest ( var Message: TWMNCHitTest );
begin
inherited;

if ( Message.Result = HTNOWHERE ) then
Message.Result := HTBORDER;
end;
 
当窗口需要确定鼠标位置时Windows向窗口发送WM_NCHITTEST信息,
可以处理该信息使Windows认为鼠标在窗口标题上。对于对话框和基于对话的应用程序,
可以使用ClassWizard处理该信息并调用基类函数, 如果函数返回HTCLIENT
则表明鼠标在客房区域,返回HTCAPTION表明鼠标在Windows的标题栏中。
 
谢谢only you 和arnew,可其它的返回值代表的含义是什么。比如说我上面的例子。哪位能
给出详细的说明呢?
 
HTBORDER In the border of a window that does not have a sizing border
HTBOTTOM In the lower horizontal border of a window
HTBOTTOMLEFT In the lower-left corner of a window border
HTBOTTOMRIGHT In the lower-right corner of a window border
HTCAPTION In a title bar
HTCLIENT In a client area
HTERROR 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 In a size box (same as HTSIZE)
HTHSCROLL In a horizontal scroll bar
HTLEFT In the left border of a window
HTMENU In a menu
HTNOWHERE On the screen background or on a dividing line between windows
HTREDUCE In a Minimize button
HTRIGHT In the right border of a window
HTSIZE In a size box (same as HTGROWBOX)
HTSYSMENU In a System menu or in a Close button in a child window
HTTOP In the upper horizontal border of a window
HTTOPLEFT In the upper-left corner of a window border
HTTOPRIGHT In the upper right corner of a window border
HTTRANSPARENT In a window currently covered by another window
HTVSCROLL In the vertical scroll bar
HTZOOM In a Maximize button

HTNOWHERE 代表非客户区域
 
没有人知道吗?
 
这个消息返回值表示鼠标点击的位置。
我试着把sbbrf的翻译一下吧。
HTBORDER In the border of a window that does not have a sizing border
窗口的边界上,这个窗口没有可以改变大的边界
HTBOTTOM In the lower horizontal border of a window
窗口的下边界
HTBOTTOMLEFT In the lower-left corner of a window border
左下角
HTBOTTOMRIGHT In the lower-right corner of a window border
右下角
HTCAPTION In a title bar
标题栏上
HTCLIENT In a client area
客户区域
HTERROR 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)
在屏幕的背景或是两个窗口的边界线上(和HTNOWHERE基本上一样,除了会导致一声怪叫外,呵呵)
HTGROWBOX In a size box (same as HTSIZE)
可变大小的box里
HTHSCROLL In a horizontal scroll bar
水平滚动条
HTLEFT In the left border of a window
左边界
HTMENU In a menu
菜单
HTNOWHERE On the screen background or on a dividing line between windows
在屏幕的背景或是两个窗口的边界线上
HTREDUCE In a Minimize button
在最小化按钮上
HTRIGHT In the right border of a window
右边界
HTSIZE In a size box (same as HTGROWBOX)
同HTGROWBOX
HTSYSMENU In a System menu or in a Close button in a child window
系统菜单或是子窗体的关闭按钮上
HTTOP In the upper horizontal border of a window
上边界
HTTOPLEFT In the upper-left corner of a window border
左上角
HTTOPRIGHT In the upper right corner of a window border
右上角
HTTRANSPARENT In a window currently covered by another window
在被当前窗口遮盖的另一个窗体上
HTVSCROLL In the vertical scroll bar
垂直滚动条
HTZOOM In a Maximize button
最大化按钮上

 
谢了,能不能解释一下我举的例子?不能也罢了。能了更好。
 
这个消息的具体作用就是, 让你根据给出坐标来决定告诉系统鼠标在窗体的什么位置.
不论坐标是什么, 在hitResult你告诉系统是什么位置系统就认为是什么了.

下面是一个例子, 当鼠标在Form上的时候, 告诉系统你的鼠标实在Form上面的Caption区域,
不论在什么位置, 你都可以拖着Form移动.

type
TForm1 = class(TForm)
private
procedure WMNCHitTest(var Message: TWMNCHitTest); message WM_NCHITTEST;
public
end;

var
Form1: TForm1;

implementation

{$R *.DFM}

{ TForm1 }

procedure TForm1.WMNCHitTest(var Message: TWMNCHitTest);
begin
Message.Result := HTCaption;
end;

end.
 
再给你一个离子, 只把你Form的下半部分当作Form的Caption, 其余照旧

procedure TForm1.WMNCHitTest(var Message: TWMNCHitTest);
var
P: TPoint;
begin
P := ScreenToClient(SmallPointToPoint(message.Pos));
if P.Y > Height div 2 then
Message.Result := HTCaption
else
inherited;
end;
 
多人接受答案了。
 
后退
顶部