|
Creating a Toolbar
The following example uses the CreateWindowEx function to create a toolbar that the user can customize and that has a
tooltip control associated with it. The example uses the TB_ADDBITMAP and TB_ADDSTRING messages to add button images and buttons strings to the toolbar. The example
also adds three buttons by using the TB_ADDBUTTONS message.
// CreateAToolBar - creates a toolbar and adds the initial set of
// buttons to it.
// Returns the handle of the toolbar if successful or NULL otherwise.
// hwndParent - handle of the parent window
HWND CreateAToolBar(HWND hwndParent)
{
HWND hwndTB;
TBADDBITMAP tbab;
TBBUTTON tbb[3];
char szBuf[16];
int iCut, iCopy, iPaste;
// Ensure that the common control DLL is loaded.
InitCommonControls();
// Create a toolbar that the user can customize and that has a
// tooltip associated with it.
hwndTB = CreateWindowEx(0, TOOLBARCLASSNAME, (LPSTR) NULL,
WS_CHILD | TBSTYLE_TOOLTIPS | CCS_ADJUSTABLE,
0, 0, 0, 0, hwndParent, (HMENU) ID_TOOLBAR, g_hinst, NULL);
// Send the TB_BUTTONSTRUCTSIZE message, which is required for
// backward compatibility.
SendMessage(hwndTB, TB_BUTTONSTRUCTSIZE,
(WPARAM) sizeof(TBBUTTON), 0);
// Add the bitmap containing button images to the toolbar.
tbab.hInst = g_hinst;
tbab.nID = IDB_BUTTONS;
SendMessage(hwndTB, TB_ADDBITMAP, (WPARAM) NUM_BUTTON_BITMAPS,
(WPARAM) &tbab);
// Add the button strings to the toolbar.
LoadString(g_hinst, IDS_CUT, (LPSTR) &szBuf, MAX_LEN);
iCut = SendMessage(hwndTB, TB_ADDSTRING, 0, (LPARAM) (LPSTR) szBuf);
LoadString(g_hinst, IDS_COPY, (LPSTR) &szBuf, MAX_LEN);
iCopy = SendMessage(hwndTB, TB_ADDSTRING, (WPARAM) 0,
(LPARAM) (LPSTR) szBuf);
LoadString(g_hinst, IDS_PASTE, (LPSTR) &szBuf, MAX_LEN);
iPaste = SendMessage(hwndTB, TB_ADDSTRING, (WPARAM) 0,
(LPARAM) (LPSTR) szBuf);
// Fill the TBBUTTON array with button information, and add the
// buttons to the toolbar.
tbb[0].iBitmap = BMP_CUT;
tbb[0].idCommand = IDM_CUT;
tbb[0].fsState = TBSTATE_ENABLED;
tbb[0].fsStyle = TBSTYLE_BUTTON;
tbb[0].dwData = 0;
tbb[0].iString = iCut;
tbb[1].iBitmap = BMP_COPY;
tbb[1].idCommand = IDM_COPY;
tbb[1].fsState = TBSTATE_ENABLED;
tbb[1].fsStyle = TBSTYLE_BUTTON;
tbb[1].dwData = 0;
tbb[1].iString = iCopy;
tbb[2].iBitmap = BMP_PASTE;
tbb[2].idCommand = IDM_PASTE;
tbb[2].fsState = TBSTATE_ENABLED;
tbb[2].fsStyle = TBSTYLE_BUTTON;
tbb[2].dwData = 0;
tbb[2].iString = iPaste;
SendMessage(hwndTB, TB_ADDBUTTONS, (WPARAM) NUM_BUTTONS,
(LPARAM) (LPTBBUTTON) &tbb);
ShowWindow(hwndTB, SW_SHOW);
return hwndTB;
}
| Last news from Greatis Software |
 |
|
Nostalgia .Net |
|
.Net is powerful, but not all-powerful, so sometimes we need to use Win32 API for our .Net applications. It's simple enough with Platform Invoke if you have Win32 skill, but we do not always have time to dig the ancient documentation, declare the special types that are compatible with Win32, find the values of the Win32's constants and so on. Nostalgia .Net offers several simple-to-use classes, and components that will allow you to forget about the headache of Win32 and just use the power of Win32 in your application the same way as you use the native. Net classes. More » |
| Recommended software for developers |
 |
|
Ultimate Pack |
|
Component pack for Delphi and C++ Builder that contains runtime form designer, runtime object inspector, print suite and much more for the very special price. More » |
 |
|
Form Designer .Net |
|
Unique runtime form design solution that allows to edit any form in .Net WinForms application at runtime with full source codes for only 300 euro! More » |
 |
|
Print Suite .Net |
|
Print Suite .Net is a set of components for easy printing texts, images and grids from your WinForms applications. Full C# source codes are available More » |
 |
|
Gradient Controls .Net |
|
Gradient Controls .Net offers controls with gradient background feature. Labels, panels and so on... Full C# source codes are available More » |
 |
|
Greatis iGrid |
|
iGrid plots drawing grid right over your desktop, so you can use it everywhere, with any drawing application without any special plugins for different graphic editors. More » |
All the contacts and projectsDmitry Vasiliev (just.dmitry)
Related LinksSoftware for Visual Studio .NET developers Software for Delphi and C++ Builder developers Software for Visual Basic 6 developers Delphi Tips&Tricks MegaDetailed.NET More Online Helps Win32 Programmer's Reference Win32 Multimedia Programmer's Reference OLE Programmer's Reference Microsoft Windows Pen API Programmer's Reference Microsoft Windows Sockets 2 Reference Microsoft Windows Telephony API (TAPI) Programmer's Reference Unix Manual Pages
|