Add a true color toolbar in the dialog

xiaoxiao2021-03-06  55

Add a toolbar in the dialog, far from the document view. If you use the CToolbar class in the document view, you can't add a floating prompt as in the document. The following is a toolbar that I have prompting text made in practical applications.

Add a member variable in the class:

Ctoolbarctrl Toolbar;

When initialization dialog:

Rect Rect; Rect.top = 0; Rect.Right = 0; Rect.Right = 20; Rect.Bottom = 20; cBitmap Bitmap; cimagelist imagelist; bitmap.LoadBitmap (iDB_bitmap4); imagelist.create (16, 16, ilc_colordb | ILC_MASK, 13,1); imageList.Add (& bitmap, RGB (255,0,255)); toolbar.Create (WS_CHILD | WS_VISIBLE | CCS_TOP | TBSTYLE_TOOLTIPS | CCS_ADJUSTABLE, rect, this, 0); toolbar.SendMessage (TB_SETIMAGELIST, 0, (LPARAM) imageList.m_hImageList); imageList.Detach (); bitmap.Detach (); buttonbitmap = toolbar.AddBitmap (13, IDR_TOOLBAR1); toolbar.AddString (IDS_STRING1); int ncount = 0; for (ncount = 0; ncount <13; ncount ) {m_button [ncount] .iBitmap = buttonbitmap ncount; m_button [ncount] .idCommand = tool1 ncount; m_button [ncount] .fsState = TBSTATE_ENABLED; m_button [ncount] .fsStyle = TBSTYLE_BUTTON; m_button [ncount] .dwdata = 0; m_button [ncount] .istring = IDS_STRING1 NCOUNT;}

Toolbar.AddButtons (ncount, m_button);

This adds 13 buttons to the toolbar.

Where ToolBar.sendMessage (tb_setimagelist, 0, (lparam) imagelist.m_himagelist);

It is the 256 color tool bar (corresponding, if you need 13 buttons, you also need to manually add 13 buttons if you need 13 buttons. ) Method for changing into true color toolbar. Before this, you have to import the true color image into the project of the dialog.

Secondly, add a text prompt:

Bool CToolbardlg :: Onnotify (WParam WPARAM, LPARAM LPARAM, LRESULT * PRESULT) {

Tooltiptext * tt = (tooltiptext *) lparam;

CSTRING TIP;

Switch (tt-> hdr.code)

{

Case TTN_NEEDTEXT:

IF (tt-> hdr.idfrom) tip.loadstring (tt-> HDr.IDFROM 1000);

STRCPY (TT-> Sztext, (LPCSTR) TIP);

Break;

}

Return CDialog :: Onnotify (WPARAM, LPARAM, PRESULT);

Before you prompt the text, you need to add 13 String resources. For convenience, I put the String ID number than the ID of the corresponding toolbar button. This will create a correspondence! Almost this point, complete a dialog-based true color toolbar. However, there is a little flaw that the button on the toolbar cannot be set to a free size like a document-based toolbar button, and the button here cannot be greater than 20 x 24, otherwise some will not show it. If someone has a better way, please tell me!

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

New Post(0)