The use of Win32 programming toolbar

Source: Internet
Author: User

Today using Win32 programming to create toolbar, because of this piece is not familiar, so today deliberately write, afraid later forget, there is no technical content, Daniel floated ~ ~ ~

Creating toolbar can use Createtoolbar and CreateWindowEx, because Microsoft does not advocate the use of Createtoolbar, so the latter is used here.

The CreateWindowEx needs to specify the window class as Toolbarclassname, which is directly on the code.

(1) using the standard bitmap in Commctl

HWND Createatoolbar (HWND Hwndlg)// Hwndlg as a handle to the window

{

  const int buttonnums = 2; //The number of buttons on the toolbar
Tbbutton tbb[2]; //Button
ZeroMemory (TBB, sizeof (TBB));
Tbb[0].ibitmap = std_filenew;
Tbb[0].fsstate = tbstate_enabled;
Tbb[0].fsstyle = Tbstyle_button;
Tbb[1].ibitmap = Std_redow;
Tbb[1].fsstate = tbstate_enabled;
Tbb[1].fsstyle = Tbstyle_button;

Bitmap, standard bitmap in Commctl
Tbaddbitmap Tbbitmap;
Tbbitmap.hinst = Hinst_commctrl;
Tbbitmap.nid = Idb_std_small_color;

RECT Windowrect;
GetWindowRect (Hwndparent,&windowrect);
Hwndtoolbar = CreateWindowEx (0l,toolbarclassname,null,ws_child| ws_visible| ws_border,0,0,0,0,
hWndParent, (HMENU) id_toolbar,hinst,null);
To add a bitmap to a toolbar
SendMessage (hwndtoolbar,tb_addbitmap,0, (LPARAM) &tbbitmap);
Calculate Toolbar size
SendMessage (Hwndtoolbar,tb_buttonstructsize, (WPARAM) sizeof (Tbbutton), 0);
Add a button to a toolbar
SendMessage (Hwndtoolbar,tb_addbuttons, (WPARAM) buttonnums, (LPARAM) &TBB);

return hwndtoolbar;

}

(2) the other is to use their own positioning of the bitmap (here I am a bitmap added, not a bitmap contains a lot of pictures)

BOOL Createatoolbar (HWND hwndlg)
{

HWND Htoolbar = CreateWindowEx (NULL, Toolbarclassname, "", Ws_child | ws_visible | Tbstyle_tooltips,
0, 0, 0, 0, Hwndlg,/*null*/(HMENU) 1111, hInst, NULL); Creating toolbars
Tbbutton tbb[13];
ZeroMemory (TBB, sizeof (TBB));

Himagelist hinmagelist = imagelist_create (+, Ilc_color24/*ilc_color16 | ilc_mask*/, 13, 0);//Gen-a bitmap list, 13 means I created 13 such

int ibitmap[13] = {0};
WORD id[13] = {idb_filemanage, Idb_screencontrol, Idb_cmd, Idb_keyrecord, Idb_processmanage, Idb_regedit, IDB_ Servicemanage,
Idb_windowsmanage, Idb_audiomomonitor, Idb_download, idb_fluship, idb_parameterset,idb_produceclient};

for (int i = 0; i <; i++)
{
Ibitmap[i] = Imagelist_add (Hinmagelist, LoadBitmap (HInst, Makeintresource (id[i))), 0);
}

SendMessage (Htoolbar, tb_setimagelist, 0, (LPARAM) hinmagelist); To add a bitmap to a toolbar

TCHAR *szbitmap[] = {"File management", "screen Monitor", "HyperTerminal", "Keylogger", "Process Management", "Registry Management", "Service Management", "Window Management",
"Audio and video surveillance", "Download Management", "Refresh IP", "Parameter Settings", "Create Customer"};
for (int j = 0; J <; J + +)
{
Tbb[j].ibitmap = Makelong (Ibitmap[j], 0);
Tbb[j].fsstate = tbstate_enabled;
Tbb[j].fsstyle = Tbstyle_button;
tbb[j].istring = (INT_PTR) szbitmap[j];
}


SendMessage (Htoolbar, Tb_buttonstructsize, (WPARAM) sizeof (Tbbutton), 0); Calculate Toolbar size
SendMessage (Htoolbar, tb_addbuttons, sizeof (TBB)/sizeof (Tbbutton), (LPARAM) &TBB); Add a button to a toolbar
SendMessage (Htoolbar, tb_setbuttonsize, 0, (LPARAM) Makelong (60, 60));
SendMessage (Htoolbar, tb_autosize, 0, 0); Resizing a toolbar

ShowWindow (Htoolbar, TRUE);

return TRUE;
}

The use of Win32 programming toolbar

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.