#pragma once ///////////////////////////////////////////////////////////////// // // Header file : skinsb.h // // Descrption : Skin scrollbar library Version 1.0 // // Auhor : LiJun // // E-Mail : notoldtree@126.com // // History : // // 2008-12-24 // 问题描述:由于RichEdit控件在拖动滑块时滑块没有反应,原因是发送滚动消息给 // RichEdit控件并没有反应 // // 解决方案:在SkinSB_TrackThumb在函数中发送滚消息不要使用SB_THUMBTRACK标记,而 // 应该使用SB_THUMBPOSITION标记. ///////////////////////////////////////////////////////////////// #ifdef __cplusplus extern "C"{ #endif #include #include #include // Min thumb size #define SB_MINTHUMB_SIZE 10 // The scroll timer ID #define SB_TIMER_DELAY 65533 #define SB_TIMER_SCROLL 65534 // Startup scroll timer delay #define SB_SCROLL_DELAY 300 #define SB_SCROLL_INTERVAL 40 // Hittest code #define HTSCROLL_NONE 0x00000000L #define HTSCROLL_LINEUP 0x00000001L #define HTSCROLL_LINEDOWN 0x00000002L #define HTSCROLL_THUMB 0x00000003L #define HTSCROLL_PAGEUP 0x00000004L #define HTSCROLL_PAGEDOWN 0x00000005L #define HTSCROLL_SIZEBOX 0x00000006L // status... #define SB_STATE_DEFAULT 0x00000000L #define SB_STATE_NORMAL 0x00000001L #define SB_STATE_HOTTRACKED 0x00000002L #define SB_STATE_PRESSED 0x00000003L #define SB_STATE_DISABLED 0x00000004L // Send scroll message #define DoScrollMsg(hwnd, cmd, pos, fvert) \ SendMessage((hwnd), (fvert) ? WM_VSCROLL : WM_HSCROLL, MAKEWPARAM((cmd), (pos)), 0); // ScrollBar data sturcture typedef struct tagSB { HWND hwnd; // The window handle UINT flags; // Scrollbar disable flags DWORD style; // The window style SCROLLINFO Horz; // Horizontal scroll SCROLLINFO Vert; // Vertical scroll WNDPROC pfnOldProc; // The originally window procedure BOOL fLeftScrollBar; // Left scrollbar style BOOL fPreventStyleChange; // Prevent window style change BOOL fMouseTracking; BOOL fTracking; // Is tracking ? BOOL fTrackVert; // Tracking target whether vertical scrollbar BOOL fRichEdit; // Whether richedit control int nTrackCode; // Tracking hittest item code int nTrackPos; // Tracking thumb position int nOffsetPoint; // Tracking the thumb of mouse point offset UINT nScrollTimerMsg; // 32 bit value, low-word -> message, high-word -> scroll command UINT nLastCode; // Last HitTest code BOOL fLastVert; // Last HitTest is vertical scrollbar ? HBITMAP hBmp; } SB, *LPSB; // Scrollbar size calculate struct typedef struct tagSBCALC { int pxLeft; int pxTop; int pxRight; int pxBottom; union { int pxUpArrow; int pxLeftArrow; }; union { int pxDownArrow; int pxRightArrow; }; union { int pxThumbTop; int pxThumbLeft; }; union { int pxThumbBottom; int pxThumbRight; }; } SBCALC, *LPSBCALC; // Internal functions LPSB SkinSB_GetSB(HWND hwnd); BOOL SkinSB_SetSBParms(LPSCROLLINFO psi, SCROLLINFO si, BOOL* pfScroll, int* plres, BOOL bOldPos); BOOL SkinSB_IsScrollInfoActive(LPCSCROLLINFO lpsi); void SkinSB_SBCalc(LPSB psb, LPSBCALC lpcalc, BOOL fVert); BOOL SkinSB_GetSizeBoxRect(LPSB psb, LPRECT lprc); BOOL SkinSB_GetScrollBarRect(LPSB psb, BOOL fVert, LPRECT lprc); BOOL SkinSB_GetThumbRect(LPSB psb, LPRECT lprc, BOOL fVert); BOOL SkinSB_GetGrooveRect(LPSB psb, LPRECT lprc, BOOL fVert); //int SkinSB_GetPosFromPoint(POINT point, BOOL fVert); // Draw functions void SkinSB_DrawScrollBar(LPSB psb, HDC hDC, BOOL fVert); BOOL SkinSB_DrawGroove(LPSB psb, HDC hdc, LPRECT lprc, BOOL fVert); void SkinSB_DrawThumb(LPSB psb, HDC hdc, BOOL fVert); BOOL SkinSB_DrawArrow(LPSB psb, HDC hdc, BOOL fVert, int nArrow, UINT uState); BOOL SkinSB_DrawSizeBox(LPSB psb, HDC hDC); //BOOL SkinSB_DrawSkinBitmap(HDC hdc, LPRECT lprc, int xSrc, int ySrc, int nWidthSrc, int nHeightSrc, // BOOL bStretchAll, int leftMargin, int topMargin, int rightMargin, int bottomMargin, // BOOL bTrans, COLORREF clrTrans); //void SkinSB_TrackLoop(LPSB psb); void SkinSB_Track(LPSB psb, BOOL fVert, UINT nHit, POINT pt); BOOL SkinSB_TrackThumb(LPSB psb, BOOL fVert, POINT pt); BOOL SkinSB_HotTrack(LPSB psb, int nHitCode, BOOL fVert, BOOL fMouseDown); UINT SkinSB_HitTest(LPSB psb, BOOL fVert, POINT pt); BOOL SkinSB_EnableArrows(LPSB psb, int nBar, UINT wArrows); UINT SkinSB_GetDisableFlags(LPSB psb, BOOL fVert); UINT SkinSB_GetState(LPSB psb, BOOL fVert, UINT nHit); // Message functions LRESULT SkinSB_OnStyleChanged(LPSB psb, int nStyleType, LPSTYLESTRUCT lpStyleStruct); LRESULT SkinSB_OnNcHitTest(LPSB psb, WPARAM wParam, LPARAM lParam); LRESULT SkinSB_OnNcPaint(LPSB psb, HRGN hRgn); LRESULT SkinSB_OnNcCalcSize(LPSB psb, BOOL bCalcValidRects, NCCALCSIZE_PARAMS* lpncsp); LRESULT SkinSB_OnNcMouseMove(LPSB psb, WPARAM wParam, LPARAM lParam); LRESULT SkinSB_OnNcLButtonDown(LPSB psb, WPARAM wParam, LPARAM lParam); LRESULT SkinSB_OnNcMouseLeave(LPSB psb, WPARAM wParam, LPARAM lParam); LRESULT SkinSB_OnMouseMove(LPSB psb, WPARAM wParam, LPARAM lParam); LRESULT SkinSB_OnLButtonUp(LPSB psb, WPARAM wParam, LPARAM lParam); LRESULT SkinSB_OnTimer(LPSB psb, WPARAM wParam, LPARAM lParam); // scroll window procedure LRESULT CALLBACK SkinSB_Proc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam); #ifdef __cplusplus } #endif /*==========================================================================*\ ===滚动条模型描述=== +-------------------------------+---+ <-------+ | | A | (1) | +---+ <-------+----------+ | | | | | | | | | |---| <-------+ | | | | | | | (10) | - | (2) | | | - | | | | | | | (3) | |---| <-------+ | | | | | | | | | | +---+ <-------+ | | | V | (4) | +---+-----------------------+---+---+ <-------+----------+ | < | [ || ] | > |///| (5) +---+-----------------------+---+---+ <-------+ ^ ^ ^ ^ ^ ^ | | | | | | | | | | | | (8) (7) (6) 描述: (1) (2) (3) (4) \*=========================================================================*/