A simple sliding control CSLIDetAb class

xiaoxiao2021-03-06  21

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 #include "./slidetab.h" #pragma comment (lib, "Winmm.LIB ") // CSlideTab IMPLEMENT_DYNAMIC (CSlideTab, CWnd) CSlideTab :: CSlideTab (): m_nTimerID (0), m_nHeight (100), m_nAction (SLIDE_TAB_STOP), m_fVert (FALSE) {} CSlideTab :: ~ CSlideTab () {} BEGIN_MESSAGE_MAP ( CSlideTab, CWnd) ON_WM_PAINT () ON_WM_MOUSEMOVE () ON_WM_ERASEBKGND () ON_WM_DESTROY () ON_WM_MOVE () END_MESSAGE_MAP () // CSlideTab message handler void CSlideTab :: CreateTab (CRect & rcTab, UINT nID, CWnd * pWndParent) {m_rcWnd.CopyRect (rcTab ); Create (AfxRegisterWndClass (CS_VREDRAW | CS_HREDRAW, NULL, NULL, NULL), NULL, WS_VISIBLE | WS_CHILD, rcTab, pWndParent, nID);} void CSlideTab :: OnPaint () {CPaintDC dc (this); // device context for painting // TODO: Add message handler code // herein does not call for the drawing CWnd :: OnPaint message () CRect ClientRect; GetClientRect (ClientRect); CBitmap MemBmp; MemBmp.CreateCompatibleBitmap (& dc, ClientRect.Width (), ClientRect .Height ()); CDC MEMDC; MEMDC.CREATECOMPATI bleDC (& dc); CBitmap * pBmpOld = MemDC.SelectObject (& MemBmp); DrawTab (& MemDC); dc.BitBlt (ClientRect.left, ClientRect.top, ClientRect.Width (), ClientRect.Height (), & MemDC, 0, 0 , SRCCOPY; MEMDC.SELECTOBJECT (PBMPOLD); MEMDC.DELETEDC (); MEMBMP.DELETEObject ();} void cslideTab :: OnMouseMove (uint nflags, cpoint point) {// Todo: Add message handler code and / or calling the default value CRect rcTab; GetWindowRect (rcTab); if (m_nAction == SLIDE_TAB_UP) {m_nAction = SLIDE_TAB_DOWN;} else if (m_nAction == SLIDE_TAB_DOWN) {TRACKMOUSEEVENT mEvent; mEvent.cbSize = sizeof (TRACKMOUSEEVENT); mEvent.hwndTrack = This-> getsafehwnd (); mevent.dwhovertime = Hover_Default; mevent.dwflags =

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 m_nHeight)) {PTAB-> getParent () -> screenToClient (rctab); * Pbottom = 5 * PTAB-> m_naction; PTAB ->

转载请注明原文地址:https://www.9cbs.com/read-39655.html

New Post(0)