Use the true color toolbar in the dialog

xiaoxiao2021-03-06  157

CTRUETOOLBAR class (a big bird writing) has encapsulated the creation of the true color toolbar, what you need to do is to display the toolbar in the dialog, add the following code in the OnInitDialog function of the dialog

IF (! m_colortoolbar.createex (this) ||! m_colortoolbar.loadtoolbar (idR_mainframe))? {?? trace0 ("failed to create toolbar / n"); ?? Return -1; ????? // fail to ?? create} m_colorToolBar.GetToolBarCtrl () SetExtendedStyle (TBSTYLE_EX_DRAWDDARROWS);. // settings drop-down arrow style toolbar m_colorToolBar.LoadTrueColorToolBar (24, IDB_TOOLBAR_NORMAL, IDB_TOOLBAR_NORMAL, IDB_TOOLBAR_DISABLED);?? // load the true color image resource m_colorToolBar.SetButtonInfo ( 0, ID_TOOLBAR_BTN_NEW, TBSTYLE_BUTTON | TBSTYLE_DROPDOWN, 0); // set the first button on the toolbar (ID_TOOLBAR_BTN_NEW) drop-down arrow, and finally a picture parameter specifies the number buttons CRect rcClient; CRect rcChild; RepositionBars (AFX_IDW_CONTROLBAR_FIRST, AFX_IDW_CONTROLBAR_LAST??? , 0, reposquery, rcclient,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; > GetWindowRect (rcchild); rcclient.top = rcchild.height () -2;? Rcclient.bottom = rcclient.top 32;? Rcclient.LEFT = 5;? M_colortoolbar.movewindow (rcclient, false); / / Move the toolbar to any location you want to place and display

Appendix: CTRUETOOLBAR class realizes code

/ *** ======================================================================================================================================================================== =============================== ???????????????????? ?????????????????????????????????????????? = ======= ????????????????? DCU TILITY ???????? ????????? ======== ????????????????????????? ????????????????????????????????????? =============== ============================================================================================================================================================================================================= ==================== ??????????????????????????????? ??????????????????????????????????????? ======== ??? file Name ??????????:? TrueColorToolbar.h ??????????????????????? ========??? Project Name ???????:? Tester ??????????????????????????? === ===== ??? Project Number ?????:? --- ???????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????? ???????? ======== ??? creeation date ??????:? 13/1/2003 ???????????????? ????????????????? ======== ??? author (s) ??????????:? Dany Cantin ????? ?????????????????????????? =======

= ??????????????????????????????????????????? ???????????????????? ======== ????????????????? CopyRight? DCUTILITY? 2003? ??????????????????????? ======== ????????????????????? ?????????????????????????????????????????? == ============================================================================================================================================================================================================= ============================================================================================================================================================================================================= ============================================================================================================================================================================================================= ==== * / # ifndef truecolortoolbar_h_ # define truecolortoolbar_h_

#if _MSC_VER> 1000 # prgma overce # endif //_MSC_VER> 1000

#include

/// CtrueColorToolbar

Class CtrueColorToolbar: Public CToolbar {// Constructionpublic:? CtrueColorToolbar ();

// attributesprivate:? BOOL M_BDROPDOWN;

? Struct stdropdownfo {? public: ?? uint? uinttonid; ?? uint? umenuid; ?? cwnd * pparent;?}; ?? carray

m_lstdropdownbutton;

?

// Operations

PUBLIC:

Bool Loadtruecolortoolbar (int? Nbtnwidth,

???????? uint utoolbar,

???????? uint utoolbarhot ?? = 0,

???????? uint utoolbardisabled = 0);

Void AddDropDownButton (CWND * PParent, Uint UbuttonID, UINT UMENUID);

PRIVATE:? BOOL settruecolortoolbar (uint utoolbartype, ???????????????????????? uint utoolbar, ?????????? INT? nbtnwidth); / / OVERRIDES? // ClassWizard generated Virtual function overrides? // {{AFX_VIRTUAL (CTRUECOLORTOOLBAR)? //}} AFX_VIRTUAL

// ImplementationPublic:? Virtual ~ ctrueColortoolbar ();

? // generated message map functionsprotace:? // {AFX_MSG (CTRUECOLORTOOLBAR)? AFX_MSG Void ONTOOLBARDROPDOWN (NMToolbar * PNMH, LRESULT * PLRES);? //}} AFX_MSG

Declare_MESSAGE_MAP ()};

/

// {{AFX_INSERT_LOCATION}} // Microsoft Visual C Will Insert Additional Declarations Immediately Before The Previous Line.

#ENDIF / / TRUECOLORTOOLBAR_H_H_H_

/ *** ======================================================================================================================================================================== =============================== ???????????????????? ?????????????????????????????????????????? = ======= ????????????????? DCU TILITY ???????? ????????? ======== ????????????????????????? ????????????????????????????????????? =============== ============================================================================================================================================================================================================= ==================== ??????????????????????????????? ??????????????????????????????????????? ======== ??? file Name ???????????:? TrueColorToolbar.cpp ?????????????????????? ======== ??? Project Name ???????:? Tester ??????????????????????????? ===== === ??? Project Number ?????:? --- ???????????????????????? ?????? ======== ??? creeation date ??????:? 13/1/2003 ??????????????????? ?????????????? ======== ??? author (s) ??????????:? Dany Cantin ??????? ??????????????????????? =======

= ??????????????????????????????????????????? ???????????????????? ======== ????????????????? CopyRight? DCUTILITY? 2003? ??????????????????????? ======== ????????????????????? ?????????????????????????????????????????? == ============================================================================================================================================================================================================= ============================================================================================================================================================================================================= ============================================================================================================================================================================================================= ==== * / # include "stdafx.h" #include "truecolortoolbar.h"

#ifdef _debug # define new debug_new # undef this_filestatic char this_file [] = __file __; # ENDIF

/// CtrueColorToolbar

CTRUECOLORTOOLBAR :: CTRUECOLORTOOLBAR () {? M_bdropdown = false;}

CTRUECOLORTOOLBAR :: ~ ctruecolortoolbar () {}

BEGIN_MESSAGE_MAP (CTrueColorToolBar, CToolBar)? // {{AFX_MSG_MAP (CTrueColorToolBar)? ON_NOTIFY_REFLECT (TBN_DROPDOWN, OnToolbarDropDown)? //}} AFX_MSG_MAPEND_MESSAGE_MAP ()

/// CTRUECOLORTOOLBAR MESSAGE HANDLERSBOOL CTRUECOLORTOOLBAR :: LoadTrueColorToolbar (int? Nbtnwidth, ??????????? uint utoolbar, ??????????? uint utoolbarhot, ??????? ? ???? UINT uToolBarDisabled) {if (! SetTrueColorToolBar (TB_SETIMAGELIST, uToolBar, nBtnWidth)) ?? return FALSE; ?? if (! uToolBarHot) {?? if (SetTrueColorToolBar (TB_SETHOTIMAGELIST, uToolBarHot, nBtnWidth)) ??? RETURN FALSE;?}? if (utoolbardisabled) {?? if (! settruecolortoolbar (tb_setdisabledimagelist, utoolbardisabled, nbtnwidth) ??? Return False ;?}

Return True;}

Bool CtrueColorToolbar :: settruecolortoolbar (uint utoolbartype, ??????????????????? uint utoolbar, ????????????? Int? Nbtnwidth) {? CIMAGELIST? CIMAGELIST;? CBITMAP ?? cbitmap;? Bitmap ?? Bmbitmap; ?? IF (! AfxgetResourceHandle (), makeintresource (uToolbar), ????????? Image_bitmap, 0, 0 , ????????? lr_defaultsize | lr_createdibsection) || ????! Cbitmap.getbitmap (& Bmbitmap))?

? Csize ?? csize (bmbitmap.bmheight);? Int ??? nnbbtn? = Csize.cx/nbtnwidth;?rgbtriple*?rgb??= (bmbitmap.bmbits) ;? Colorref? RGBMASK? = RGB (RGB [0] .RGBTRED, RGB [0] .RGBTGREEN, RGB [0] .RGBTBLUE); ?? IF (! cimelist.create (nbtnwidth, csize.cy, ilc_color24 | ilc_mask, nnbbtn, 0) Return False; ?? IF (Cimagelist.Add (& CBitmap, RGBMASK) == -1) ?? Return False;

? SendMessage (Utoolbartype, 0, (LPARAM) CIMAGELIST.M_HIMAGELIST) ;? CIMAGELIST.DETACH ();? Cbitmap.detach (); ?? Return True;}

void CTrueColorToolBar :: AddDropDownButton (CWnd * pParent, UINT uButtonID, UINT uMenuID) {if (m_bDropDown!) {?? GetToolBarCtrl () SendMessage (TB_SETEXTENDEDSTYLE, 0, (LPARAM) TBSTYLE_EX_DRAWDDARROWS);?. ?? m_bDropDown = TRUE ;?}

• setButtonStyle (CommandToIndex (UbuttonID), TBStyle_Dropdown;

? StDropDownInfo DropDownInfo;? DropDownInfo.pParent = pParent;?? DropDownInfo.uButtonID = uButtonID;?? DropDownInfo.uMenuID = uMenuID;?? M_lstDropDownButton.Add (DropDownInfo);} void CTrueColorToolBar :: OnToolbarDropDown (NMTOOLBAR * pnmtb, LRESULT * plr {? for (int i = 0; i

?? if (DropDownInfo.ubuttonId == uint (pnmtb-> iItem)) {

??? cmenu menu; ??? menu.loadmenu (DropdownInfo.uMenu); ??? cmenu * ppopup = menu.getsubmenu (0); ?????? CRECT RC; ??? SendMessage (TB_GETRECT, (WPARAM PNMTB-> IIIM, (LPARAM) & rc); ??? ClientToscreen (& RC); ?????? ppopup-> TRACKPOPUPMENU (TPM_LEFTALIGN | TPM_LEFTBUTTON | TPM_VERTICAL, ??????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????? ????????? rc.left, rc.bottom, dropdowninfo.pparent, & rc); ??? Break; ??}?}}

转载请注明原文地址:https://www.9cbs.com/read-128417.html

New Post(0)