1
我做了一個用純WinAPI編寫的編輯器。一些用戶希望標題圖標成爲在編輯器中打開的文件的拖動源,就像瀏覽器窗口所做的一樣。我不知道要實現這樣的功能。有人可以給我舉個例子嗎?使標題圖標成爲瀏覽器窗口的拖動源
我做了一個用純WinAPI編寫的編輯器。一些用戶希望標題圖標成爲在編輯器中打開的文件的拖動源,就像瀏覽器窗口所做的一樣。我不知道要實現這樣的功能。有人可以給我舉個例子嗎?使標題圖標成爲瀏覽器窗口的拖動源
這裏是示出如何使用該系統菜單(「字幕圖標」),以檢測何時發起拖放操作的示例:
class SysMenuDragSample
: public CWindowImpl< SysMenuDragSample, CWindow, CFrameWinTraits >
{
private:
static const UINT WM_SHOWSYSTEMMENU = 0x313;
bool mouse_down_in_sys_menu_;
public:
BEGIN_MSG_MAP_EX(SysMenuDragSample)
MSG_WM_NCLBUTTONDOWN(OnNcLButtonDown)
MSG_WM_NCLBUTTONUP(OnNcLButtonUp)
MSG_WM_MOUSEMOVE(OnMouseMove)
MSG_WM_LBUTTONUP(OnLButtonUp)
END_MSG_MAP()
SysMenuDragSample()
: mouse_down_in_sys_menu_(false)
{
}
void BeginDragDropOperation()
{
// TODO: Implement
}
void OnNcLButtonDown(UINT hit_test, CPoint cursor_pos)
{
if(hit_test == HTSYSMENU)
{
mouse_down_in_sys_menu_ = true;
SetCapture();
// NOTE: Future messages will come through WM_MOUSEMOVE, WM_LBUTTONUP, etc.
}
else
SetMsgHandled(FALSE);
}
void OnNcLButtonUp(UINT hit_test, CPoint cursor_pos)
{
if(hit_test == HTSYSMENU)
{
// This message and hit_test combination should never be received because
// SetCapture was called in OnNcLButtonDown.
assert(false);
}
else
SetMsgHandled(FALSE);
}
void OnMouseMove(UINT modifiers, CPoint cursor_pos)
{
if(mouse_down_in_sys_menu_)
{
ClientToScreen(&cursor_pos);
UINT hit_test = SendMessage(WM_NCHITTEST, 0, MAKELPARAM(cursor_pos.x, cursor_pos.y));
if(hit_test != HTSYSMENU)
{
// The cursor has moved outside of the system menu icon so begin the drag-
// drop operation.
mouse_down_in_sys_menu_ = false;
ReleaseCapture();
BeginDragDropOperation();
}
}
else
SetMsgHandled(FALSE);
}
void OnLButtonUp(UINT modifiers, CPoint cursor_pos)
{
if(mouse_down_in_sys_menu_)
{
// The button was released inside the system menu so simulate a normal click.
mouse_down_in_sys_menu_ = false;
ReleaseCapture();
ClientToScreen(&cursor_pos);
SendMessage(WM_SHOWSYSTEMMENU, 0, MAKELPARAM(cursor_pos.x, cursor_pos.y));
}
else
SetMsgHandled(FALSE);
}
};