// ComboXP.cpp: implementation of the CComboXP class. // ////////////////////////////////////////////////////////////////////// /**************以下设置必需包含在每个子类中**********************/ //头部 //////////////////////////////////////////////////////////////////////////////////////////////////// // 编译预处理 #if _WIN32_WINNT < 0x0400 #define _WIN32_WINNT 0x0400 #endif // 强制使用 C 语言方式编译 #ifdef __cplusplus extern "C" { #endif // __cplusplus #include "ComboXP.h" #include "ScrollXP.H" ////////////////////////////////////////////////////////////////////////////////////////////////// // 全局变量 extern HHOOK g_hPrevHookXP ; // 窗口消息 HOOK 句柄 extern PCLASSXP g_pClassXP ; // 窗口的 CLASSXP 结构指针 extern COLORREF g_crDialogbkColor; // 窗口背景颜色 ////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////////////////////////// // 绘制组合框 VOID WINAPI ComboDrawComboBoxXP(PCLASSXP pCxp) { /* int i; RECT Rect; MEMDCXP Mdcxp; 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} }; // 获取内存兼容设备场景 Mdcxp.hWnd = pCxp->hWnd; Mdcxp.bTransfer = TRUE; Mdcxp.hBitmap = NULL; GetMemDCXP(&Mdcxp); // 获取窗口大小 GetWindowRect(pCxp->hWnd, &Rect); Rect.right -= Rect.left; Rect.bottom -= Rect.top; Rect.top = Rect.left = 0; // 绘制外框 hHandle = (HANDLE) CreateSolidBrush( (pCxp->dwState & CXPS_DISABLED) ? (GetSysColor(COLOR_BTNFACE) - 0x00202020) : 0x00BD9E7B); FrameRect(Mdcxp.hMemDC, &Rect, (HBRUSH) hHandle); DeleteObject((HGDIOBJ) hHandle); // 绘制内框 InflateRect(&Rect, -1, -1); // hHandle = (HANDLE) GetSysColorBrush((pCxp->dwState & CXPS_DISABLED) ? COLOR_BTNFACE : COLOR_WINDOW); if (pCxp->dwState & CXPS_DISABLED) hHandle = (HANDLE) GetSysColorBrush(g_crDialogbkColor); else hHandle = (HANDLE) GetSysColorBrush(COLOR_WINDOW); FrameRect(Mdcxp.hMemDC, &Rect, (HBRUSH) hHandle); InflateRect(&Rect, -1, -1); Rect.left = Rect.right - GetSystemMetrics(SM_CYVTHUMB); FrameRect(Mdcxp.hMemDC, &Rect, (HBRUSH) hHandle); Rect.left++; if (pCxp->dwState & CXPS_DISABLED) i = 0; else if (pCxp->dwState & CXPS_PRESSED) i = 1; else if (pCxp->dwState & CXPS_HOTLIGHT) i = 2; else i = 3; // 绘制下拉外框 GradientRectXP(Mdcxp.hMemDC, &Rect, s_crGradientXP[i]); // 绘制下拉外框拐角像素 SetPixel(Mdcxp.hMemDC, Rect.left, Rect.top, s_crGradientXP[i + 4][0]); SetPixel(Mdcxp.hMemDC, Rect.right - 1, Rect.top, s_crGradientXP[i + 4][1]); SetPixel(Mdcxp.hMemDC, Rect.left, Rect.bottom - 1, s_crGradientXP[i + 4][2]); SetPixel(Mdcxp.hMemDC, Rect.right - 1, Rect.bottom - 1, s_crGradientXP[i + 4][3]); // 绘制下拉内框 InflateRect(&Rect, -1, -1); GradientRectXP(Mdcxp.hMemDC, &Rect, s_crGradientXP[i + 8]); // 绘制下拉标志 Rect.left += (Rect.right - Rect.left) / 2; Rect.top += (Rect.bottom - Rect.top) / 2; hHandle = (HANDLE) SelectObject(Mdcxp.hMemDC, CreatePen(PS_SOLID, 1, (pCxp->dwState & CXPS_DISABLED) ? 0x00C6CBCE : 0x0084614A)); MoveToEx(Mdcxp.hMemDC, Rect.left - 4, Rect.top - 2, NULL); LineTo(Mdcxp.hMemDC, Rect.left, Rect.top + 2); LineTo(Mdcxp.hMemDC, Rect.left + 5, Rect.top - 3); MoveToEx(Mdcxp.hMemDC, Rect.left - 3, Rect.top - 2, NULL); LineTo(Mdcxp.hMemDC, Rect.left, Rect.top + 1); LineTo(Mdcxp.hMemDC, Rect.left + 4, Rect.top - 3); MoveToEx(Mdcxp.hMemDC, Rect.left - 3, Rect.top - 3, NULL); LineTo(Mdcxp.hMemDC, Rect.left, Rect.top); LineTo(Mdcxp.hMemDC, Rect.left + 4, Rect.top - 4); DeleteObject(SelectObject(Mdcxp.hMemDC, (HGDIOBJ) hHandle)); // 还原并释放内存设备场景 Mdcxp.bTransfer = TRUE; ReleaseMemDCXP(&Mdcxp); */ RECT Rect; MEMDCXP Mdcxp; HANDLE hHandle; // 获取窗口大小 GetWindowRect(pCxp->hWnd, &Rect); Rect.right -= Rect.left; Rect.bottom -= Rect.top; Rect.top = Rect.left = 0; //在WIN98下会把箭头绘到下拉窗口中 if (Rect.bottom>2*GetSystemMetrics(SM_CYVTHUMB)) return; // 获取内存兼容设备场景 Mdcxp.hWnd = pCxp->hWnd; Mdcxp.bTransfer = TRUE; Mdcxp.hBitmap = NULL; GetMemDCXP(&Mdcxp); #ifdef CXP_BKCOLOR hHandle = (HANDLE) CreateSolidBrush( (pCxp->lState & CXPS_DISABLED) ? (CXP_BKCOLOR - 0x00202020) : 0x00BD9E7B); #else // CXP_BKCOLOR hHandle = (HANDLE) CreateSolidBrush( (pCxp->dwState & CXPS_DISABLED) ? (GetSysColor(COLOR_BTNFACE) - 0x00202020) : 0x00BD9E7B); #endif // CXP_BKCOLOR // 绘制外框 FrameRect(Mdcxp.hMemDC, &Rect, (HBRUSH) hHandle); DeleteObject((HGDIOBJ) hHandle); // 绘制内框 InflateRect(&Rect, -1, -1); #ifdef CXP_BKCOLOR hHandle = (HANDLE) CreateSolidBrush( (pCxp->dwState & CXPS_DISABLED) ? CXP_BKCOLOR : GetSysColor(COLOR_WINDOW)); #else // CXP_BKCOLOR hHandle = (HANDLE) GetSysColorBrush( (pCxp->dwState & CXPS_DISABLED) ? COLOR_BTNFACE : COLOR_WINDOW); #endif // CXP_BKCOLOR FrameRect(Mdcxp.hMemDC, &Rect, (HBRUSH) hHandle); InflateRect(&Rect, -1, -1); Rect.left = Rect.right - GetSystemMetrics(SM_CYVTHUMB); FrameRect(Mdcxp.hMemDC, &Rect, (HBRUSH) hHandle); #ifdef CXP_BKCOLOR DeleteObject(hHandle); #endif // CXP_BKCOLOR Rect.left++; ScrollDrowThumbXP(Mdcxp.hMemDC, Rect, pCxp->dwState | CXPH_DOWNWARDS | CXPH_LARGEARROW); //MoveToEx(Mdcxp.hMemDC, 0, 0); /*if (pCxp->iType == CXPT_COMBOBOX) { char szTemp[1024]; HDC h = GetWindowDC(NULL); wsprintf(szTemp, "%d", Sbi.dxyLineButton); TextOut(h, 100, 100, szTemp, lstrlen(szTemp)); ReleaseDC(NULL, h); } if (GetWindowLong(pCxp->hWnd, GWL_STYLE) & CBS_AUTOHSCROLL ) { pCxp->lState &= ~CXPS_HORIZON; ScrollBarXP(Mdcxp.hMemDC, pCxp); }*/ // 还原并释放内存设备场景 Mdcxp.bTransfer = TRUE; ReleaseMemDCXP(&Mdcxp); } BOOL WINAPI ComboOnMouseDown(PCLASSXP pCxp) { RECT Rect; POINT point; // 获取窗口大小 GetWindowRect(pCxp->hWnd, &Rect); Rect.right -= Rect.left; Rect.bottom -= Rect.top; Rect.top = Rect.left = 0; GetCursorPos(&point); Rect.left = Rect.right - 2 * GetSystemMetrics(SM_CYVTHUMB); if(Rect.left < 0) Rect.left = 0; ScreenToClient(pCxp->hWnd, &point); if(!PtInRect(&Rect,point)) return FALSE; pCxp->dwState |= CXPS_PRESSED; ComboDrawComboBoxXP(pCxp); Sleep(300); pCxp->dwState &= ~CXPS_PRESSED; ComboDrawComboBoxXP(pCxp); return TRUE; // } /****************************************************************/ LRESULT ComboWindowProc(PCLASSXP pCxp, UINT message,WPARAM wParam, LPARAM lParam) { LONG lReturn; POINT point; HWND hWnd = pCxp->hWnd; switch (message) { case WM_NCPAINT: case WM_PAINT: lReturn = (LONG) CallWindowProc(pCxp->wpPrev, hWnd, message, wParam, lParam); //lReturn = DefWindowProc(hWnd, message, wParam, lParam); ComboDrawComboBoxXP(pCxp); return lReturn; case WM_NCLBUTTONDOWN: return 0; case WM_LBUTTONDOWN: ComboOnMouseDown(pCxp); lReturn = (LONG) CallWindowProc(pCxp->wpPrev, hWnd, message, wParam, lParam); return lReturn; case WM_LBUTTONUP: pCxp->dwState &= ~CXPS_PRESSED; lReturn = (LONG) CallWindowProc(pCxp->wpPrev, hWnd, message, wParam, lParam); ComboDrawComboBoxXP(pCxp); return lReturn; //lReturn = DefWindowProc(hWnd, message, wParam, lParam); break; } // 调用原来的回调函数 lReturn = (LONG) CallWindowProc(pCxp->wpPrev, hWnd, message, wParam, lParam); if (message == WM_NCDESTROY) // 窗口销毁 DeleteClassXP(hWnd); return lReturn; } /**************以下设置必需包含在每个子类中**********************/ //尾部 #ifdef __cplusplus } #endif // __cplusplus /*****************************************************************/