//////////////////////////////////////// ////////////////////////////////////// // 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 ); } |