//////////////////////////////////////// //////////// // FlatComboBox. h: header file # If! Defined (FLATCOMBOBOX_H_INCLUDED) # Define FLATCOMBOBOX_H_INCLUDED # If _ MSC_VER> 1000 # Pragma once # Endif // _ MSC_VER> 1000 # Define FC_DRAWNORMAL 0x00000001 # Define FC_DRAWRAISED 0x00000002 # Define FC_DRAWPRESSD 0x00000004// CFlatComboBox window Class CFlatComboBox: public CComboBox { // Construction Public: CFlatComboBox (); // Attributes Public: Bool m_bLBtnDown; COLORREF m_clrHilite; COLORREF m_clrShadow; COLORREF m_clrDkShad; COLORREF m_clrButton; // Operations Public: Void DrawCombo (DWORD dwStyle, COLORREF clrTopLeft, COLORREF clrBottomRight ); Int Offset (); // Overrides // ClassWizard generated virtual function overrides // {AFX_VIRTUAL (CFlatComboBox) //} AFX_VIRTUAL // Implementation Public: Virtual ~ Cflatcombobox (); // Generated message map Functions Protected: // {Afx_msg (cflatcombobox) Afx_msg void onmousemove (uint nflags, cpoint point ); Afx_msg void onlbuttondown (uint nflags, cpoint point ); Afx_msg void onlbuttonup (uint nflags, cpoint point ); Afx_msg void ontimer (uint nidevent ); Afx_msg void onpaint (); //} Afx_msg Declare_message_map () }; # Endif //! Defined (flatcombobox_h_included) //////////////////////////////////////// /// # Include "stdafx. H" # Include "flatcombobox. H" # Ifdef _ debug # Define new debug_new # UNDEF this_file Static char this_file [] = _ file __; # Endif //// // CFlatComboBox CFlatComboBox: CFlatComboBox () { M_bLBtnDown = false; } CFlatComboBox ::~ CFlatComboBox () {} BEGIN_MESSAGE_MAP (CFlatComboBox, CComboBox) // {AFX_MSG_MAP (CFlatComboBox) ON_WM_MOUSEMOVE () ON_WM_LBUTTONDOWN () ON_WM_LBUTTONUP () ON_WM_TIMER () ON_WM_PAINT () //} AFX_MSG_MAP END_MESSAGE_MAP () /// // CFlatComboBox message handlers Void CFlatComboBox: OnMouseMove (UINT nFlags, CPoint point) { SetTimer (1, 10, NULL ); CComboBox: OnMouseMove (nFlags, point ); } Void CFlatComboBox: OnLButtonDown (UINT nFlags, CPoint point) { M_bLBtnDown = true; CComboBox: OnLButtonDown (nFlags, point ); } Void CFlatComboBox: OnLButtonUp (UINT nFlags, CPoint point) { M_bLBtnDown = false; Invalidate (); CComboBox: OnLButtonUp (nFlags, point ); } Void CFlatComboBox: OnTimer (UINT nIDEvent) { POINT pt; GetCursorPos (& pt ); CRect rcItem; GetWindowRect (& rcItem ); Static bool bPainted = false; // OnLButtonDown, show pressed. If (m_bLBtnDown = true ){ KillTimer (1 ); If (bPainted = true ){ DrawCombo (FC_DRAWPRESSD,: GetSysColor (COLOR_BTNSHADOW),: GetSysColor (COLOR_BTNHIGHLIGHT )); BPainted = false; } Return; } // If mouse leaves, show flat. If (! Rcitem. ptinrect (PT )){ Killtimer (1 ); If (bpainted = true ){ Drawcombo (fc_drawnormal,: getsyscolor (color_btnface),: getsyscolor (color_btnface )); Bpainted = false; } Return; } // On mouse over, show raised. Else { If (bpainted = true) Return; Else { Bpainted = true; Drawcombo (fc_drawraised,: getsyscolor (color_btnshadow),: getsyscolor (color_btnhighlight )); } } Ccombobox: ontimer (nidevent ); } Void cflatcombobox: onpaint () { Default (); Drawcombo (fc_drawnormal,: getsyscolor (color_btnface),: getsyscolor (color_btnface )); } Void cflatcombobox: drawcombo (DWORD dwstyle, colorref clrtopleft, Colorref clrbottomright) { Crect rcitem; Getclientrect (& rcitem ); CDC * PDC = getdc (); // Cover up dark 3D shadow. PDC-> draw3drect (rcitem, clrtopleft, clrbottomright ); Rcitem. deflaterect (1, 1 ); If (! Iswindowenabled ()){ PDC-> draw3drect (rcitem,: getsyscolor (color_btnhighlight),: getsyscolor (color_btnhighlight )); } Else { PDC-> draw3drect (rcitem,: getsyscolor (color_btnface),: getsyscolor (color_btnface )); } // Cover up dark 3D shadow on drop arrow. Rcitem. deflaterect (1, 1 ); RcItem. left = rcItem. right-Offset (); PDC-> Draw3dRect (rcItem,: GetSysColor (COLOR_BTNFACE ), : GetSysColor (COLOR_BTNFACE )); // Cover up normal 3D shadow on drop arrow. RcItem. DeflateRect (1, 1 ); PDC-> Draw3dRect (rcItem,: GetSysColor (COLOR_BTNFACE ), : GetSysColor (COLOR_BTNFACE )); If (! IsWindowEnabled ()){ Return; } Switch (dwStyle) { Case FC_DRAWNORMAL: RcItem. top-= 1; RcItem. bottom + = 1; PDC-> Draw3dRect (rcItem,: GetSysColor (COLOR_BTNHIGHLIGHT),: GetSysColor (COLOR_BTNHIGHLIGHT )); RcItem. left-= 1; PDC-> Draw3dRect (rcItem,: GetSysColor (COLOR_BTNHIGHLIGHT),: GetSysColor (COLOR_BTNHIGHLIGHT )); Break; Case FC_DRAWRAISED: RcItem. top-= 1; RcItem. bottom + = 1; PDC-> Draw3dRect (rcItem,: GetSysColor (COLOR_BTNHIGHLIGHT),: GetSysColor (COLOR_BTNSHADOW )); Break; Case FC_DRAWPRESSD: RcItem. top-= 1; RcItem. bottom + = 1; RcItem. OffsetRect (1, 1 ); PDC-> Draw3dRect (rcItem,: GetSysColor (COLOR_BTNSHADOW),: GetSysColor (COLOR_BTNHIGHLIGHT )); Break; } ReleaseDC (pDC ); } Int CFlatComboBox: Offset () { // Thanks to Todd Brannam for this suggestion... Return: GetSystemMetrics (SM_CXHTHUMB ); } /// // MainToolBar. h: interface for the CMainToolBar class. # If! Defined (afx_maintoolbar_h000076cf28f4_005f_11d7_8f58_00e04c0bece600000000ded _) # Define afx_maintoolbar_h000076cf28f4_005f_11d7_8f58_00e04c0bece600000000ded _ # If _ MSC_VER> 1000 # Pragma once # Endif // _ MSC_VER> 1000 # Include "FlatComboBox. h" Class CMainToolBar: public CToolBar { Public: CMainToolBar (); Virtual ~ CMainToolBar (); Public: CFlatComboBox m_wndZoom; }; # Endif ///// // MainToolBar. cpp: implementation of the CMainToolBar class. # Include "stdafx. h" # Include "ToolBar. h" # Include "MainToolBar. h" # Ifdef _ DEBUG # Undef THIS_FILE Static char THIS_FILE [] =__ FILE __; # Define new DEBUG_NEW # Endif CMainToolBar: CMainToolBar () {} CMainToolBar ::~ CMainToolBar () {} //////////////////////////////////////// //////////////////// Int CMainFrame: OnCreate (maid) { If (CFrameWnd: OnCreate (lpCreateStruct) =-1) Return-1; If (! M_wndToolBar.CreateEx (this, TBSTYLE_FLAT, WS_CHILD | WS_VISIBLE | CBRS_TOP | CBRS_GRIPPER | CBRS_TOOLTIPS | CBRS_FLYBY | CBRS_SIZE_DYNAMIC) |! M_wndToolBar.LoadToolBar (IDR_MAINFRAME )) { TRACE0 ("Failed to create toolbar/n "); Return-1; // fail to create } If (! M_wndStatusBar.Create (this) |! M_wndStatusBar.SetIndicators (indicators, Sizeof (indicators)/sizeof (uint ))) { Trace0 ("failed to create status bar/N "); Return-1; // fail to create } // Todo: delete these three lines if you don't want the toolbar to be dockable M_wndtoolbar.enabledocking (cbrs_align_any ); Enabledocking (cbrs_align_any ); Dockcontrolbar (& m_wndtoolbar ); Int Index = 0; Rect; // Find the specified tool item While (m_wndtoolbar.getitemid (INDEX )! = Id_tool_zoom) Index ++; // Set the width of the specified tool item and obtain that the new area 80 is the width. M_wndtoolbar.setbuttoninfo (index, id_tool_zoom, tbbs_separator, 80 ); M_wndtoolbar.getitemrect (index, & rect ); // Set the location Rect. Top + = 2; Rect. Bottom + = 200; // Create and display If (! M_wndToolBar.m_wndZoom.Create (WS_CHILD | WS_VISIBLE | CBS_AUTOHSCROLL | CBS_DROPDOWNLIST | CBS_HASSTRINGS, rect, & m_wndToolBar, ID_TOOL_ZOOM )) { TRACE0 ("Failed to create combo-box/n "); Return FALSE; } M_wndToolBar.m_wndZoom.ShowWindow (SW_SHOW ); // Fill in the content M_wndToolBar.m_wndZoom.AddString ("25% "); M_wndToolBar.m_wndZoom.AddString ("50% "); M_wndToolBar.m_wndZoom.AddString ("75% "); M_wndToolBar.m_wndZoom.AddString ("100% "); M_wndToolBar.m_wndZoom.AddString ("125% "); M_wndToolBar.m_wndZoom.AddString ("150% "); M_wndToolBar.m_wndZoom.AddString ("175% "); M_wndToolBar.m_wndZoom.AddString ("200% "); M_wndToolBar.m_wndZoom.SetCurSel (3 ); Return 0; } Void CMainFrame: OnSelectZoomed () { CString strContent; M_wndToolBar.m_wndZoom.GetWindowText (strContent ); AfxMessageBox (strContent ); } |