Seeing some people in the forum need a universal sliding control, considering it, inheriting a CSLIDetAb class from CWND, implementing some demo functions.
Instructions:
1. #include "slideTab.h" // In the header file of the window class you need to use, the 2. cslideTab m_slideTab; // Declare a CSLIDetab member variable 3. m_slideTab.createTab (CRECT (-1, -1, 50 , 50), ID_slideTab, this); // Call CSLideTab :: CreateTab (CRECT & RCTAB, UINT NID, CWND * PWNDParent) method during window initialization, where id_slideTab is the control ID and needs to be defined in the resource file. 4. m_slideTab.SetHeight (400); // Set to expand down, expand the height of 400 or m_slideTab.SetWidth (400); // set to the right to unfold, the unfolded width is more than 400 or more only the last call is valid. 5. You can overload this type of DrawTab (CDC * PDC) virtual member function to achieve the required interface effect. Double buffers have been implemented inside, directly drawn on the PDC. SlideTab.h
SlideTab.h
#pragma once #include "atltypes.h" // CSlideTab typedef enum _SLIDE_TAB_ACTION {SLIDE_TAB_UP = -1, SLIDE_TAB_STOP, SLIDE_TAB_DOWN} SLIDE_TAB_ACTION; class CSlideTab: public CWnd {DECLARE_DYNAMIC (CSlideTab) public: CSlideTab (); virtual ~ CSlideTab (); protected: DECLARE_MESSAGE_MAP () public: void CreateTab (CRect & rcTab, UINT nID, CWnd * pWndParent); afx_msg void OnPaint (); afx_msg void OnMouseMove (UINT nFlags, CPoint point); virtual BOOL PreTranslateMessage (MSG * pMsg); public: static void CALLBACK OpenTab (UINT uID, UINT uMsg, DWORD dwUser, DWORD dw1, DWORD dw2); int SetHeight (int nHeight); int SetWidth (int nWidth); afx_msg BOOL OnEraseBkgnd (CDC * pDC); virtual void DrawTab (CDC * pDC ); AFX_MSG Void OnDestroy (); AFX_MSG Void Onmove (int X, int y); private: uint m_ntimerid; int m_nhem; slide_tab_action m_naction; crect m_rcwnd; BOOL M_FVERT;};
SlideTab.cpp
// SlideTab.cpp: Implement file // #include "stdafx.h" #include "slideTab.h" #include
TME_LEAVE; _TrackMouseEvent (& mEvent);} else if (! (M_fVert && rcTab.Height () <= m_rcWnd.Height ()) || (m_fVert && rcTab.Width () <= m_rcWnd.Width ())) {TRACKMOUSEEVENT mEvent ; mEvent.cbSize = sizeof (TRACKMOUSEEVENT); mEvent.hwndTrack = this-> GetSafeHwnd (); mEvent.dwHoverTime = HOVER_DEFAULT; mEvent.dwFlags = TME_HOVER; _TrackMouseEvent (& mEvent);} CWnd :: OnMouseMove (nFlags, point);} BOOL CSlideTab :: PreTranslateMessage (MSG * pMsg) {// TODO: add this special code and / or calls the base class if (pMsg-> message == WM_MOUSEHOVER) {m_nAction = SLIDE_TAB_DOWN; if (m_nTimerID!) {m_nTimerID = timeSetEvent (5, 1, OpenTab, (DWORD_PTR) THIS, TIME_PERIODIC);}} Else IF (PMSG-> Message == WM_MouseLeave) {m_nAction = slide_tab_up; if (! M_ntimerid) {m_ntimerid = TimeStevent (5, 1, OpenTab, DWORD_PTR) this, TIME_PERIODIC);}} return CWnd :: PreTranslateMessage (pMsg);} void CALLBACK CSlideTab :: OpenTab (UINT uID, UINT uMsg, DWORD dwUser, DWORD dw1, DWORD dw2) {CSlideTab * pTab = (CSlideTab *) Dwuser; CRECT RCTAB; PTAB-> getWindowRect (RCTAB); int nTabHeight, nWndHeight; LONG * pBottom, * pTop; if (pTab-> m_fVert) {nTabHeight = rcTab.Height (); nWndHeight = pTab-> m_rcWnd.Height (); pTop = & rcTab.top; pBottom = & rcTab.bottom ;} else {nTabHeight = rcTab.Width (); nWndHeight = pTab-> m_rcWnd.Width (); pTop = & rcTab.left; pBottom = & rcTab.right;} if (((nTabHeight> nWndHeight) && pTab-> m_nAction = = SLIDE_TAB_UP) || (PTAB-> m_nAction == slide_tab_down) && (NtabHeight