#include <commctrl.h>
#pragma comment(lib, TEXT("comctl32"))
HWND hToolBar;
LRESULT CALLBACK WndProc(HWND hWnd,UINT iMessage,WPARAM wParam,LPARAM lParam)
{
static TBBUTTON ToolBtn[5]={
{0,10,TBSTATE_ENABLED,TBSTYLE_BUTTON,0,0,0,0},
{1,11,TBSTATE_ENABLED,TBSTYLE_BUTTON,0,0,0,0},
{5,0,0,TBSTYLE_SEP,0,0,0,0},
{2,12,TBSTATE_ENABLED | TBSTATE_CHECKED,TBSTYLE_CHECKGROUP,0,0,0,0},
{3,13,TBSTATE_ENABLED,TBSTYLE_CHECKGROUP,0,0,0,0}
};
switch (iMessage) {
case WM_CREATE:
InitCommonControls();
/*
or
INITCOMMONCONTROLSEX cc ;
cc.dwSize = sizeof(INITCOMMONCONTROLSEX) ;
cc.dwICC = ICC_BAR_CLASSES ; // register only the toolbar control
InitCommonControlsEx(&cc) ;
*/
hToolBar=CreateToolbarEx(hWnd, WS_CHILD|WS_VISIBLE|WS_BORDER,
ID_TOOLBAR, 4, g_hInst, IDB_BITMAP1, ToolBtn, 5,
16,16,16,16,sizeof(TBBUTTON));
return 0;
case WM_DESTROY:
PostQuitMessage(0);
return 0;
case WM_COMMAND:
switch (LOWORD(wParam)) {
case 10:
MessageBox(hWnd,"첫번째 버튼을 선택했습니다","알림",MB_OK);
break;
case 11:
MessageBox(hWnd,"두번째 버튼을 선택했습니다","알림",MB_OK);
break;
}
return 0;
case WM_SIZE:
SendMessage(hToolBar,TB_AUTOSIZE,0,0);
/*
or
SendMessage(hToolBar, WM_SIZE, wParam, lParam);
*/
return 0;
}
return(DefWindowProc(hWnd,iMessage,wParam,lParam));
}