谈无标题窗口的拖放

[入库:2005年8月18日] [更新:2007年3月24日]

本文简介:选择自 canvashat 的 blog

从微软的站点看到一个简单的方法实现,不必计算rect,不必处理鼠标消息的细节和窗口绘制,就能轻松实现没有标题栏的窗口移动的问题,就是使用onnchittest消息。

手工增加该消息映射:
用classwizard是无法增加该消息的,在begin_message_map中加入消息on_wm_nchittest(),然后在头文件中加入
afx_msg uint onnchittest(cpoint point);

在实现文件中,加入lbuttondown消息函数

void cclyzdlg::onlbuttondown(uint nflags, cpoint point)
{
ctrandialog::onlbuttondown(nflags, point);//把ctrandialog改成你的基类
postmessage( wm_nclbuttondown, htcaption, makelparam( point.x, point.y));
}

加入nchittest消息函数

uint cclyzdlg::onnchittest(cpoint point)
{
uint nhittest = ctrandialog::onnchittest( point );//把ctrandialog改成你的基类
return (nhittest == htclient) ? htcaption : nhittest;
}

编译运行,没有出错就完成了,前后不到十行代码。

我用基于对话框的应用程序,在vc6.0,winnt4.0下编译,运行良好。 

本文关键:谈无标题窗口的拖放
  相关方案
Google
 

本站最佳浏览方式为 分辨率 1024x768 IE 6.0(或更高版本的 IE浏览器)

go top