123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227 |
- // ListXP.cpp: implementation of the CListXP class.
- //
- //////////////////////////////////////////////////////////////////////
- /**************以下设置必需包含在每个子类中**********************/
- //头部
- ////////////////////////////////////////////////////////////////////////////////////////////////////
- // 编译预处理
- #if _WIN32_WINNT < 0x0400
- #define _WIN32_WINNT 0x0400
- #endif
- // 强制使用 C 语言方式编译
- #ifdef __cplusplus
- extern "C"
- {
- #endif // __cplusplus
- #include "ScrollXP.h"
- //////////////////////////////////////////////////////////////////////////////////////////////////
- // 全局变量
- extern HHOOK g_hPrevHookXP ; // 窗口消息 HOOK 句柄
- extern PCLASSXP g_pClassXP ; // 窗口的 CLASSXP 结构指针
- extern COLORREF g_crDialogbkColor; // 窗口背景颜色
- //#define AREATOP 1
- //#define AREABOTTOM 2
- //#define AREALEFT 1
- //#define AREARIGHT 2
- //#define AREANONE 0
- #define SCROLLAREA 0 //滚动条区域
- #define SCROLLTOPARROW 1 //上箭头
- #define SCROLLBOTTOMARROW 2 //下箭头
- #define SCROLLLEFTARROW 3 //左箭头
- #define SCROLLRIGHTARROW 4 //右箭头
- #define SCROLLTHUMB 5 //移动块
- #define SCROLLAREANULL 6 //滚动条空区域
- #define SCROLLALL 7 //所有区域
- /*static COLORREF gScrolls_crGradientXP[][4] =
- {
- {0x00FFE7CE, 0x00FFE7CE, 0x00EE8269, 0xFFEE8269},
- {0x00C1CCD1, 0x00C1CCD1, 0x00EEF1F2, 0xFFEEF1F2},
- {0x00FFE7CE, 0x00EE8269, 0x00FFE7CE, 0xFFEE8269},
- {0x00C1CCD1, 0x00EEF1F2, 0x00C1CCD1, 0xFFEEF1F2},
- {0x00FFFFFF, 0x00FFFFFF, 0x00D6DFE2, 0xFFD6DFE2},
- };
- */
- /**************以下设置必需包含在每个子类中**********************/
- //////////////////////////////////////////////////////////////
- ////////////////////////////////////////////////////////////////////////////////////////////////////
- // 绘制 Thumb 块
- VOID WINAPI ScrollDrowThumbXP(HDC hDC, RECT Rect, LONG lState)
- {
- int i;
- // RECT Rect;
- HANDLE hHandle;
- static COLORREF s_crGradientXP[][4] =
- {
- {0x00EFF3F7, 0x00DEE7E7, 0x00DEE3E7, 0x00DEE3E7},
- {0x00DEAEA5, 0x00F7CBBD, 0x00DE8273, 0x00F7C7B5},
- {0x00EFC7B5, 0x00E7AE94, 0x00DEA284, 0x00DEA68C},
- {0x00FFE3D6, 0x00F7CBBD, 0x00F7C3AD, 0x00F7C7B5},
- {0x00F7F7F7, 0x00EFF3F7, 0x00EFF3F7, 0x00EFF3F7},
- {0x00DEC3BD, 0x00DEB6AD, 0x00FFE3DE, 0x00F7E3DE},
- {0x00EFDBCE, 0x00EFCFC6, 0x00E7CFC6, 0x00E7CBBD},
- {0x00FFEFE7, 0x00FFE7DE, 0x00FFE3DE, 0x00F7E3DE},
- {0x00F7F7F7, 0x00E7EFEF, 0x00E7EBEF, 0x00DEE7E7},
- {0x00F78E6B, 0x00F79684, 0x00EF9E8C, 0x00EFDFD6},
- {0x00FFFFFF, 0x00FFE3CE, 0x00FFDFC6, 0x00FFDBBD},
- {0x00FFEBE7, 0x00FFCFBD, 0x00FFCBB5, 0x00F7CBAD},
- {0x00EFF3F7, 0x00DEE7E7, 0x00EFF3F7, 0x00DEE3E7},//水平滚条
- {0x00DEAEA5, 0x00F7CBBD, 0x00DEAEA5, 0x00F7C7B5},
- {0x00EFC7B5, 0x00E7AE94, 0x00EFC7B5, 0x00DEA68C},
- {0x00FFE3D6, 0x00F7CBBD, 0x00FFE3D6, 0x00F7C7B5},
- {0x00DEE7E7, 0x00DEE7E7, 0x00DEE3E7, 0x00DEE3E7},//垂直滚条
- {0x00F7CBBD, 0x00F7CBBD, 0x00DE8273, 0x00F7C7B5},
- {0x00EFC7B5, 0x00EFC7B5, 0x00E7AE94, 0x00DEA68C},
- {0x00F7CBBD, 0x00F7CBBD, 0x00F7C3AD, 0x00F7C7B5},
- };
- // CopyRect(&Rect, pRect);
- if (lState & CXPH_HASFRAME) //画外框阴影
- {
- //InflateRect(&Rect, -1, -1);
- //Rect.top--;
- Rect.right--;Rect.bottom--;
- FrameRect(hDC, &Rect, (HBRUSH )GetStockObject(WHITE_BRUSH));
- hHandle = (HANDLE) SelectObject(hDC,
- CreatePen(PS_SOLID, 1, (lState & CXPS_DISABLED) ? 0x00BDCFCE : 0x00D6B69C));
- MoveToEx(hDC, Rect.right, Rect.top + 2, NULL);
- LineTo(hDC, Rect.right, Rect.bottom - 2);
- LineTo(hDC, Rect.right - 2, Rect.bottom);
- LineTo(hDC, Rect.left + 1, Rect.bottom);
- LineTo(hDC, Rect.left - 1, Rect.bottom - 2);
- DeleteObject(SelectObject(hDC, (HGDIOBJ) hHandle));
- InflateRect(&Rect, -1, -1);
- }
- // 绘制 Thumb 外框
- if (lState & CXPS_DISABLED)
- i = 0;
- else if (lState & CXPS_PRESSED)
- i = 1;
- else if (lState & CXPS_HOTLIGHT)
- i = 2;
- else
- i = 3;
- if(lState & CXPH_AREA) //只绘滚条内区
- {
- i += 12;
- if(lState & CXPS_HORIZON)
- {i += 4;
- GradientRectXP(hDC, &Rect, s_crGradientXP[i]);
- //InflateRect(&Rect, -1, -1);
- //GradientRectXP(hDC, &Rect, s_crGradientXP[i + 8]);
- }
- else
- {
- GradientRectXP(hDC, &Rect, s_crGradientXP[i]);
- }
- return;
- }
- else //画按钮
- {
- GradientRectXP(hDC, &Rect, s_crGradientXP[i]);
- // 绘制下拉外框拐角像素
- SetPixel(hDC, Rect.left, Rect.top, s_crGradientXP[i + 4][0]);
- SetPixel(hDC, Rect.right - 1, Rect.top, s_crGradientXP[i + 4][1]);
- SetPixel(hDC, Rect.left, Rect.bottom - 1, s_crGradientXP[i + 4][2]);
- SetPixel(hDC, Rect.right - 1, Rect.bottom - 1, s_crGradientXP[i + 4][3]);
- // 绘制 Thumb 内框
- InflateRect(&Rect, -1, -1);
- GradientRectXP(hDC, &Rect, s_crGradientXP[i + 8]);
- }
- // 绘制 Thumb 标志
- Rect.left += (Rect.right - Rect.left) / 2;
- Rect.top += (Rect.bottom - Rect.top) / 2;
-
- if (lState & CXPH_DROPHANDLE)
- {
- hHandle = (HANDLE) SelectObject(hDC, CreatePen(PS_SOLID, 1, 0x00FFF7EF));
- for (i = -4; i <= 2; i += 2)
- {
- if (lState & CXPS_HORIZON)
- {
- MoveToEx(hDC, Rect.left + i, Rect.top - 3, NULL);
- LineTo(hDC, Rect.left + i, Rect.top + 3);
- }
- else
- {
- MoveToEx(hDC, Rect.left - 3, Rect.top + i, NULL);
- LineTo(hDC, Rect.left + 3, Rect.top + i);
- }
- }
- DeleteObject(SelectObject(hDC, (HGDIOBJ) hHandle));
- hHandle = (HANDLE) SelectObject(hDC, CreatePen(PS_SOLID, 1, 0x00FFB28C));
- for (i = -3; i <= 3; i += 2)
- {
- if (lState & CXPS_HORIZON)
- {
- MoveToEx(hDC, Rect.left + i, Rect.top - 2, NULL);
- LineTo(hDC, Rect.left + i, Rect.top + 4);
- }
- else
- {
- MoveToEx(hDC, Rect.left - 2, Rect.top + i, NULL);
- LineTo(hDC, Rect.left + 4, Rect.top + i);
- }
- }
- DeleteObject(SelectObject(hDC, (HGDIOBJ) hHandle));
- }
- else
- {
- hHandle = (HANDLE) SelectObject(hDC,
- CreatePen(PS_SOLID, 1, (lState & CXPS_DISABLED) ? 0x00C6CBCE : 0x0084614A));
- if (lState & CXPH_SMALLARROW)
- {
- if (lState & CXPH_LEFTWARDS)
- {
- MoveToEx(hDC, Rect.left - 2, Rect.top, NULL);
- LineTo(hDC, Rect.left - 2, Rect.top + 1);
- MoveToEx(hDC, Rect.left - 1, Rect.top - 1, NULL);
- LineTo(hDC, Rect.left - 1, Rect.top + 2);
- MoveToEx(hDC, Rect.left, Rect.top - 2, NULL);
- LineTo(hDC, Rect.left, Rect.top + 3);
- MoveToEx(hDC, Rect.left + 1, Rect.top - 3, NULL);
- LineTo(hDC, Rect.left + 1, Rect.top);
- MoveToEx(hDC, Rect.left + 1, Rect.top + 1, NULL);
- LineTo(hDC, Rect.left + 1, Rect.top + 4);
- }
- else if (lState & CXPH_UPWARDS)
- {
- MoveToEx(hDC, Rect.left - 3, Rect.top + 1, NULL);
- LineTo(hDC, Rect.left, Rect.top + 1);
- MoveToEx(hDC, Rect.left + 1, Rect.top + 1, NULL);
- LineTo(hDC, Rect.left + 4, Rect.top + 1);
- MoveToEx(hDC, Rect.left - 2, Rect.top, NULL);
- LineTo(hDC, Rect.left + 3, Rect.top);
- MoveToEx(hDC, Rect.left - 1, Rect.top - 1, NULL);
- LineTo(hDC, Rect.left + 2, Rect.top - 1);
- MoveToEx(hDC, Rect.left, Rect.top - 2, NULL);
- LineTo(hDC, Rect.left + 1, Rect.top - 2);
- }
- else if (lState & CXPH_RIGHTWARDS)
- {
- MoveToEx(hDC, Rect.left + 2, Rect.top, NULL);
- LineTo(hDC, Rect.left + 2, Rect.top + 1);
- MoveToEx(hDC, Rect.left + 1, Rect.top - 1, NULL);
- LineTo(hDC, Rect.left + 1, Rect.top + 2);
- MoveToEx(hDC, Rect.left, Rect.top - 2, NULL);
- LineTo(hDC, Rect.left, Rect.top + 3);
- MoveToEx(hDC, Rect.left - 1, Rect.top - 3, NULL);
- LineTo(hDC, Rect.left - 1, Rect.top);
- MoveToEx(hDC, Rect.left - 1, Rect.top + 1, NULL);
- LineTo(hDC, Rect.left - 1, Rect.top + 4);
- }
- else if (lState & CXPH_DOWNWARDS)
- {
- MoveToEx(hDC, Rect.left - 3, Rect.top - 1, NULL);
- LineTo(hDC, Rect.left, Rect.top - 1);
- MoveToEx(hDC, Rect.left + 1, Rect.top - 1, NULL);
- LineTo(hDC, Rect.left + 4, Rect.top - 1);
- MoveToEx(hDC, Rect.left - 2, Rect.top, NULL);
- LineTo(hDC, Rect.left + 3, Rect.top);
- MoveToEx(hDC, Rect.left - 1, Rect.top + 1, NULL);
- LineTo(hDC, Rect.left + 2, Rect.top + 1);
- MoveToEx(hDC, Rect.left, Rect.top + 2, NULL);
- LineTo(hDC, Rect.left + 1, Rect.top + 2);
- }
- }
- else if (lState & CXPH_LARGEARROW)
- {
- if (lState & CXPH_LEFTWARDS)
- {
- MoveToEx(hDC, Rect.left + 1, Rect.top - 4, NULL);
- LineTo(hDC, Rect.left - 3, Rect.top);
- LineTo(hDC, Rect.left + 2, Rect.top + 5);
- MoveToEx(hDC, Rect.left + 1, Rect.top - 3, NULL);
- LineTo(hDC, Rect.left - 2, Rect.top);
- LineTo(hDC, Rect.left + 2, Rect.top + 4);
- MoveToEx(hDC, Rect.left + 2, Rect.top - 3, NULL);
- LineTo(hDC, Rect.left - 1, Rect.top);
- LineTo(hDC, Rect.left + 3, Rect.top + 4);
- }
- else if (lState & CXPH_UPWARDS)
- {
- MoveToEx(hDC, Rect.left - 4, Rect.top + 1, NULL);
- LineTo(hDC, Rect.left, Rect.top - 3);
- LineTo(hDC, Rect.left + 5, Rect.top + 2);
- MoveToEx(hDC, Rect.left - 3, Rect.top + 1, NULL);
- LineTo(hDC, Rect.left, Rect.top - 2);
- LineTo(hDC, Rect.left + 4, Rect.top + 2);
- MoveToEx(hDC, Rect.left - 3, Rect.top + 2, NULL);
- LineTo(hDC, Rect.left, Rect.top - 1);
- LineTo(hDC, Rect.left + 4, Rect.top + 3);
- }
- else if (lState & CXPH_RIGHTWARDS)
- {
- MoveToEx(hDC, Rect.left - 1, Rect.top - 4, NULL);
- LineTo(hDC, Rect.left + 3, Rect.top);
- LineTo(hDC, Rect.left - 2, Rect.top + 5);
- MoveToEx(hDC, Rect.left - 1, Rect.top - 3, NULL);
- LineTo(hDC, Rect.left + 2, Rect.top);
- LineTo(hDC, Rect.left - 2, Rect.top + 4);
- MoveToEx(hDC, Rect.left - 2, Rect.top - 3, NULL);
- LineTo(hDC, Rect.left + 1, Rect.top);
- LineTo(hDC, Rect.left - 3, Rect.top + 4);
- }
- else if (lState & CXPH_DOWNWARDS)
- {
- MoveToEx(hDC, Rect.left - 4, Rect.top - 2, NULL);
- LineTo(hDC, Rect.left, Rect.top + 2);
- LineTo(hDC, Rect.left + 5, Rect.top - 3);
- MoveToEx(hDC, Rect.left - 3, Rect.top - 2, NULL);
- LineTo(hDC, Rect.left, Rect.top + 1);
- LineTo(hDC, Rect.left + 4, Rect.top - 3);
- MoveToEx(hDC, Rect.left - 3, Rect.top - 3, NULL);
- LineTo(hDC, Rect.left, Rect.top);
- LineTo(hDC, Rect.left + 4, Rect.top - 4);
- }
- }
- DeleteObject(SelectObject(hDC, (HGDIOBJ) hHandle));
- }
- }
- //画按钮
- void ScrollDrawButton(PCLASSXP pCxp, HDC hDC, RECT Rect,
- DWORD dwStyle, int nType)
- {
- /*
- FrameRect FrameRect 画一个矩形框
- Lineto Lineto 画线到
- Moveto Moveto 移 到
- Pie Pie 画扇形
- Polygon Polygon 画多边形
- PolyLine PolyLine 画多根相连的线
- Rectangle Rectangle 画一个实心矩形
- RoundRect RoundRect 画一个圆角的矩形
- {0x00CEF3FF, 0x0063CBFF, 0x0063CBFF, 0x0031B2FF},
- */
- PSCROLLXP pXP;
- pXP = (PSCROLLXP)pCxp->pData;
- // HANDLE hPen, hBrush;
- // RECT rt;
- // POINT szPoint[3];
- // COLORREF crColor ;
- /* if(dwStyle == SBS_HORZ && pXP->m_bMouseDown)
- GradientRectXP(hDC, &Rect, gScrolls_crGradientXP[0]);
- else if(dwStyle == SBS_HORZ && !pXP->m_bMouseDown)
- GradientRectXP(hDC, &Rect, gScrolls_crGradientXP[1]);
- else if(dwStyle == SBS_VERT && pXP->m_bMouseDown)
- GradientRectXP(hDC, &Rect, gScrolls_crGradientXP[2]);
- else
- GradientRectXP(hDC, &Rect, gScrolls_crGradientXP[3]);
- */
- /* if(dwStyle == SBS_HORZ)
- GradientRectXP(hDC, &Rect, gScrolls_crGradientXP[1]);
- else
- GradientRectXP(hDC, &Rect, gScrolls_crGradientXP[3]);
- if(nType != SCROLLAREANULL)//无边框
- {
- hBrush = SelectObject(hDC, GetStockObject(NULL_BRUSH));
- RoundRect(hDC, Rect.left, Rect.top,
- Rect.right , Rect.bottom , 4,4);
- SelectObject(hDC, hBrush);
- }
- int nWidth = (Rect.right - Rect.left)/2;
- int nHeight = (Rect.bottom - Rect.top)/2;
- if(pXP->m_bMouseDownArrowForwad ||
- pXP->m_bMouseDownArrowForback)
- crColor = RGB(123,12,123);
- else
- crColor = RGB(0,0,0);
- switch (nType)
- {
- case SCROLLLEFTARROW: //左箭头
- hBrush = SelectObject(hDC, CreateSolidBrush(crColor));
- hPen = SelectObject(hDC, CreatePen(1,1,crColor));
- szPoint[0].x = Rect.left + 6; szPoint[0].y = Rect.top + nHeight;
- szPoint[1].x = szPoint[0].x + 3; szPoint[1].y = szPoint[0].y - 3;
- szPoint[2].x = szPoint[0].x + 3; szPoint[2].y = szPoint[0].y + 3;
- Polygon(hDC, szPoint, 3);
- DeleteObject(SelectObject(hDC, hBrush));
- DeleteObject(SelectObject(hDC, hPen));
- break;
- case SCROLLRIGHTARROW://右箭头
- hBrush = SelectObject(hDC, CreateSolidBrush(crColor));
- hPen = SelectObject(hDC, CreatePen(1,1,crColor));
- szPoint[0].x = Rect.right - 6; szPoint[0].y = Rect.top + nHeight;
- szPoint[1].x = szPoint[0].x - 3; szPoint[1].y = szPoint[0].y - 3;
- szPoint[2].x = szPoint[0].x - 3; szPoint[2].y = szPoint[0].y + 3;
- Polygon(hDC, szPoint, 3);
- DeleteObject(SelectObject(hDC, hBrush));
- DeleteObject(SelectObject(hDC, hPen));
- break;
- case SCROLLTOPARROW://上箭头
- hBrush = SelectObject(hDC, CreateSolidBrush(crColor));
- hPen = SelectObject(hDC, CreatePen(1,1,crColor));
- szPoint[0].x = Rect.left + nWidth; szPoint[0].y = Rect.top + 5;
- szPoint[1].x = szPoint[0].x - 3; szPoint[1].y = szPoint[0].y + 3;
- szPoint[2].x = szPoint[0].x + 3; szPoint[2].y = szPoint[0].y + 3;
- Polygon(hDC, szPoint, 3);
- DeleteObject(SelectObject(hDC, hBrush));
- DeleteObject(SelectObject(hDC, hPen));
- break;
- case SCROLLBOTTOMARROW://下箭头
- hBrush = SelectObject(hDC, CreateSolidBrush(crColor));
- hPen = SelectObject(hDC, CreatePen(1,1,crColor));
- szPoint[0].x = Rect.left + nWidth; szPoint[0].y = Rect.bottom - 7;
- szPoint[1].x = szPoint[0].x - 3; szPoint[1].y = szPoint[0].y - 3;
- szPoint[2].x = szPoint[0].x + 3; szPoint[2].y = szPoint[0].y - 3;
- Polygon(hDC, szPoint, 3);
- DeleteObject(SelectObject(hDC, hBrush));
- DeleteObject(SelectObject(hDC, hPen));
- break;
- case SCROLLAREA://活动区域
- break;
- case SCROLLTHUMB://移动块
- if (pXP->m_bDragging)
- hBrush = CreateSolidBrush(0x00CEF3FF);
- else
- hBrush = CreateSolidBrush(RGB(0,155,0));
- rt = Rect;
- if (dwStyle & SBS_VERT) //垂直
- { //上下两个边
- //hBrush = CreateSolidBrush(RGB(213,155,36));
- rt.left = Rect.left + 1; rt.top = Rect.top + 1;
- rt.right = Rect.right - 1; rt.bottom = Rect.top + nHeight/2;
- FillRect(hDC, &rt, (HBRUSH)hBrush);
- rt.left = Rect.left + 1; rt.top = Rect.bottom - nHeight/2;
- rt.right = Rect.right - 1; rt.bottom = Rect.bottom - 1;
- FillRect(hDC, &rt, (HBRUSH)hBrush);
- DeleteObject(hBrush);
- }
- else
- {//左右两个边
- //hBrush = CreateSolidBrush(RGB(213,155,36));
- rt.left = Rect.left + 1; rt.top = Rect.top + 1;
- rt.right = Rect.left + nWidth/2; rt.bottom = Rect.bottom - 1;
- FillRect(hDC, &rt, (HBRUSH)hBrush);
- rt.left = Rect.right - nWidth/2; rt.top = Rect.top + 1;
- rt.right = Rect.right - 1; rt.bottom = Rect.bottom - 1;
- FillRect(hDC, &rt, (HBRUSH)hBrush);
- DeleteObject(hBrush);
- }
- pXP->m_ThumbRectOld = pXP->m_ThumbRect;
- break;
- }
- // FillRect(hDC,&Rect,(HBRUSH)hHandle);
- */
- }
- //计算移动块大小
- void ScrollCalVertical(PCLASSXP pCxp, SCROLLINFO sif, RECT Rect)
- {
- PSCROLLXP pXP;
- pXP = (PSCROLLXP)pCxp->pData;
- if(pXP->m_bDragging)sif.nPos = pXP->m_nThumbTrackPos;
- int ThumbWidth = 30;
- if(ThumbWidth > pXP->m_AreaRect.bottom - pXP->m_AreaRect.top)
- ThumbWidth = (pXP->m_AreaRect.bottom - pXP->m_AreaRect.top)/2;
- double height = pXP->m_AreaRect.bottom - pXP->m_AreaRect.top - ThumbWidth;
- double range = sif.nMax - sif.nMin;
- double per = height / range;
- int pos = (int)(per * (sif.nPos - sif.nMin));
-
- if( range <= 0)
- return;
- pXP->m_ThumbRect.left = Rect.left;
- pXP->m_ThumbRect.top = pXP->m_AreaRect.top + pos;
- pXP->m_ThumbRect.right = Rect.right;
- pXP->m_ThumbRect.bottom = pXP->m_ThumbRect.top + ThumbWidth;
- InflateRect(&pXP->m_ThumbRect, -2, -1);
- }
- //画垂直动条
- void ScrollDrawVertical(PCLASSXP pCxp, long nType)
- {
- BOOL IsWindowEnable;
- RECT Rect;//, NewRect;
- HWND hWnd;
- PSCROLLXP pXP;
- HDC hDC;
- long lState;
- pXP = (PSCROLLXP)pCxp->pData;
- hWnd = pCxp->hWnd;
- GetWindowRect(hWnd, &Rect);
- Rect.right -= Rect.left;
- Rect.bottom -= Rect.top;
- Rect.left = Rect.top = 0;
- long lSmall = 0;
- IsWindowEnable = IsWindowEnabled(hWnd);
- //有效判断
- SCROLLINFO sif;
- ZeroMemory(&sif, sizeof(SCROLLINFO));
- sif.cbSize = sizeof(SCROLLINFO);
- sif.fMask = SIF_ALL;
- if(!GetScrollInfo(hWnd, SB_CTL, &sif))
- return;
- if(sif.nMin == sif.nMax)
- return;
- MEMDCXP Mdcxp;
- Mdcxp.hWnd = hWnd;
- Mdcxp.bTransfer = FALSE;
- Mdcxp.hBitmap = NULL;
- GetMemDCXP(&Mdcxp);
- hDC = Mdcxp.hDC;
- //小箭头
- if (Rect.bottom-Rect.left < 2*(Rect.right-Rect.left))
- lSmall = CXPH_SMALLARROW;
- //上箭头
- pXP->m_TopArrowRect = Rect;
- pXP->m_TopArrowRect.bottom = Rect.top+Rect.right-Rect.left;
- if (nType == SCROLLTOPARROW || nType == SCROLLALL)
- { if(pXP->m_bMouseDownArrowForback)
- ScrollDrowThumbXP(hDC, pXP->m_TopArrowRect, CXPH_LARGEARROW|CXPH_UPWARDS|CXPS_PRESSED|lSmall);
- else
- ScrollDrowThumbXP(hDC, pXP->m_TopArrowRect, CXPH_LARGEARROW|CXPH_UPWARDS|lSmall);
- }
- //下箭头
- pXP->m_BottomArrowRect = Rect;
- pXP->m_BottomArrowRect.top = Rect.bottom-(Rect.right-Rect.left);
- if (nType == SCROLLBOTTOMARROW || nType == SCROLLALL)
- { if(pXP->m_bMouseDownArrowForwad)
- ScrollDrowThumbXP(hDC, pXP->m_BottomArrowRect, CXPH_LARGEARROW|CXPH_DOWNWARDS|CXPS_PRESSED|lSmall);
- else
- ScrollDrowThumbXP(hDC, pXP->m_BottomArrowRect, CXPH_LARGEARROW|CXPH_DOWNWARDS|lSmall);
- }
- //空区域
- pXP->m_AreaRect = Rect;
- pXP->m_AreaRect.top = pXP->m_TopArrowRect.bottom;//+1;
- pXP->m_AreaRect.bottom = pXP->m_BottomArrowRect.top;// - 1;
- if (nType == SCROLLALL)
- ScrollDrowThumbXP(hDC, pXP->m_AreaRect, CXPH_HASFRAME|CXPH_AREA);
- else
- ScrollDrowThumbXP(hDC, pXP->m_ThumbRect, CXPH_AREA);
-
- //移动块
- ScrollCalVertical(pCxp,sif, Rect);
- lState = CXPH_LARGEARROW|CXPH_DROPHANDLE|CXPS_HOTLIGHT;
- if (pXP->m_bMouseDown)
- lState |= CXPS_PRESSED;
- if(!lSmall)
- ScrollDrowThumbXP(hDC, pXP->m_ThumbRect, lState);
- ReleaseMemDCXP(&Mdcxp);
- }
- //计算移动块大小
- void ScrollCalHorizontal(PCLASSXP pCxp, SCROLLINFO sif, RECT Rect)
- {
- PSCROLLXP pXP;
- pXP = (PSCROLLXP)pCxp->pData;
- if(pXP->m_bDragging)sif.nPos = pXP->m_nThumbTrackPos;
- int ThumbWidth = 30;
- if(ThumbWidth > (pXP->m_AreaRect.right-pXP->m_AreaRect.left))
- ThumbWidth = (pXP->m_AreaRect.right-pXP->m_AreaRect.left)/ 2;
- double width = (pXP->m_AreaRect.right-pXP->m_AreaRect.left) - ThumbWidth;
- double range = sif.nMax - sif.nMin;
- double per = width / range;
- int pos = (int)(per * (sif.nPos - sif.nMin));
- if(range <= 0)return;
- pXP->m_ThumbRect.left = pXP->m_AreaRect.left + pos;
- pXP->m_ThumbRect.top = Rect.top;
- pXP->m_ThumbRect.right = pXP->m_ThumbRect.left + ThumbWidth;
- pXP->m_ThumbRect.bottom = Rect.bottom;
- if(pXP->m_ThumbRect.right == pXP->m_ThumbRect.left)
- pXP->m_ThumbRect.right = pXP->m_ThumbRect.left + 3;
- InflateRect(&pXP->m_ThumbRect, -1, -3);
- }
- //画水平滚动条
- void ScrollDrawHorizontal(PCLASSXP pCxp, long nType)
- {
- BOOL IsWindowEnable;
- RECT Rect;
- HWND hWnd;
- PSCROLLXP pXP;
- HDC hDC;
- long lState;
- pXP = (PSCROLLXP)pCxp->pData;
- hWnd = pCxp->hWnd;
- GetWindowRect(hWnd, &Rect);
- Rect.right -= Rect.left;
- Rect.bottom -= Rect.top;
- Rect.left = Rect.top = 0;
-
- IsWindowEnable = IsWindowEnabled(hWnd);
- //有效判断
- SCROLLINFO sif;
- ZeroMemory(&sif, sizeof(SCROLLINFO));
- sif.cbSize = sizeof(SCROLLINFO);
- sif.fMask = SIF_ALL;
- if(!GetScrollInfo(hWnd, SB_CTL, &sif))
- return;
- if(sif.nMin == sif.nMax)
- return;
- MEMDCXP Mdcxp;
- Mdcxp.hWnd = hWnd;
- Mdcxp.bTransfer = FALSE;
- Mdcxp.hBitmap = NULL;
- GetMemDCXP(&Mdcxp);
- hDC = Mdcxp.hDC;
- //左箭头
- pXP->m_LeftArrowRect = Rect;
- pXP->m_LeftArrowRect.right = Rect.left+Rect.bottom-Rect.top;
- // if (nType == SCROLLLEFTARROW || nType == SCROLLALL)
- // ScrollDrawButton(pCxp,hDC,pXP->m_LeftArrowRect, SBS_HORZ,SCROLLLEFTARROW);
- if (nType == SCROLLLEFTARROW || nType == SCROLLALL)
- { if(pXP->m_bMouseDownArrowForback)
- ScrollDrowThumbXP(hDC, pXP->m_LeftArrowRect, CXPH_LARGEARROW|CXPH_LEFTWARDS|CXPS_PRESSED);
- else
- ScrollDrowThumbXP(hDC, pXP->m_LeftArrowRect, CXPH_LARGEARROW|CXPH_LEFTWARDS);
- }
- //右箭头
- pXP->m_RightArrowRect = Rect;
- pXP->m_RightArrowRect.left = Rect.right-(Rect.bottom-Rect.top);
- // if (nType == SCROLLRIGHTARROW || nType == SCROLLALL)
- // ScrollDrawButton(pCxp,hDC,pXP->m_RightArrowRect, SBS_HORZ,SCROLLRIGHTARROW);
- if (nType == SCROLLRIGHTARROW || nType == SCROLLALL)
- { if(pXP->m_bMouseDownArrowForwad)
- ScrollDrowThumbXP(hDC, pXP->m_RightArrowRect, CXPH_LARGEARROW|CXPH_RIGHTWARDS|CXPS_PRESSED);
- else
- ScrollDrowThumbXP(hDC, pXP->m_RightArrowRect, CXPH_LARGEARROW|CXPH_RIGHTWARDS);
- }
- //空区域
- pXP->m_AreaRect = Rect;
- pXP->m_AreaRect.left = pXP->m_LeftArrowRect.right;//+1;
- pXP->m_AreaRect.right = pXP->m_RightArrowRect.left;// - 1;
- // if (nType == SCROLLALL)
- // ScrollDrawButton(pCxp,hDC,pXP->m_AreaRect, SBS_HORZ,SCROLLAREA);
- // else
- // ScrollDrawButton(pCxp,hDC,pXP->m_ThumbRect, SBS_HORZ,SCROLLAREANULL);
- if (nType == SCROLLALL)
- ScrollDrowThumbXP(hDC, pXP->m_AreaRect, CXPS_HORIZON|CXPH_HASFRAME|CXPH_AREA);
- else
- ScrollDrowThumbXP(hDC, pXP->m_ThumbRect,CXPS_HORIZON|CXPH_AREA);
- //移动块
- ScrollCalHorizontal(pCxp,sif, Rect);
- // ScrollDrawButton(pCxp,hDC,pXP->m_ThumbRect,SBS_HORZ, SCROLLTHUMB);
- lState = CXPS_HOTLIGHT|CXPH_DROPHANDLE|CXPS_HORIZON;
- if (pXP->m_bMouseDown)
- lState |= CXPS_PRESSED;
- ScrollDrowThumbXP(hDC, pXP->m_ThumbRect, lState);
- /* if(!IsWindowEnable)
- CRTDraw::RTDrawBitmap(&memDC,&m_ThumbRect,m_ScrollBarHorizontalBitmap[BMP_DISABLE],m_ScrollBarHorizontalBitmapDrawMode[BMP_DISABLE]);
- else
- {
- if(m_bDragging)
- CRTDraw::RTDrawBitmap(&memDC,&m_ThumbRect,m_ScrollBarHorizontalBitmap[BMP_DOWN],m_ScrollBarHorizontalBitmapDrawMode[BMP_DOWN]);
- else
- CRTDraw::RTDrawBitmap(&memDC,&m_ThumbRect,m_ScrollBarHorizontalBitmap[BMP_NORMAL],m_ScrollBarHorizontalBitmapDrawMode[BMP_NORMAL]);
- }
- */
- ReleaseMemDCXP(&Mdcxp);
- }
- //压下左键
- void ScrollOnLButtonDown(PCLASSXP pCxp,WPARAM wParam,LPARAM lParam)
- //UINT nFlags, CPoint point
- {
- SCROLLINFO sif;
- POINT point;
- PSCROLLXP pXP;
- HWND hWnd, hParent;
- HDC hDC;
- DWORD dwStyle;
- pXP = (PSCROLLXP)pCxp->pData;
- // pXP->m_MouseDownTime = 0;
- hWnd = pCxp->hWnd;
- point.x = LOWORD(lParam);
- point.y = HIWORD(lParam);
- SetCapture(hWnd);
- // DWORD style = GetStyle();
- dwStyle = (DWORD)GetWindowLong(pCxp->hWnd, GWL_STYLE);
- hParent = GetParent(hWnd);
- if((dwStyle & SBS_VERT)==SBS_VERT)
- {
- if(PtInRect(&pXP->m_ThumbRect,point))
- {
- pXP->m_bMouseDown = true;
- pXP->m_MouseDownPoint.x = point.x - pXP->m_ThumbRect.left;
- pXP->m_MouseDownPoint.y = point.y - pXP->m_ThumbRect.top;
- hDC = GetDC(pCxp->hWnd); //强制刷亮移动块
- //pXP->m_bDragging = true;
- //ScrollDrawButton(pCxp,hDC,pXP->m_ThumbRect,SBS_VERT, SCROLLTHUMB);
- ScrollDrowThumbXP(hDC, pXP->m_ThumbRect,
- CXPH_LARGEARROW|CXPH_DROPHANDLE|CXPS_PRESSED);
- //pXP->m_bDragging = false;
- //ScrollDrawVertical(pCxp, SCROLLALL);
- ReleaseDC(hWnd,hDC);
- }
- else if(PtInRect(&pXP->m_BottomArrowRect,point))
- {
- // SetTimer(hWnd,2,100,NULL);
- pXP->m_bMouseDownArrowForwad = true;
- //hDC = GetDC(pCxp->hWnd);
- //ReleaseDC(hWnd,hDC);
- SendMessage(hWnd,WM_SETREDRAW,FALSE,0);
- SendMessage(hParent,WM_VSCROLL,MAKEWPARAM(SB_LINEDOWN,0),(LPARAM)hWnd);
- SendMessage(hWnd,WM_SETREDRAW,TRUE,0);
- ScrollDrawVertical(pCxp, SCROLLBOTTOMARROW);
- //CClientDC dc(this);
- //DrawVertical(&dc);
- }
- else if(PtInRect(&pXP->m_TopArrowRect,point))
- {
- // SetTimer(hWnd,2,100,NULL);
- pXP->m_bMouseDownArrowForback = true;
- //hDC = GetDC(pCxp->hWnd);
- //ReleaseDC(hWnd,hDC);
- SendMessage(hWnd,WM_SETREDRAW,FALSE,0);
- SendMessage(hParent,WM_VSCROLL,MAKEWPARAM(SB_LINEUP,0),(LPARAM)hWnd);
- SendMessage(hWnd,WM_SETREDRAW,TRUE,0);
- ScrollDrawVertical(pCxp, SCROLLTOPARROW);
- //CClientDC dc(this);
- //DrawVertical(&dc);
- //SetTimer(2,100,NULL);
- }
- else if(PtInRect(&pXP->m_AreaRect,point))
- {
- if(hParent != NULL)
- {
- ZeroMemory(&sif,sizeof(sif));
- sif.cbSize = sizeof(sif);
- sif.fMask = SIF_ALL;
- // GetScrollInfo(hWnd,SB_VERT, &sif);
- GetScrollInfo(hWnd, SB_CTL, &sif);
-
- if(point.y < pXP->m_ThumbRect.top)
- {
- pXP->m_bMouseDownArrowForback = TRUE;
- SendMessage(hWnd,WM_SETREDRAW,FALSE,0);
- SendMessage(hParent,WM_VSCROLL,MAKEWPARAM(SB_PAGEUP,0),(LPARAM)hWnd);
- SendMessage(hWnd,WM_SETREDRAW,TRUE,0);
- ScrollDrawVertical(pCxp, SCROLLAREANULL);
- }
- else
- {
- pXP->m_bMouseDownArrowForwad = TRUE;
- SendMessage(hWnd,WM_SETREDRAW,FALSE,0);
- SendMessage(hParent,WM_VSCROLL,MAKEWPARAM(SB_PAGEDOWN,0),(LPARAM)hWnd);
- SendMessage(hWnd,WM_SETREDRAW,TRUE,0);
- ScrollDrawVertical(pCxp, SCROLLAREANULL);
- }
- }
- // SetTimer(hWnd,1,100,NULL);
- //SetTimer(1,100,NULL);
- }
- }
- else
- {
- if(PtInRect(&pXP->m_ThumbRect,point))
- {
- pXP->m_bMouseDown = true;
- pXP->m_MouseDownPoint.x = point.x - pXP->m_ThumbRect.left;
- pXP->m_MouseDownPoint.y = point.y - pXP->m_ThumbRect.top;
- pXP->m_bDragging = true;
-
- hDC = GetDC(pCxp->hWnd); //强制刷亮移动块
- // pXP->m_bDragging = true;
- // ScrollDrawButton(pCxp,hDC,pXP->m_ThumbRect,SBS_HORZ, SCROLLTHUMB);
- // pXP->m_bDragging = false;
- ScrollDrowThumbXP(hDC, pXP->m_ThumbRect, CXPS_HORIZON|
- CXPH_LARGEARROW|CXPH_DROPHANDLE|CXPS_PRESSED);
- ReleaseDC(hWnd,hDC);
- }
- else if(PtInRect(&pXP->m_RightArrowRect,point))
- {
- pXP->m_bMouseDownArrowForwad = true;
- SendMessage(hWnd,WM_SETREDRAW,FALSE,0);
- SendMessage(hParent,WM_HSCROLL,MAKEWPARAM(SB_LINERIGHT,0),(LPARAM)hWnd);
- SendMessage(hWnd,WM_SETREDRAW,TRUE,0);
- // CClientDC dc(this);
- // DrawHorizontal(&dc);
- // hDC = GetDC(hWnd);
- ScrollDrawHorizontal(pCxp, SCROLLRIGHTARROW);
- // ReleaseDC(hWnd,hDC);
- // SetTimer(hWnd,2,100,NULL);
- //SetTimer(2,100,NULL);
- }
- else if(PtInRect(&pXP->m_LeftArrowRect,point))
- {
- pXP->m_bMouseDownArrowForback = true;
- SendMessage(hWnd,WM_SETREDRAW,FALSE,0);
- SendMessage(hParent,WM_HSCROLL,MAKEWPARAM(SB_LINELEFT,0),(LPARAM)hWnd);
- SendMessage(hWnd,WM_SETREDRAW,TRUE,0);
- // CClientDC dc(this);
- // DrawHorizontal(&dc);
- // hDC = GetDC(hWnd);
- ScrollDrawHorizontal(pCxp, SCROLLLEFTARROW);
- // ReleaseDC(hWnd,hDC);
- // SetTimer(hWnd,2,100,NULL);
- }
- else if(PtInRect(&pXP->m_AreaRect,point))
- {
- if(hParent != NULL)
- {
- ZeroMemory(&sif,sizeof(sif));
- sif.cbSize = sizeof(sif);
- sif.fMask = SIF_ALL;
- // GetScrollInfo(&sif,SIF_PAGE|SIF_RANGE|SIF_POS|SIF_TRACKPOS);
- GetScrollInfo(hWnd, SB_CTL, &sif);
- if(point.x < pXP->m_ThumbRect.left)
- {
- pXP->m_bMouseDownArrowForback = TRUE;
- SendMessage(hWnd,WM_SETREDRAW,FALSE,0);
- SendMessage(hParent,WM_HSCROLL,MAKEWPARAM(SB_PAGELEFT,0),(LPARAM)hWnd);
- SendMessage(hWnd,WM_SETREDRAW,TRUE,0);
- ScrollDrawHorizontal(pCxp, SCROLLAREANULL);
- }
- else
- {
- pXP->m_bMouseDownArrowForwad = TRUE;
- SendMessage(hWnd,WM_SETREDRAW,FALSE,0);
- SendMessage(hParent,WM_HSCROLL,MAKEWPARAM(SB_PAGERIGHT,0),(LPARAM)hWnd);
- SendMessage(hWnd,WM_SETREDRAW,TRUE,0);
- ScrollDrawHorizontal(pCxp, SCROLLAREANULL);
- }
- }
- // SetTimer(hWnd,1,100,NULL);
- }
- }
- }
- ////////////////////////////////////////////////////////////
- //松开左键
- void ScrollOnLButtonUp(PCLASSXP pCxp,WPARAM wParam,LPARAM lParam)
- //UINT nFlags, CPoint point
- {
- POINT point, mousePoint;
- PSCROLLXP pXP;
- HWND hWnd, hParent;
- HDC hDC;
- DWORD dwStyle;
- SCROLLINFO sif;
- pXP = (PSCROLLXP)pCxp->pData;
- pXP->m_MouseDownTime = 0;
- hWnd = pCxp->hWnd;
- point.x = LOWORD(lParam);
- point.y = HIWORD(lParam);
- ReleaseCapture();
-
- // DWORD style = GetStyle();
- // CWnd *pParent = GetParent();
- dwStyle = (DWORD)GetWindowLong(pCxp->hWnd, GWL_STYLE);
- hParent = GetParent(hWnd);
- if(pXP->m_bDragging)
- {
- pXP->m_bDragging = FALSE;
- pXP->m_bMouseDown = FALSE;
- mousePoint.x = pXP->m_ThumbRect.left + pXP->m_MouseDownPoint.x;
- mousePoint.y= pXP->m_ThumbRect.top + pXP->m_MouseDownPoint.y;
- if( (dwStyle & SBS_VERT) == SBS_VERT)
- {
- if(mousePoint.y != point.y)
- {
- int move = point.y - mousePoint.y;
- double pos = pXP->m_ThumbRect.top + move - pXP->m_AreaRect.top;
- double height = (pXP->m_AreaRect.bottom-pXP->m_AreaRect.top) -
- (pXP->m_ThumbRect.bottom-pXP->m_ThumbRect.top);
- double per = pos / height;
- //GetScrollInfo(&sif);
- ZeroMemory(&sif,sizeof(sif));
- sif.cbSize = sizeof(SCROLLINFO);
- sif.fMask = SIF_ALL;
- GetScrollInfo(hWnd, SB_CTL, &sif);
- int newpos = (int)((sif.nMax - sif.nMin) * per);
- if(newpos < sif.nMin)newpos = sif.nMin;
- if(newpos > sif.nMax)newpos = sif.nMax;
- if(hParent != NULL)
- {
- SendMessage(hWnd,WM_SETREDRAW,FALSE,0);
- SendMessage(hParent,WM_VSCROLL,MAKEWPARAM(SB_THUMBPOSITION,newpos),(LPARAM)hWnd);
- SendMessage(hWnd,WM_SETREDRAW,TRUE,0);
- }
- // ScrollDrawVertical(pCxp, SCROLLAREANULL);
- }
- ScrollDrawVertical(pCxp, SCROLLALL);
- }
- else
- {
- if(mousePoint.x != point.x)
- {
- int move = point.x - mousePoint.x;
- double pos = pXP->m_ThumbRect.left + move - pXP->m_AreaRect.left;
- double width = (pXP->m_AreaRect.right-pXP->m_AreaRect.left) -
- (pXP->m_ThumbRect.right-pXP->m_ThumbRect.left);
- double per = pos / width;
- ZeroMemory(&sif,sizeof(sif));
- sif.cbSize = sizeof(SCROLLINFO);
- // GetScrollInfo(&sif);
- sif.fMask = SIF_ALL;
- GetScrollInfo(hWnd, SB_CTL, &sif);
- int newpos = (int)((sif.nMax - sif.nMin) * per);
- if(newpos < sif.nMin)newpos = sif.nMin;
- if(newpos > sif.nMax)newpos = sif.nMax;
- if(hParent != NULL)
- {
- SendMessage(hWnd,WM_SETREDRAW,FALSE,0);
- SendMessage(hParent,WM_HSCROLL,MAKEWPARAM(SB_THUMBPOSITION,newpos),(LPARAM)hWnd);
- SendMessage(hWnd,WM_SETREDRAW,TRUE,0);
- }
- }
- ScrollDrawHorizontal(pCxp, SCROLLALL);
- }
- }
- else if (pXP->m_bMouseDown) //移动块
- {
- hDC = GetDC(pCxp->hWnd);
- pXP->m_bMouseDown = false;
- if ((dwStyle & SBS_VERT) == SBS_VERT) //
- ScrollDrowThumbXP(hDC, pXP->m_ThumbRect,CXPS_HOTLIGHT|CXPH_DROPHANDLE);
- else
- ScrollDrowThumbXP(hDC, pXP->m_ThumbRect,CXPS_HOTLIGHT|CXPH_DROPHANDLE|CXPS_HORIZON);
- ReleaseDC(hWnd,hDC);
- }
- else if (pXP->m_bMouseDownArrowForback&&
- (dwStyle & SBS_VERT) == SBS_VERT) //上键
- {
- hDC = GetDC(pCxp->hWnd);
- pXP->m_bMouseDownArrowForback = false;
- ScrollDrowThumbXP(hDC, pXP->m_TopArrowRect, CXPH_LARGEARROW|CXPH_UPWARDS);
- ReleaseDC(hWnd,hDC);
- }
- else if (pXP->m_bMouseDownArrowForwad &&
- (dwStyle & SBS_VERT) == SBS_VERT) //下键
- {
- hDC = GetDC(pCxp->hWnd);
- pXP->m_bMouseDownArrowForwad = false;
- ScrollDrowThumbXP(hDC, pXP->m_BottomArrowRect, CXPH_LARGEARROW|CXPH_DOWNWARDS);
- ReleaseDC(hWnd,hDC);
- // ScrollDrawHorizontal(pCxp, SCROLLRIGHTARROW);
- }
- else if (pXP->m_bMouseDownArrowForback&&
- (dwStyle & SBS_HORZ) == SBS_HORZ) //左键
- {
- hDC = GetDC(pCxp->hWnd);
- pXP->m_bMouseDownArrowForback = false;
- ScrollDrowThumbXP(hDC, pXP->m_LeftArrowRect, CXPH_LARGEARROW|CXPH_LEFTWARDS);
- ReleaseDC(hWnd,hDC);
- // ScrollDrawHorizontal(pCxp, SCROLLLEFTARROW);
- }
- else if (pXP->m_bMouseDownArrowForwad&&
- (dwStyle & SBS_HORZ) == SBS_HORZ) //右键
- {
- hDC = GetDC(pCxp->hWnd);
- pXP->m_bMouseDownArrowForwad = false;
- ScrollDrowThumbXP(hDC, pXP->m_RightArrowRect, CXPH_LARGEARROW|CXPH_RIGHTWARDS);
- ReleaseDC(hWnd,hDC);
- // ScrollDrawHorizontal(pCxp, SCROLLLEFTARROW);
- }
- if(pXP->m_bMouseDown ||
- pXP->m_bMouseDownArrowForback ||
- pXP->m_bMouseDownArrowForwad)
- {
- pXP->m_bMouseDown = FALSE;
- pXP->m_bMouseDownArrowForback = FALSE;
- pXP->m_bMouseDownArrowForwad = FALSE;
- // KillTimer(hWnd,2);
- // KillTimer(hWnd,1);
- //CClientDC dc(this);
- //if((style & SBS_VERT) == SBS_VERT)
- // DrawVertical(&dc);
- //else
- // DrawHorizontal(&dc);
- //ScrollOnPaint(pCxp);
- }
- }
- //////////////////////////////////////////////////////////////
- void ScrollOnMouseMove(PCLASSXP pCxp, WPARAM wParam, LPARAM lParam)
- // UINT nFlags, CPoint point
- {
- POINT point, mousePoint;
- PSCROLLXP pXP;
- HWND hWnd, hParent;
- RECT Rect;
- HDC hDC;
- DWORD dwStyle;
- SCROLLINFO sif;
- pXP = (PSCROLLXP)pCxp->pData;
- // pXP->m_MouseDownTime = 0;
- hWnd = pCxp->hWnd;
- point.x = LOWORD(lParam);
- point.y = HIWORD(lParam);
- dwStyle = (DWORD)GetWindowLong(pCxp->hWnd, GWL_STYLE);
- GetWindowRect(hWnd, &Rect);
- Rect.right -= Rect.left;
- Rect.bottom -= Rect.top;
- Rect.left = Rect.top = 0;
- hParent = GetParent(hWnd);
-
- // CWnd *pParent = GetParent();
- if(hParent == NULL)return;
- if(pXP->m_bMouseDown)pXP->m_bDragging = TRUE;
- if(!pXP->m_bDragging)return;
- mousePoint.x = pXP->m_ThumbRect.left + pXP->m_MouseDownPoint.x;
- mousePoint.y = pXP->m_ThumbRect.top + pXP->m_MouseDownPoint.y;
- // DWORD style = GetStyle();
- // dwStyle = (DWORD)GetWindowLong(pCxp->hWnd, GWL_STYLE);
- if( (dwStyle & SBS_VERT) == SBS_VERT)
- {
- if(mousePoint.y == point.y)return;
- // if(!PtInRect(&Rect,point))return;
- int move = point.y - mousePoint.y;
- double pos = pXP->m_ThumbRect.top + move - pXP->m_AreaRect.top;
- double height = (pXP->m_AreaRect.bottom-pXP->m_AreaRect.top) -
- (pXP->m_ThumbRect.bottom-pXP->m_ThumbRect.top);
- double per = pos / height;
- // GetScrollInfo(&sif);
- ZeroMemory(&sif,sizeof(sif));
- sif.cbSize = sizeof(SCROLLINFO);
- sif.fMask = SIF_ALL;
- GetScrollInfo(hWnd, SB_CTL, &sif);
- int newpos = (int)((sif.nMax - sif.nMin) * per);
- if(newpos < sif.nMin) newpos = sif.nMin;
- if(newpos > sif.nMax) newpos = sif.nMax;
- sif.nTrackPos = newpos;
- if(pXP->m_nThumbTrackPos != newpos)
- {
- /* hDC = GetDC(hWnd);
- ScrollDrawButton(pCxp,hDC,pXP->m_ThumbRect, SBS_VERT, SCROLLAREANULL);
- pXP->m_nThumbTrackPos = newpos;
- ScrollCalVertical(pCxp,sif,Rect);
- ScrollDrawButton(pCxp,hDC,pXP->m_ThumbRect, SBS_VERT, SCROLLTHUMB);
- ReleaseDC(hWnd,hDC);
- */
- SendMessage(hWnd,WM_SETREDRAW,FALSE,0);
- SendMessage(hParent,WM_VSCROLL,MAKEWPARAM(SB_THUMBTRACK,sif.nTrackPos),(LPARAM)hWnd);
- SendMessage(hWnd,WM_SETREDRAW,TRUE,0);
- hDC = GetDC(hWnd);
- ScrollDrowThumbXP(hDC, pXP->m_ThumbRect, CXPH_AREA);
- // ScrollDrowThumbXP(hDC, pXP->m_AreaRect, CXPH_LARGEARROW|CXPH_HASFRAME);
- pXP->m_nThumbTrackPos = newpos;
- ScrollCalVertical(pCxp,sif, Rect);
- ScrollDrowThumbXP(hDC, pXP->m_ThumbRect, CXPS_PRESSED|
- CXPH_LARGEARROW|CXPH_DROPHANDLE);
- ReleaseDC(hWnd,hDC);
- }
- }
- else
- {
- if(mousePoint.x == point.x)return;
- // if(!PtInRect(&Rect,point))return;
- int move = point.x - mousePoint.x;
- double pos = pXP->m_ThumbRect.left + move - pXP->m_AreaRect.left;
- double width = (pXP->m_AreaRect.right-pXP->m_AreaRect.left) -
- (pXP->m_ThumbRect.right-pXP->m_ThumbRect.left);
- double per = pos / width;
- // GetScrollInfo(&sif);
- ZeroMemory(&sif,sizeof(sif));
- sif.cbSize = sizeof(SCROLLINFO);
- sif.fMask = SIF_ALL;
- GetScrollInfo(hWnd, SB_CTL, &sif);
- int newpos = (int)((sif.nMax - sif.nMin) * per);
- if(newpos < sif.nMin) newpos = sif.nMin;
- if(newpos > sif.nMax) newpos = sif.nMax;
- sif.nTrackPos = newpos;
- if(pXP->m_nThumbTrackPos != newpos)
- {
- /* hDC = GetDC(hWnd);
- ScrollDrawButton(pCxp,hDC,pXP->m_ThumbRect, SBS_HORZ, SCROLLAREANULL);
- //GetScrollInfo(hWnd, SB_CTL, &sif);
- pXP->m_nThumbTrackPos = newpos;
- ScrollCalHorizontal(pCxp,sif,Rect);
- ScrollDrawButton(pCxp,hDC,pXP->m_ThumbRect, SBS_HORZ, SCROLLTHUMB);
- ReleaseDC(hWnd,hDC);
- */
- SendMessage(hWnd,WM_SETREDRAW,FALSE,0);
- SendMessage(hParent,WM_HSCROLL,MAKEWPARAM(SB_THUMBTRACK,sif.nTrackPos),(LPARAM)hWnd);
- SendMessage(hWnd,WM_SETREDRAW,TRUE,0);
- hDC = GetDC(hWnd);
- ScrollDrowThumbXP(hDC, pXP->m_ThumbRect, CXPS_HORIZON|CXPH_AREA);
- pXP->m_nThumbTrackPos = newpos;
- ScrollCalHorizontal(pCxp,sif, Rect);
- ScrollDrowThumbXP(hDC, pXP->m_ThumbRect, CXPS_PRESSED|
- CXPH_LARGEARROW|CXPH_DROPHANDLE|CXPS_HORIZON);
- // ScrollDrawVertical(pCxp, SCROLLTHUMB);
- ReleaseDC(hWnd,hDC);
- }
- }
- }
- ////////////////////////////////////////////////////////////
- void CALLBACK ScrollOnTimer(PCLASSXP pCxp, UINT nIDEvent)
- {
- // if(!m_IsEnableSkin)return CScrollBar::OnTimer(nIDEvent);
- /* POINT point;
- SCROLLINFO sif;
- PSCROLLXP pXP;
- HWND hWnd, hParent;
- HDC hDC;
- DWORD dwStyle;
- pXP = (PSCROLLXP)pCxp->pData;
- // pXP->m_MouseDownTime = 0;
- hWnd = pCxp->hWnd;
- if(pXP->m_MouseDownTime < 3)
- {
- pXP->m_MouseDownTime++;
- return;
- }
- // CWnd* pParent = GetParent();
- // DWORD style = GetStyle();
- dwStyle = (DWORD)GetWindowLong(pCxp->hWnd, GWL_STYLE);
- hParent = GetParent(hWnd);
- // GetScrollInfo(&sif);
- // GetScrollInfo(hWnd,SB_VERT, &sif);
- if( (dwStyle & SBS_VERT) == SBS_VERT)
- {
- if(nIDEvent == 2)
- {
- if(pXP->m_bMouseDownArrowForback)
- {
- SendMessage(hParent,WM_VSCROLL,MAKEWPARAM(SB_LINEUP,0),(LPARAM)hWnd);
- }
- else if(pXP->m_bMouseDownArrowForwad)
- {
- SendMessage(hParent,WM_VSCROLL,MAKEWPARAM(SB_LINEDOWN,0),(LPARAM)hWnd);
- }
- }
- else if(nIDEvent == 1)
- {
- // CPoint point;
- GetCursorPos(&point);
- ScreenToClient(hWnd, &point);
- if(!PtInRect(&pXP->m_ThumbRect,point))
- {
- if(pXP->m_bMouseDownArrowForback)
- {
- SendMessage(hParent,WM_VSCROLL,MAKEWPARAM(SB_PAGEUP,0),(LPARAM)hWnd);
- }
- else if(pXP->m_bMouseDownArrowForwad)
- {
- SendMessage(hParent,WM_VSCROLL,MAKEWPARAM(SB_PAGEDOWN,0),(LPARAM)hWnd);
- }
- }
- }
- }
- else
- {
- if(nIDEvent == 2)
- {
- if(pXP->m_bMouseDownArrowForback)
- {
- SendMessage(hParent,WM_HSCROLL,MAKEWPARAM(SB_LINELEFT,0),(LPARAM)hWnd);
- }
- else if(pXP->m_bMouseDownArrowForwad)
- {
- SendMessage(hParent,WM_HSCROLL,MAKEWPARAM(SB_LINERIGHT,0),(LPARAM)hWnd);
- }
- }
- else if(nIDEvent == 1)
- {
- //CPoint point;
- GetCursorPos(&point);
- ScreenToClient(hWnd, &point);
- if(!PtInRect(&pXP->m_ThumbRect,point))
- {
- if(pXP->m_bMouseDownArrowForback)
- {
- SendMessage(hParent,WM_HSCROLL,MAKEWPARAM(SB_PAGELEFT,0),(LPARAM)hWnd);
- }
- else if(pXP->m_bMouseDownArrowForwad)
- {
- SendMessage(hParent,WM_HSCROLL,MAKEWPARAM(SB_PAGERIGHT,0),(LPARAM)hWnd);
- }
- }
- }
- }
- */
- }
- void ScrollOnPaint(PCLASSXP pCxp)
- {
- //CPaintDC dc(this);
- //HDC hDC = GetDC(pCxp->hWnd);
- DWORD dwStyle = (DWORD)GetWindowLong(pCxp->hWnd, GWL_STYLE);
- if( (dwStyle & SBS_VERT) == SBS_VERT)
- {
- ScrollDrawVertical(pCxp, SCROLLALL); //全部
- }
- else
- {
- ScrollDrawHorizontal(pCxp, SCROLLALL); //全部
- }
- //ReleaseDC(pCxp->hWnd,hDC);
- }
- /////////////////////////////////////////////////////////////
- void ScrollOnLButtonDblClk(PCLASSXP pCxp,WPARAM wParam, LPARAM lParam)
- //UINT nFlags, CPoint point
- {
- ScrollOnLButtonDown(pCxp,wParam,lParam);
- ScrollOnLButtonUp(pCxp,wParam,lParam);
- }
- ////////////////////////////////////////////////////////////////////////////////////////////////////
- LRESULT ScrollWindowProc(PCLASSXP pCxp, UINT message,WPARAM wParam, LPARAM lParam)
- {
- LONG lReturn;
- HWND hWnd = pCxp->hWnd;
- switch (message)
- {
- case WM_LBUTTONDBLCLK :
- ScrollOnLButtonDblClk(pCxp, wParam,lParam);
- return 0;
- case WM_LBUTTONDOWN: //11
- ScrollOnLButtonDown(pCxp, wParam,lParam);
- return 0;
- case WM_LBUTTONUP: //11
- ScrollOnLButtonUp(pCxp, wParam,lParam);
- return 0;
- case WM_MOUSEMOVE: //12
- ScrollOnMouseMove(pCxp, wParam,lParam);
- return 0;
- case WM_ERASEBKGND:
- return TRUE;
- case WM_TIMER:
- ScrollOnTimer(pCxp, (UINT )wParam);
- lReturn = DefWindowProc(hWnd, message, wParam, lParam);
- return lReturn;
- break;
- case WM_NCPAINT:
- return 0;
- case WM_PAINT:
- lReturn = DefWindowProc(hWnd, message, wParam, lParam);
- ScrollOnPaint(pCxp);
- return lReturn;
- }
-
- // 调用原来的回调函数
- lReturn = (LONG) CallWindowProc(pCxp->wpPrev, hWnd, message, wParam, lParam);
- if (message == WM_NCDESTROY) // 窗口销毁
- DeleteClassXP(hWnd);
- return lReturn;
- }
- //尾部
- #ifdef __cplusplus
- }
- #endif // __cplusplus
- /*****************************************************************/
|