仿QQ悬挂窗口的实现
2010-07-20 20:46:10 来源:WEB开发网鼠标消息一旦发到本窗口线程的消息队列后,本窗口过程在鼠标消息未被翻译之前从消息队列中取出消息,并进行处理。故得重载PreTranslateMessage这个虚函数。逻辑判断过程如下:
BOOL CHookTestDlg::PreTranslateMessage(MSG* pMsg)
{
// TODO: Add your specialized code here and/or call the base class
static int i=0;
int nSrcWidth = ::GetSystemMetrics(SM_CXSCREEN);
int nSrcHeight = ::GetSystemMetrics(SM_CYSCREEN);
switch(pMsg->message)
{
case WM_USER+1000:
{
POINT pt;
CRect rcWindow;
::GetCursorPos(&pt);
GetWindowRect(&rcWindow);
if(pt.x<1 && (pt.y>rcWindow.top && pt.y<rcWindow.bottom))
{
if(rcWindow.left<1 && rcWindow.Width()<1)
{
SliderWindow(LEFT, true);
}
else if(rcWindow.left<1 && rcWindow.Width()>99)
{
}
else if(rcWindow.left>1 && rcWindow.Width()>99)
{
}
else
{
}
}
else if(pt.y<rcWindow.top || pt.y>rcWindow.bottom)
{
if(rcWindow.left<1 && rcWindow.Width()<1)
{
}
else if(rcWindow.left<1 && rcWindow.Width()>99)
{
SliderWindow(LEFT, false);
}
else if(rcWindow.left>1 && rcWindow.Width()>99)
{
}
else
{
}
}
else if(pt.x>0 && pt.x<100)
{
if(rcWindow.left<1 && rcWindow.Width()<1 && (pt.y>rcWindow.top && pt.y<rcWindow.bottom))
{
}
else if(rcWindow.left<1 && rcWindow.Width()>99)
{
//SliderWindow(LEFT, true);
}
else if(rcWindow.left>1 && rcWindow.Width()>99)
{
}
else
{
}
}
else
{
if(rcWindow.left<1 && rcWindow.Width()<1)
{
}
else if(rcWindow.left<1 && rcWindow.Width()>99 && (pt.y>rcWindow.top && pt.y<rcWindow.bottom))
{
SliderWindow(LEFT, false);
}
else if(rcWindow.left>1 && rcWindow.Width()>99)
{
}
else
{
}
}
}
break;
default:
break;
}
return CDialog::PreTranslateMessage(pMsg);
}
void CHookTestDlg::SliderWindow(int nPos, bool bShow)
{
CRect rc;
GetWindowRect(rc);
int nSrcWidth = ::GetSystemMetrics(SM_CXSCREEN);
switch(nPos)
{
case LEFT:
if(bShow)
{
for(int i=0; i<=10; i++)
{
SetWindowPos(&CWnd::wndTopMost, 0, rc.top, i*10, rc.Height(), SWP_SHOWWINDOW);
Sleep(20);
}
}
else
{
for(int i=0; i<=10; i++)
{
SetWindowPos(&CWnd::wndTopMost, 0, rc.top, 100-10*i, rc.Height(), SWP_SHOWWINDOW);
Sleep(20);
}
}
break;
case RIGHT:
break;
case TOP:
break;
case BOTTOM:
break;
default:
break;
}
}
更多精彩
赞助商链接