Open notepad, open any common software, and almost use the toolbar and taskbar. Is it mysterious? No at all. Come with me and work together.
Because Resource edit cannot be used for painting, to implement these two controls, you need to reference the <commctrl. h> header file and Its Dynamic Connection Library to manually create
First, add the header file, load the dynamic Connection Library # pragma comment (Lib, "comctl32.lib"), and then register the Common Control
Typedef struct taginitcommoncontrolsex
{
DWORD dwsize;
DWORD dwicc;
} Initcommoncontrolsex, * lpinitcommoncontrolsex;
Dwsize = sizoef (initcommoncontrolsex) indicates the size of the struct,
Dwicc is the control type to be loaded from the DLL. We need icc_bar_classes, including toolbar, status bar, trackbar, and tooltip.
Then, initialize
Initcommoncontrolsex initctrlex;
Initcommoncontrolsex (& initctrlex );
Create a toolbar and a taskbar.
// Create a status bar
Hwnd hstatusbar;
Hstatusbar = createincluwex (0l, // extended styles
Statusclassname, // Status Bar
Null, // No text
Ws_child | ws_visible, // styles
0, 0, 0, 0, // X, Y, CX, Cy
Hwnd, // parent window
(Hmenu) 100, // window ID
Hinst, // instance
Null); // window data
If (hstatusbar = NULL)
{
MessageBox (hwnd, l "status bar not created! ", Null, mb_iconerror );
Return false;
}
// Create a toolbar
Const int numbuttons = 3; // Number of buttons on the toolbar
Tchar caption [40] = {0 };
Hwnd htoolbar;
Tbbutton TBB [] = {
{0, idm_exit, tbstate_enabled, tbstyle_button, 0l, 0 },
{0, 0, tbstate_enabled, tbstyle_sep, 0l,-1 },
{1, idm_about, tbstate_enabled, tbstyle_button, 0l, 0}
};
/* Tbbuton is a struct that contains information about buttons on the toolbar.
Typedef struct _ tbbutton
{
Int ibitmap;
Int idcommand;
Byte fsstate;
Byte fsstyle;
# Ifdef _ win64
Byte breserved [6] // padding for alignment
# Elif defined (_ Win32)
Byte breserved [2] // padding for alignment
# Endif
Dword_ptr dwdata;
Int_ptr istring;
} Tbbutton, near * ptbbutton * lptbbutton;
Where,
Ibitmap (zero-based index of the button image ),
Idcommand (command identifier associated with the button ),
Fsstate (Button state flags ),
Fsstyle (button style ),
Dwdata (application-defined value ),
Istring (zero-based index of the button string, or a pointer to a string buffer that contains text for the button .)
*/
Tbaddbitmap tbbitamps;
Tbbitamps. hinst = hinst; // current instance
Tbbitamps. nid = idb_bitmap_standard;
// Add an image to the toolbar
Htoolbar = createextenwex (0l, // No extended styles
Toolbarclassname, // Status Bar
Null, // No text
Ws_child | ws_visible, // styles
16, 16, 16, 16, // X, Y, CX, Cy
Hwnd, // parent window
(Hmenu) 101, // window ID
Hinst, // instance
Null); // window data
If (htoolbar = NULL)
{
MessageBox (hwnd, l "tool bar not created! ", Null, mb_iconerror );
Return false;
}
Sendmessage (htoolbar, tb_addbitmap, 0, (lparam) & tbbitamps); // Add an image to the toolbar
Sendmessage (htoolbar, tb_buttonstructsize, (wparam) sizeof (tbbutton), 0); // calculate the toolbar size
Sendmessage (htoolbar, tb_addbuttons, (wparam) 3, (lparam) (lptbbutton) & TBB); // Add the button to the toolbar
There is also a convenient method, but Microsoft does not advocate Calling API functions.
Hwnd createmedilbarex (
Hwnd,
Dword ws,
Uint WID,
Int nbitmaps,
Hinstance hbminst,
Uint_ptr wbmid,
Lpctbbutton lpbuttons,
Int inumbuttons,
Int dxbutton,
Int dybutton,
Int dxbitmap,
Int dybitmap,
Uint ustructsize
);
For details, refer to msdn.