m_isSizeChanged = FALSE;
m_isSetTimer = FALSE;m_hsFinished = TRUE;
m_hiding = FALSE;m_oldWndHeight = MINCY;
m_taskBarHeight =;
m_edgeHeight =;
m_edgeWidth=;
m_hideMode = HM_NONE;
完成了一些初始的工作
代碼一
int CQQHideWndDlg::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
if (CDialog::OnCreate(lpCreateStruct) ==)
return;
// TODO: Add your specialized creation code here//獲得任務欄高度
CWnd* p;
p = this>FindWindow( Shell_TrayWnd NULL);
if(p != NULL)
{
CRect tRect;
p>GetWindowRect(tRect);
m_taskBarHeight = tRectHeight();
}//修改風格使得他不在任務欄顯示
ModifyStyleEx(WS_EX_APPWINDOWWS_EX_TOOLWINDOW);
//去掉關閉按鍵(如果想畫個按鍵的話)
//ModifyStyle(WS_SYSMENUNULL); //獲得邊緣高度和寬度
m_edgeHeight = GetSystemMetrics(SM_CYEDGE);
m_edgeWidth = GetSystemMetrics(SM_CXFRAME);return
;
}
接著如何知道鼠標進入或移出窗口呢?在前面我已經證明了WM_MOUSEMOVE和WM_MOUSELEAVE不符合我們的要求
代碼二
UINT CQQHideWndDlg::OnNcHitTest(CPoint point)
{
// TODO: Add your message handler code here and/or call default
CString str;
strFormat( Mouse (%d %d) point x point y);
GetDlgItem(IDC_CURSOR)>SetWindowText(str);
if(m_hideMode != HM_NONE && !m_isSetTimer &&
//防止鼠標超出屏幕右邊時向右邊收縮造成閃爍
pointx < GetSystemMetrics(SM_CXSCREEN) + INFALTE)
{ //鼠標進入時如果是從收縮狀態到顯示狀態則開啟Timer
SetTimer(CM_ELAPSE NULL);
m_isSetTimer = TRUE;
m_hsFinished = FALSE;
m_hiding = FALSE;
SetTimer(HS_ELAPSE NULL); //開啟顯示過程
}
return CDialog::OnNcHitTest(point);
}
然後在OnTimer中
代碼三
void CQQHideWndDlg::OnTimer(UINT nIDEvent)
{
// TODO: Add your message handler code here and/or call default
if(nIDEvent ==)
{
POINT curPos;
GetCursorPos(&curPos);
CString str;
strFormat( Timer On(%d %d) curPos x curPos y);
GetDlgItem(IDC_TIMER)>SetWindowText(str); CRect tRect;
//獲取此時窗口大小
GetWindowRect(tRect);
//膨脹tRect以達到鼠標離開窗口邊沿一定距離才觸發事件
tRectInflateRect(INFALTE INFALTE); if(!tRect
PtInRect(curPos)) //如果鼠標離開了這個區域
{
KillTimer(); //關閉檢測鼠標Timer
m_isSetTimer = FALSE;
GetDlgItem(IDC_TIMER)>SetWindowText( Timer Off ); m_hsFinished = FALSE;
m_hiding = TRUE;
SetTimer(HS_ELAPSE NULL); //開啟收縮過程
}
}if(nIDEvent ==
)
{
if(m_hsFinished) //如果收縮或顯示過程完畢則關閉Timer
KillTimer();
else
m_hiding ? DoHide() : DoShow();
}
CDialog::OnTimer(nIDEvent);
}
暫時不管OnTimer中的DoHide(); DoShow();
先來看看核心的函數之一的 FixMoving
[
From:http://tw.wingwit.com/Article/program/net/201311/15311.html