1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150
|
#define WIN32_LEAN_AND_MEAN
#define _WIN32_IE 0x0300 // EDIT !
#include <windows.h>
#include <commctrl.h>
#include "resource.h"
#include <array>
LRESULT CALLBACK
windowProcedure( HWND hwnd,
UINT uMsg,
WPARAM wParam,
LPARAM lParam );
int WINAPI
WinMain( HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR lpCmdLine,
int nCmdShow )
{
LPCTSTR className( "bla" );
char windowCaption[ 50 ];
const int numberOfButtons = 7;
LoadString( hInstance, IDS_APPNAME, windowCaption, 50 );
WNDCLASSEX wndClassEx
{
sizeof( WNDCLASSEX ), // cbSize
CS_HREDRAW | CS_VREDRAW, // style
windowProcedure, // lpfnWinProc
0, // cbClsExtra
0, // cbWinExtra
hInstance, // hInstance
LoadIcon( NULL, IDI_APPLICATION ), // hIcon
LoadCursor( NULL, IDC_ARROW ), // hCursor
static_cast<HBRUSH>( GetStockObject( WHITE_BRUSH ) ), // hbrBackground
MAKEINTRESOURCE( IDR_MAINMENU ), // lpszMenuName
className, // lpszClassName
LoadIcon( NULL, IDI_APPLICATION ) // hIconSm
};
RegisterClassEx( &wndClassEx );
HWND hWnd(
CreateWindow(
className,
windowCaption,
WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT,
CW_USEDEFAULT,
CW_USEDEFAULT,
CW_USEDEFAULT,
nullptr,
nullptr,
hInstance,
nullptr
)
);
if( !hWnd )
return 1;
INITCOMMONCONTROLSEX initCtrlEx
{
sizeof( INITCOMMONCONTROLSEX ),
ICC_BAR_CLASSES
};
InitCommonControlsEx( &initCtrlEx );
TBBUTTON tbrButtons[ numberOfButtons ]
{
{
0, IDM_FILE_NEW, TBSTATE_ENABLED,
TBSTYLE_BUTTON, { 0,0 }, 0L, 0
},
{
1, IDM_FILE_OPEN, TBSTATE_ENABLED,
TBSTYLE_BUTTON, { 0, 0 }, 0L, 0
},
{
0, 0, TBSTATE_ENABLED, TBSTYLE_SEP,
{ 0, 0 }, 0L, 0
},
{
2, IDM_ARROW, TBSTATE_ENABLED,
TBSTYLE_BUTTON, { 0, 0 }, 0L, 0
},
{
3, IDM_DRAWLINE, TBSTATE_ENABLED,
TBSTYLE_BUTTON, { 0, 0 }, 0L, 0
},
{
4, IDM_DRAW_RECTANGLE, TBSTATE_ENABLED,
TBSTYLE_BUTTON, { 0, 0 }, 0L, 0
},
{
5, IDM_ELLIPSE, TBSTATE_ENABLED,
TBSTYLE_BUTTON, { 0, 0 }, 0L, 0
}
};
HWND hWndToolbar =
CreateToolbarEx(
hWnd,
WS_VISIBLE | WS_CHILD | WS_BORDER,
IDB_BITMAP1,
numberOfButtons,
hInstance,
IDB_BITMAP1,
tbrButtons,
numberOfButtons,
16, 16, 16, 16,
sizeof( TBBUTTON )
);
// Display the window
ShowWindow( hWnd, SW_SHOWNORMAL );
UpdateWindow( hWnd );
MSG msg;
// Message loop
while( GetMessage( &msg, nullptr, 0, 0 ) )
{
TranslateMessage( &msg );
DispatchMessage( &msg );
}
return msg.wParam;
}
LRESULT CALLBACK windowProcedure( HWND hWnd,
UINT uMsg,
WPARAM wParam,
LPARAM lParam )
{
switch( uMsg )
{
case WM_DESTROY :
PostQuitMessage( WM_QUIT );
break;
default :
return DefWindowProc( hWnd, uMsg, wParam, lParam );
}
return 0;
}
|