Free from the toolbar

zhaozj2021-02-11  208

Free from the toolbar

The engineering provided by the VC creates Wizard only provides options in the toolbar in the Doc / View structure, and how to use the toolbar for the general dialog or the normal window created by yourself?

The method of free use of the toolbar window will be described below.

Suppose we use a CMYWND window class, first we want to define a ctoolbarctrl member variable in this window: CToolbarCtrl M_Wndtoolbar;

Create a toolbar's window and define each button of the toolbar in the Window's oncreate function, and attach pictures and text information to press New. For example, we have to specify 3 button for the toolbar, and its ID is IDC_PLAY, IDC_PAUSE, IDC_STOP, we need this to do:

CMyWnd :: OnCreate (LPCREATESTRUCT lpCreateStruct) {...... // other processing if (m_ wndToolBar.Create (WS_CHILD |! WS_VISIBLE | TBSTYLE_FLAT | TBSTYLE_TOOLTIPS | CCS_NORESIZE, CRect (0, 0, 50, 20), this, // this is CWND Type Pointer IDR_TOOLBAR) containing the parent window of the toolbar) {trace0 ("failed to create toolbar / n"); return -1; // fail to create}

// Initialization Toolbar // Add a picture, specified as a button number 3, IDB_Playbox is the bitmap resource number m_wndtoolbar.addbitmap (3, IDB_PlayBox) of the toolbar;

// Add a label string. // idc_play, etc. is a string resource number m_ wndtoolbar.addstring (idc_play); m_ wndtoolbar.addstring (idc_pause); m_ wndtoolbar.addstring (IDC_Stop);

/ / Add a button to the toolbar. TBButton TBButton [3] = {{0, IDC_Play, Null, TBStyle_Button, 0, 0}, {1, IDC_Pause, Null, TBStyle_Button, 0, 1}, {2, IDC_Stop, NULL, TBSTYLE_BUTTON, 0, 2},} ;

M_WndtoolBar.AddButtons (3, TBButton);

The definition of the TBButton structure is as follows: typedef struct_tbbutton {int ionmap; // Press the index in the bitmap, in 0 is the cardinal idcommand; // press the Command ID of the New, this Command will be sent when the button is pressed. IDBYTE fsState; // Press the New Status BYTE FSSTYLE; / / Press New Style DWORD DWDATA; // User Custom Data Int istring; / / The index of the header tag string of 0 is the base.

By creating the toolbar created in the order, when the mouse is turned on, if the toolbar has a TBStyle_ToolTips property, a TTN_NeedText message will be sent to the parent window of the toolbar to obtain the string required by the TIP prompt window. Therefore, in the message handler of the parent window, this message must be in response to the corresponding string. The specific practices are as follows: Add such statements to the message mapping table of the window:

BEGIN_MESSAGE_MAP (CWndMusicFrame, CWndFrame) file: // {{AFX_MSG_MAP (CWndMusicFrame) ... .. // other message mapping ON_NOTIFY_EX_RANGE (TTN_NEEDTEXT, 0, 0xFFFF, OnToolTipText) ... .. // END_MESSAGE_MAP other message map () message handler is defined as follows : BOOL CMYWND :: ONTOOLTEXT (UINT, NMHDR * PNMHDR, LRESULT * PRESULT) {Assert (pnmhdr-> code == TTN_NeedText);

Tooltiptext * pttt = (tooltiptext *) pnmhdr; // Get the button's ID uint nid = pnmHDR-> IDFROM;

IF (PTTT-> UFLAGS & TTF_IDISHWND) NID = :: getdlgctrlid ((hwnd) NID);

If (nid) {// for its specified resource number and resource Handle, of course, you may also specify a string directly, but better habits are saved in the resource. PTTT-> LPSZTEXT = MakeintResource (NID); PTTT-> Hinst = AFXGETRESOURCEHANDLE ();

// Set the TIP window to the top window :: SetWindowPos (pnmhdr-> hwndfrom, hwnd_top, 0, 0, 0, 0, swp_noactivate | swp_nosize | swp_nomove | swp_noownerzorder);

Return True;}

* PRESULT = 0;

Return False; // Message Was Handled}

The above is an example of using a custom toolbar in a general window. On this basis, you can add more processing features and patterns for this toolbar.

A Wen http://tulipstudio.yeah.net

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

New Post(0)