Basic programming of the toolbar

xiaoxiao2021-03-05  44

// Define a control ID

#define idc_main_toolbar 1001

#include // Reference General Control Liber

// Load ComctL32.dll in _twinmain ()

INITCOMMONCONTROLS ();

// Create a toolbar at the WM_CREATE message.

HWND HWNDTOOLBAR; TBBUTTON TBB [3]; TBADDBITMAP TBAB;

Case wm_create: hwndtoolbar = CreateWindowex (0, ToolbarclassName, Null, WS_CHILD | WS_VISIBLE, 0, 0, 0, 0, HWND, (HMENU) IDC_MAIN_TOOLBAR, HINST, NULL

// send the TB_ButtonstructSize Message, Which is Required for // Backward Compatibility. SendMessage (Hwndtoolbar, Tb_ButtonStructSize, (WPARAM) SIZEOF (TBB /TON), 0);

TBAB.HINST = hinst_commctrl; // can also be set into its own program Hinstance, which is the tool Icon TBAB.NID = IDB_STD_SMALL_COLOR; SENDMESSAGE (HWndToolbar, TB_ADDBITMAP, 0, (LPARAM) & TBAB);

ZeromeMory (TBB, SIZEOF (TBB)); TBB [0] .IBitmap = std_filenew; TBB [0] .fsState = TBSTATE_ENABED; TBB [0] .fsStyle = TBStyle_Button; TBB [0] .idcommand = id_file_new;

TBB [1] .IBITMAP = std_fileopen; TBB [1] .fsState = TBSTATE_ENABED; TBB [1] .fsStyle = TBStyle_Button; TBB [1] .idcommand = id_file_open;

TBB [2] .IBITMAP = std_filesave; TBB [2] .fsState = TBSTATE_ENABED; TBB [2] .fsStyle = TBStyle_Button; TBB [2] .idcommand = id_file_saveas;

SendMessage (HWndToolbar, TB_ADDButtons, Sizeof (TBB) / Sizeof (TBButton), (LPARAM) & TBB);

Break;

/ / Respond to WM_SIZE message

Case wm_size: hwndtoolbar = getdlgitem (hwnd, idc_main_toolbar); SendMessage (Hwndtoolbar, TB_AUTOSIZE, 0, 0);

The program is running as follows:

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

New Post(0)