製做像QQ那種自動停靠.自動收縮的窗口,好東西呀,收藏起來,方便以後使用。謝謝了。

(轉自:
http://blog.csdn.net/hxblvc/archive/2004/09/30/122057.aspx

我想使用TrackBacks試試)

1.首先處理自動停靠.
    1).建立一個對話框類CDlg.
    2).
        ///dlg.h
          class CDlg
        {
            private:
                   bool m_isAutoHide; //窗口是否可以自動隱藏
                   bool m_isWinHide; // 窗口是否隱藏
               ...........
        }

      ///dlg.cpp
         .....
    void CDlg::OnMove(int x, int y)
    {
         CDialog::OnMove(x, y);
         
         ///窗口從顯示到隱藏時,不做其它操作
        if(m_isWinHide)
         {
              return;
         }
         
         CRect tRect;
         GetWindowRect(tRect);
         if(tRect.top<10)
         {///如果窗口移動後的位置和到屏幕上方的距離小於10
           ///就使窗口停靠到屏幕上方.

              tRect.bottom-= tRect.top;
              tRect.top= 0;
              MoveWindow(tRect);
               ///窗口停靠後就可以自動隱藏
              m_isAutoHide= true;
          }
         else
         {
               ///如窗口沒有停靠就不可以自動隱藏
              m_isAutoHide= false;
         }
 
       }

    void CDlg::OnMoving(UINT fwSide, LPRECT pRect)
    {
        if((pRect->top < 10)
          && (!m_isAutoHide) )
        {///如果窗口移動到的位置和到屏幕上方的距離小於10
           ///就使窗口停靠到屏幕上方.

                pRect->bottom-= pRect->top;
                pRect->top= 0;
                m_isAutoHide= true;
        }

        CDialog::OnMoving(fwSide, pRect);
    }
2.處理自動收縮
      //dlg.h
        class CDlg
         {
                .....
                LRESULT  OnMouseLeave( HWND hwnd, UINT msg,
                                              WPARAM  wParam,LPARAM lParam  );
         }

     //dlg.cpp
            BEGIN_MESSAGE_MAP(CDlg, CDialog)
                  ON_MESSAGE(WM_MOUSELEAVE,OnMouseLeave)
            END_MESSAGE_MAP()
      .......

     LRESULT CDlg::OnMouseLeave(HWND hwnd, UINT msg, WPARAM wParam,                                                                   LPARAM lParam  )
        {
             if(m_isAutoHide)
             {
                  CPoint tPoint;
                  GetCursorPos(&tPoint);
                  CRect tRect;
                  GetWindowRect(&tRect);
                  if(!(tRect.PtInRect(tPoint)))
                  {
                      m_isWinHide=true;
                   tRect.top= tRect.top - tRect.bottom +5;
                   tRect.bottom= 5;
                   MoveWindow(tRect);

                   ::SetWindowPos(
                            ::GetDesktopWindow()
                            ,HWND_TOPMOST,tRect.left,tRect.top
                            ,tRect.Width(),tRect.Height    ()
                            ,SWP_SHOWWINDOW);
                 }
            }
      return TRUE;
    }


    void CDlg::OnMouseMove(UINT nFlags, CPoint point)
        {
                 if(m_isWinHide)
                 {
                      CRect tRect;
                      GetWindowRect(&tRect);
                     tRect.bottom+= (tRect.bottom-tRect.top-5);
                     tRect.top=0;
                     MoveWindow(tRect);
                     m_isWinHide= false;
                  }

                    TRACKMOUSEEVENT EventTrack;
                      EventTrack.cbSize= sizeof(TRACKMOUSEEVENT);
                      EventTrack.dwFlags= TME_LEAVE;
                      EventTrack.hwndTrack= this->m_hWnd;
                      _TrackMouseEvent(&EventTrack);

            CDialog::OnMouseMove(nFlags, point);

        }

<完成>

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章