// CheckBoxExt.cpp: implementation of the CCheckBoxExt class. // ////////////////////////////////////////////////////////////////////// #include "stdafx.h" #include "CheckBoxExt.h" #include "library.h" #ifdef _DEBUG #undef THIS_FILE static char THIS_FILE[]=__FILE__; #define new DEBUG_NEW #endif WNDPROC CCheckBoxExt::m_cWndProc = NULL; int CCheckBoxExt::pos =0; ////////////////////////////////////////////////////////////////////// // Construction/Destruction ////////////////////////////////////////////////////////////////////// LRESULT CCheckBoxExt::DefWindowProc( HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam ) { CWnd *pWnd = NULL; CPoint point; LRESULT lReturn; TRACKMOUSEEVENT Tme; pos=FindPos((DWORD)hWnd, g_wndstatelist); pos++; pWnd = CWnd::FromHandle( hWnd ); switch( message ) { case WM_ERASEBKGND: return 1; case WM_NCPAINT: case WM_PAINT: CallWindowProc( m_cWndProc, hWnd, message, wParam, lParam ); OnPaint( pWnd ); return 1; case BM_SETSTYLE: // 按钮风格改变 CXPM_SETSTATE(g_wndstatelist.ElementAt (pos), CXPS_DEFAULT, wParam & BS_DEFPUSHBUTTON); OnPaint( pWnd ); break; case BM_SETSTATE: // 设置按钮状态 lReturn = (LONG) CallWindowProc( m_cWndProc, hWnd, message, wParam, lParam ); CXPM_SETSTATE(g_wndstatelist.ElementAt (pos), CXPS_PRESSED, wParam); OnPaint( pWnd ); return lReturn; case BM_SETCHECK: // 设置选中状态 lReturn = (LONG) CallWindowProc( m_cWndProc, hWnd, message, wParam, lParam ); CXPM_SETSTATE(g_wndstatelist.ElementAt (pos), CXPS_CHECKED, (wParam == BST_CHECKED)); CXPM_SETSTATE(g_wndstatelist.ElementAt (pos), CXPS_INDETERMINATE, (wParam == BST_INDETERMINATE)); OnPaint( pWnd ); return lReturn; case WM_SETTEXT: // 设置窗口文本 lReturn = (LONG) CallWindowProc( m_cWndProc, hWnd, message, wParam, lParam ); OnPaint( pWnd ); return lReturn; case WM_MOUSELEAVE: // 鼠标移出 if (g_wndstatelist.ElementAt (pos) & CXPS_HOTLIGHT) { g_wndstatelist.ElementAt (pos) &= ~CXPS_HOTLIGHT; } if (g_wndstatelist.ElementAt (pos) & CXPS_PRESSED) { g_wndstatelist.ElementAt (pos) &= ~CXPS_PRESSED; } OnPaint( pWnd ); return 0; case WM_MOUSEMOVE: // 窗口移动 if (((g_wndstatelist.ElementAt (pos) & CXPS_HOTLIGHT) == 0) && ((wParam & MK_LBUTTON) == 0)) { g_wndstatelist.ElementAt (pos) |= CXPS_HOTLIGHT; OnPaint( pWnd ); // 追踪鼠标移出消息一次 Tme.cbSize = sizeof(TRACKMOUSEEVENT); Tme.dwFlags = TME_LEAVE; Tme.hwndTrack = hWnd; _TrackMouseEvent(&Tme); } break; case WM_ENABLE: // 窗口被设置为禁用或可用 CXPM_SETSTATE(g_wndstatelist.ElementAt (pos), CXPS_DISABLED, !wParam); pWnd->Invalidate (); return FALSE; OnPaint( pWnd ); break; case WM_DESTROY: { g_wndstatelist.RemoveAt(pos); g_wndstatelist.RemoveAt(pos-1); break; } default: break; } return CallWindowProc( m_cWndProc, hWnd, message, wParam, lParam ); } void CCheckBoxExt::OnPaint( CWnd *pWnd ) { int i; RECT Rect, rcText; MEMDCXP Mdcxp; HANDLE hHandle; char szTemp[256]; COLORREF crColor; DWORD dwStyle; HDC hDC; // 获取内存兼容设备场景 Mdcxp.hWnd = pWnd->GetSafeHwnd (); Mdcxp.bTransfer = FALSE; Mdcxp.hBitmap = NULL; g_bDrawBk=1; GetMemDCXP(&Mdcxp); hDC = Mdcxp.hMemDC; // 获取窗口大小 GetWindowRect( pWnd->GetSafeHwnd (), &Rect); Rect.right -= Rect.left; Rect.bottom -= Rect.top; Rect.left = Rect.top = 0; // 填充背景 g_crDialogbkColor // hHandle = CreateSolidBrush(g_crDialogbkColor); // FillRect(hDC,&Rect, (HBRUSH)hHandle); // DeleteObject(hHandle); //按显示模式调整位置 dwStyle = GetWindowLong(pWnd->GetSafeHwnd (), GWL_STYLE); if (Rect.bottom > 13) { Rect.top = (Rect.bottom - 13)/2; Rect.bottom = Rect.top + 13; } if (dwStyle & BS_LEFTTEXT) { rcText = Rect; rcText.right -= 17; Rect.left = Rect.right - 13; } else { rcText = Rect; rcText.left += 17; Rect.left = 0; Rect.right = 13; } // 画最外面的框 FrameRect(Mdcxp.hMemDC, &Rect, (HBRUSH) g_frameedgebrush); // 画热点框渐变背景 InflateRect(&Rect, -1, -1); if (!(g_wndstatelist.ElementAt (pos) & CXPS_DISABLED)) { if (g_wndstatelist.ElementAt (pos) & CXPS_PRESSED) i = 0; else if (g_wndstatelist.ElementAt (pos) & CXPS_HOTLIGHT) i = 1; else i = 2; GradientRectXP(hDC, &Rect, gChecks_crGradientXP[i]); } // 画内框 InflateRect(&Rect, -2, -2); if ((g_wndstatelist.ElementAt (pos) & CXPS_INDETERMINATE) || ((g_wndstatelist.ElementAt (pos) & CXPS_HOTLIGHT) && (!(g_wndstatelist.ElementAt (pos) & CXPS_PRESSED)))) { if (g_wndstatelist.ElementAt (pos) & CXPS_INDETERMINATE) { if (g_wndstatelist.ElementAt (pos) & CXPS_DISABLED) crColor = 0x00BDCBCE; else if (g_wndstatelist.ElementAt (pos) & CXPS_PRESSED) crColor = 0x00188A18; else if (g_wndstatelist.ElementAt (pos) & CXPS_HOTLIGHT) crColor = 0x0021A221; else crColor = 0x0073C373; } else if (g_wndstatelist.ElementAt (pos) & CXPS_CHECKED) crColor = 0x00F7F7F7; else crColor = 0x00E7E7E7; hHandle = (HANDLE) CreateSolidBrush(crColor); FillRect(hDC, &Rect, (HBRUSH) hHandle); DeleteObject((HGDIOBJ) hHandle); } // 画框内选中标志 if (g_wndstatelist.ElementAt (pos) & CXPS_CHECKED) { hHandle = (HANDLE) SelectObject(hDC,CreatePen(PS_SOLID, 1, 0x0021A221)); for (i = 3; i < 10; i++) { MoveToEx(hDC, Rect.left+i-3, Rect.top + ((i < 6) ? i - 1 : (9 - i)), NULL); LineTo(hDC, Rect.left+i-3, Rect.top + ((i < 6) ? i + 2 : (12 - i))); } DeleteObject(SelectObject(hDC,(HGDIOBJ) hHandle)); } // 写文字 if (GetWindowText(pWnd->GetSafeHwnd (), szTemp, sizeof(szTemp))) { SetBkColor(hDC, g_crDialogbkColor); SetTextColor(hDC, GetSysColor((g_wndstatelist.ElementAt (pos) & CXPS_DISABLED) ? COLOR_GRAYTEXT: COLOR_BTNTEXT)); hHandle = (HANDLE) SelectObject(hDC, (HGDIOBJ) SendMessage(pWnd->GetSafeHwnd (), WM_GETFONT, 0, 0)); rcText.bottom = rcText.top + 1 + DrawText(hDC, szTemp, -1, &rcText, DT_CALCRECT | DT_SINGLELINE | DT_VCENTER); DrawText(hDC, szTemp, -1, &rcText, DT_SINGLELINE | DT_VCENTER); SelectObject(hDC, (HGDIOBJ) hHandle); } Mdcxp.bTransfer = TRUE; ReleaseMemDCXP(&Mdcxp); }