15,979
社区成员
发帖
与我相关
我的任务
分享
BOOL PreTranslateMessage(MSG *pMsg)
{
static POINT ptLast;
// TODO: Add your specialized code here and/or call the base class
if(pMsg->message==WM_MOUSEMOVE)
{
if(MK_LBUTTON==pMsg->wParam)
{
RECT rc;
GetWindowRect(pMsg->hwnd,&rc);// desk
MoveWindow(pMsg->hwnd, rc.left+(pMsg->pt.x-ptLast.x), rc.top+(pMsg->pt.y-ptLast.y),
rc.right-rc.left, rc.bottom-rc.top, TRUE);
ptLast=pMsg->pt;// screen coord
}
else
{
ptLast=pMsg->pt;// screen coord
}
return TRUE;
}
return FALSE;
}
调用处
while (GetMessage (&msg, NULL, 0, 0))
{
if(!PreTranslateMessage (&msg)) TranslateMessage (&msg) ;
DispatchMessage (&msg) ;
}
BOOL CDIDlg::PreTranslateMessage(MSG* pMsg)
{
static CPoint ptLast;
// TODO: Add your specialized code here and/or call the base class
if(pMsg->message==WM_MOUSEMOVE)
{
if(MK_LBUTTON==pMsg->wParam)
{
CRect rc;
GetWindowRect(&rc);// screen coord
MoveWindow(rc.left+(pMsg->pt.x-ptLast.x), rc.top+(pMsg->pt.y-ptLast.y), rc.Width(), rc.Height());
ptLast=pMsg->pt;// screen coord
}
else
{
ptLast=pMsg->pt;// screen coord
}
return TRUE;
}
return CDialog::PreTranslateMessage(pMsg);
}