Button Größe in Toolbar



  • Ich versuche eine Tooolbar mit 6 Buttons der Größe 30x30 zu erstellen, das klappt auch soweit. Jedoch wird meine Bitmap Resource nicht richtig dargestellt. Das Bitmap wird in 16x16 große teile aufgeteilt und auf die Buttons gelegt, das Bitmap hat aber die Größe 30x180 = 6 Buttons. Hier ist mein Code:

    HWND ToolBar(HWND hWndParent, HINSTANCE hInst){
    
    	HWND				hwndTB; 
    	TBADDBITMAP			tbab; 
    	TBBUTTON			TB_Button[6]; 
    	INITCOMMONCONTROLSEX	icex;
    	int				num_of_Buttons = 6,i;
    
    	icex.dwSize = sizeof(INITCOMMONCONTROLSEX);
    	icex.dwICC  = ICC_BAR_CLASSES;
    	InitCommonControlsEx(&icex);
    
    	tbab.hInst = hInst;
    	tbab.nID = IDR_TOOLBAR1;
    
    	hwndTB = CreateWindowEx(0, TOOLBARCLASSNAME, (LPSTR) NULL, WS_CHILD | WS_VISIBLE, 0, 0, 0, 0, hWndParent, (HMENU)NULL, NULL, NULL); 
    	SendMessage(hwndTB, TB_SETBUTTONSIZE, 0, (LPARAM) MAKELONG (30, 30));
    	SendMessage(hwndTB, TB_BUTTONSTRUCTSIZE, (WPARAM) sizeof(TBBUTTON), 0);
    
    	SendMessage(hwndTB, TB_ADDBITMAP, (WPARAM)num_of_Buttons, (LPARAM) &tbab);
    	SendMessage(hwndTB, TB_LOADIMAGES, IDR_TOOLBAR1, (LPARAM) hInst);
    	ZeroMemory(&TB_Button, sizeof(TBBUTTON)*num_of_Buttons);
    
    	for(i=0; i < num_of_Buttons; i++){
    		TB_Button[i].fsState = TBSTATE_ENABLED; 
    		TB_Button[i].fsStyle = TBSTYLE_BUTTON;
    		TB_Button[i].iString = 0;
    	}
    
    	TB_Button[0].iBitmap = 0;
    	TB_Button[0].idCommand = BUTTON_0; 
     	TB_Button[1].iBitmap = 1; 
    	TB_Button[1].idCommand = BUTTON_1; 
    	TB_Button[2].iBitmap = 2;
    	TB_Button[2].idCommand = BUTTON_2; 
    	TB_Button[3].iBitmap = 3; 
    	TB_Button[3].idCommand = BUTTON_3; 
    	TB_Button[4].iBitmap = 4; 
    	TB_Button[4].idCommand = BUTTON_4; 
    	TB_Button[5].iBitmap = 5; 
    	TB_Button[5].idCommand = BUTTON_5; 
    
    	SendMessage(hwndTB, TB_ADDBUTTONS, num_of_Buttons, (LPARAM) (LPTBBUTTON) &TB_Button); 
    	SendMessage(hwndTB, TB_AUTOSIZE, 0, 0); 					
    	ShowWindow(hwndTB, SW_SHOW); 
    	return hwndTB;
    }
    

    Weiß jemand Rat, was mache ich falsch?



  • msdn schrieb:

    Microsoft Windows assumes that all of a toolbar's bitmapped images are the same size. You specify the size when you create the toolbar by using CreateToolbarEx. If you use the CreateWindowEx function to create a toolbar, the size of the images is set to the default dimensions of 16 by 15 pixels. You can use the TB_SETBITMAPSIZE message to change the dimensions of the bitmapped images, but you must do so before adding any images to the internal list.

    schon probiert?
    http://msdn.microsoft.com/library/default.asp?url=/library/en-us/shellcc/platform/commctls/toolbar/messages/tb_setbitmapsize.asp



  • Super, hat geklappt, 1000 Dank.


Anmelden zum Antworten