////////////////////////////////////////////////////////////////////// // Creation d'une toolbar a la main // S. Marechal ////////////////////////////////////////////////////////////////////// #include #include #include #include #include #include #include "resource.h" long FAR PASCAL WndProc( HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam ); // Tout pour la toolbar static int s_NbTBButton = 2; static const int s_NbTBButtonImage = 2; static const TBBUTTON s_TBButton[] = { 0, ID_EXIT, TBSTATE_ENABLED, TBSTYLE_BUTTON, 0, 0, 0, 0, 1, ID_ABOUT, TBSTATE_ENABLED, TBSTYLE_BUTTON, 0, 0, 0, 0, }; #define CX_TBBUTTON 16 #define CY_TBBUTTON 16 HWND s_hToolBar; // Status bar HWND s_hStatusBar; ////////////////////////////////////////////////////////////////////// int WINAPI WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow ) { HWND hWnd; MSG msg; WNDCLASSEX wndclass; InitCommonControls(); // Enregistrement de la classe wndclass.cbSize = sizeof(WNDCLASSEX); wndclass.style = CS_HREDRAW | CS_VREDRAW | CS_DBLCLKS; wndclass.lpfnWndProc = WndProc; wndclass.cbClsExtra = 0; wndclass.cbWndExtra = 0; wndclass.hInstance = GetModuleHandle(NULL); wndclass.hIcon = NULL; wndclass.hIconSm = NULL; wndclass.hCursor = LoadCursor (NULL, IDC_ARROW); wndclass.hbrBackground = CreateSolidBrush (GetSysColor (COLOR_MENU)); wndclass.lpszMenuName = MAKEINTRESOURCE(IDR_MENU); wndclass.lpszClassName = "MYTOOLBARCLASS"; if (!RegisterClassEx (&wndclass)) { MessageBox (NULL, "RegisterClassEx() failed!", "Error", MB_OK); return (1); } // Creation de la fenetre hWnd = CreateWindow( "MYTOOLBARCLASS", "COUCOU", WS_OVERLAPPEDWINDOW, 0, 0, 400, 400, NULL, NULL, hInstance, NULL ); // ToolBar s_hToolBar = CreateToolbarEx( hWnd, WS_CHILD|WS_VISIBLE|WS_CLIPSIBLINGS|CCS_TOP|TBSTYLE_TOOLTIPS|TBSTYLE_FLAT, /*ID_TOOLBAR*/0, s_NbTBButtonImage, GetModuleHandle(NULL), IDR_TOOLBAR, s_TBButton, s_NbTBButton, // <- Nombre totals de boutons (pas forcement affiches) CX_TBBUTTON, CY_TBBUTTON, CX_TBBUTTON*s_NbTBButton, CY_TBBUTTON, sizeof(TBBUTTON)); // StatusBar s_hStatusBar = CreateStatusWindow( WS_CHILD|WS_VISIBLE|WS_CLIPSIBLINGS|CCS_BOTTOM|SBARS_SIZEGRIP, "", hWnd, /*ID_STATUSBAR*/ 0 ); SendMessage(s_hStatusBar, SB_SETTEXT, 0,(LPARAM)"coucou") ; // Boucle des messages // La fenetre est ShowWindow( hWnd, SW_SHOW ); UpdateWindow( hWnd ); while(GetMessage(&msg, NULL, 0, 0)) { TranslateMessage(&msg); DispatchMessage(&msg); } return(msg.wParam); } ////////////////////////////////////////////////////////////////////// long FAR PASCAL WndProc( HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam ) { switch( message ) { case WM_CREATE : { return 0; } case WM_COMMAND: { switch(wParam) { case ID_ABOUT: MessageBox( hWnd, "Programme de test", "message", MB_OK ); break; case ID_EXIT: SendMessage( hWnd, WM_DESTROY, 0, 0 ); break; } return 0; } case WM_DESTROY : { PostQuitMessage( 0 ); return 0L; } } return( DefWindowProc(hWnd, message, wParam, lParam) ); }