msiasty Temat założony przez niniejszego użytkownika |
Problem z paskiem TOOLBAR w winapi » 2014-07-26 09:51:07 Witam wszystkich, mam pewien problem a mianowicie ćwiczę tworzenie toolbaru w WINAPI i przyciski z paska toolbar w aplikacji MDI nie dają znaku życia. próbowałem juz wszystkiego ale nie mam pojęcia jak sprawdzić wywołanie przycisku. Proszę o pomoc (może coś źle robie) #include <windows.h> #include <commctrl.h>
#define ID_MDI_FIRSTCHILD 50000 #define tool_1 0 #define tool_2 1 #define tool_3 2 #define tool_4 4 #define tool_00 700
LRESULT CALLBACK WindowProcedure( HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam ); LRESULT CALLBACK ChildWindowProcedure( HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam );
char szClassName[] = "KlasaOkna"; char szChildName[] = "KlasaOknaDziecka";
HWND hMDIClient, hToolbar;
int WINAPI WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow ) { HWND hwnd; MSG messages; WNDCLASSEX wincl; InitCommonControls(); wincl.hInstance = hInstance; wincl.lpszClassName = szClassName; wincl.lpfnWndProc = WindowProcedure; wincl.style = 0; wincl.cbSize = sizeof( WNDCLASSEX ); wincl.hIcon = LoadIcon( hInstance, IDI_APPLICATION ); wincl.hIconSm = LoadIcon( hInstance, IDI_APPLICATION ); wincl.hCursor = LoadCursor( NULL, IDC_ARROW ); wincl.lpszMenuName = NULL; wincl.cbClsExtra = 0; wincl.cbWndExtra = 0; wincl.hbrBackground =( HBRUSH ) COLOR_WINDOW; if( !RegisterClassEx( & wincl ) ) return FALSE; wincl.lpfnWndProc = ChildWindowProcedure; wincl.lpszMenuName =( LPCTSTR ) NULL; wincl.lpszClassName = "KlasaOknaDziecka"; if( !RegisterClassEx( & wincl ) ) return FALSE; hwnd = CreateWindowEx( 0, szClassName, "Aplikacja MDI", WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT, 400, 300, NULL, NULL, hInstance, NULL ); ShowWindow( hwnd, nCmdShow ); CLIENTCREATESTRUCT ccs; ccs.hWindowMenu = NULL; ccs.idFirstChild = ID_MDI_FIRSTCHILD; hMDIClient = CreateWindowEx( 0, "MDICLIENT",( LPCTSTR ) NULL, WS_CHILD | WS_CLIPCHILDREN | WS_VSCROLL | WS_HSCROLL, 1, 1, 800, 600, hwnd,( HMENU ) 0xCAC, hInstance,( LPSTR ) & ccs ); ShowWindow( hMDIClient, SW_SHOW ); HBITMAP hbmTool =( HBITMAP ) LoadImage( GetModuleHandle( NULL ), "1.bmp", IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE | LR_LOADMAP3DCOLORS ); TBBUTTON tbb[ 3 ]; ZeroMemory( tbb, sizeof( tbb ) ); for( int i = 0; i < 3; ++i ) { tbb[ i ].idCommand = i; tbb[ i ].iBitmap = tbb[ i ].iString = i; tbb[ i ].fsState = TBSTATE_ENABLED; tbb[ i ].fsStyle = TBSTYLE_BUTTON; } HWND hToolbar = CreateToolbarEx( hMDIClient, WS_CHILD | WS_VISIBLE, tool_00, 3, NULL,( UINT ) hbmTool, tbb, 3, 16, 16, 16, 16, sizeof( TBBUTTON ) ); SendMessage( hToolbar, TB_ADDSTRING, 0,( LPARAM ) "Player\0Ustawienia\0Wyjscie" ); while( GetMessage( & messages, NULL, 0, 0 ) ) { if( !TranslateMDISysAccel( hMDIClient, & messages ) ) { TranslateMessage( & messages ); DispatchMessage( & messages ); } } return messages.wParam; }
LRESULT CALLBACK WindowProcedure( HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam ) { switch( message ) { case WM_DESTROY: PostQuitMessage( 0 ); break; case WM_SIZE: break; c default: return DefFrameProc( hwnd, hMDIClient, message, wParam, lParam ); } return 0; }
LRESULT CALLBACK ChildWindowProcedure( HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam ) { switch( message ) { case WM_COMMAND: { if(( HWND ) lParam == hToolbar ) { switch( LOWORD( wParam ) ) { case tool_1: { } break; case tool_2: { } break; case tool_3: { PostQuitMessage( 0 ); } break; } } } break; default: return DefMDIChildProc( hwnd, message, wParam, lParam ); } return 0; }
|