📄 how to move dialog which dose not have a caption.html
字号:
<H1>How to move dialog which dose not have a caption</H1>
<H2>Introduction</H2>
<P nd="1">This article is aimed at the beginners and presents two ways to move a
dialog which does not have a caption by dragging its client area.</P>
<H2>1. WM_SYSCOMMAND message</H2>
<P nd="2">Sending the <CODE nd="3">WM_SYSCOMMAND</CODE> message starts the move
operation.
Add the following code to handle the mouse down event:</P><PRE nd="4">BEGIN_MSG_MAP(CMainDlg)
...
MESSAGE_HANDLER(WM_LBUTTONDOWN, OnLButtonDown)
END_MSG_MAP()
LRESULT OnLButtonDown(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
{
SendMessage(WM_SYSCOMMAND, SC_MOVE|0x0002);
return 0;
}
</PRE>
<P nd="5">One note though: specifying just <CODE nd="6">SC_MOVE</CODE> in a
<CODE nd="7">WM_SYSCOMMAND</CODE> message tells Windows that you are moving the
dialog by using the keyboard. To indicate that you want to move the dialog by
using the mouse, you must specify <CODE nd="8">SC_MOVE|0x0002</CODE>.</P>
<H2>2. WM_NCHITTEST message</H2>
<P nd="9">The idea is to handle the <CODE nd="10">WM_NCHITTEST</CODE> message to
return <CODE nd="11">HTCAPTION</CODE> instead of <CODE nd="12">HTCLIENT</CODE>
when the mouse is in the client area to trick Windows to start moving the
dialog.</P><PRE nd="13">BEGIN_MSG_MAP(CMainDlg)
...
MESSAGE_HANDLER(WM_NCHITTEST, OnNcHitTest)
END_MSG_MAP()
LRESULT OnNcHitTest(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
{
if (::DefWindowProc(m_hWnd, uMsg, wParam, lParam) == HTCLIENT && ::GetAsyncKeyState(MK_LBUTTON) < 0)
return HTCAPTION;
return 0;
}
</PRE>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -