Eigene Buttons zu Tabbar hinzufügen



  • Hi ich habe folgenden code wo ich ein Tabbar erstelle und die systembuttons hinzufüge nun möchte ich gerne noch eigene Buttons hinzufügen bekomm das allerdings nicht ganz hin.
    Hier mein code

    hwndToolbar = CreateWindowEx(WS_EX_TOOLWINDOW, TOOLBARCLASSNAME, NULL,
                             WS_CHILD | WS_VISIBLE | WS_CLIPCHILDREN | WS_CLIPSIBLINGS |
    						 CCS_NODIVIDER | CCS_NOPARENTALIGN | CCS_NORESIZE | TBSTYLE_FLAT | TBSTYLE_TOOLTIPS, 
                             0, 0, 200, 30, hwnd, NULL, ghInstance, NULL); 
    
    			SendMessage(hwndToolbar, TB_BUTTONSTRUCTSIZE, (WPARAM)sizeof(TBBUTTON), 0); 
    
    			tbAddBmp.hInst = HINST_COMMCTRL; 
    			tbAddBmp.nID = IDB_STD_SMALL_COLOR; 
    			SendMessage(hwndToolbar, TB_ADDBITMAP, 0, (WPARAM)&tbAddBmp); 
    
    			tbb[0].iBitmap = STD_FILENEW; 
    			tbb[0].idCommand = ID_TOLLBAR_NEW; 
    			tbb[0].fsState = TBSTATE_ENABLED; 
    			tbb[0].fsStyle = TBSTYLE_BUTTON; 
    			tbb[0].dwData = 0; 
    			tbb[0].iString = 0;
    
    			tbb[1].iBitmap = STD_FILEOPEN; 
    			tbb[1].idCommand = ID_TOOLBAR_OPEN; 
    			tbb[1].fsState = TBSTATE_ENABLED; 
    			tbb[1].fsStyle = TBSTYLE_BUTTON; 
    			tbb[1].dwData = 0; 
    			tbb[1].iString = 0;
    
    			tbb[2].iBitmap = STD_FILESAVE; 
    			tbb[2].idCommand = ID_TOOLBAR_SAVE; 
    			tbb[2].fsState = TBSTATE_ENABLED; 
    			tbb[2].fsStyle = TBSTYLE_BUTTON;  
    			tbb[2].dwData = 0; 
    			tbb[2].iString = 0;
    
    			tbb[3].iBitmap = 0; 
    			tbb[3].idCommand = -1; 
    			tbb[3].fsState = TBSTATE_ENABLED; 
    			tbb[3].fsStyle = TBSTYLE_SEP;    
    			tbb[3].dwData = 0; 
    			tbb[3].iString = 0; 
    
    			tbb[4].iBitmap = STD_UNDO; 
    			tbb[4].idCommand = ID_TOOLBAR_UNDO; 
    			tbb[4].fsState = TBSTATE_ENABLED; 
    			tbb[4].fsStyle = TBSTYLE_BUTTON; 
    			tbb[4].dwData = 0; 
    			tbb[4].iString = 0;
    
    			tbb[5].iBitmap = STD_REDOW; 
    			tbb[5].idCommand = ID_TOOLBAR_REDOW; 
    			tbb[5].fsState = TBSTATE_ENABLED; 
    			tbb[5].fsStyle = TBSTYLE_BUTTON; 
    			tbb[5].dwData = 0; 
    			tbb[5].iString = 0;
    
    			tbb[6].iBitmap = 0; 
    			tbb[6].idCommand = -1; 
    			tbb[6].fsState = TBSTATE_ENABLED; 
    			tbb[6].fsStyle = TBSTYLE_SEP; 
    			tbb[6].dwData = 0; 
    			tbb[6].iString = 0; 
    
    			tbb[7].iBitmap = STD_FIND ; 
    			tbb[7].idCommand = ID_TOOLBAR_FIND; 
    			tbb[7].fsState = TBSTATE_ENABLED; 
    			tbb[7].fsStyle = TBSTYLE_BUTTON; 
    			tbb[7].dwData = 0; 
    			tbb[7].iString = 0;
    
    			tbb[8].iBitmap = STD_HELP; 
    			tbb[8].idCommand = ID_TOOLBAR_HELP; 
    			tbb[8].fsState = TBSTATE_ENABLED; 
    			tbb[8].fsStyle = TBSTYLE_BUTTON; 
    			tbb[8].dwData = 0; 
    			tbb[8].iString = 0;
    
    			SendMessage(hwndToolbar, TB_ADDBUTTONS, 9, (LPARAM)(LPTBBUTTON)&tbb);
    

    habe dann das versucht allerdings bekomm ich da ein Button aber das Bitmap wird nicht angezeigt

    tbb[9].iBitmap = IDB_TEST; 
    			tbb[9].idCommand = ID_TEST; 
    			tbb[9].fsState = TBSTATE_ENABLED; 
    			tbb[9].fsStyle = TBSTYLE_BUTTON; 
    			tbb[9].dwData = 0; 
    			tbb[9].iString = 0;
    
    			SendMessage(hwndToolbar, TB_ADDBUTTONS, 10, (LPARAM)(LPTBBUTTON)&tbb);
    

    Ich hoffe ihr könnt mir helfen?
    MfG schirrmie



  • MSDN schrieb:

    iBitmap
    Zero-based index of the button image. Set this member to I_IMAGECALLBACK, and the toolbar will send the TBN_GETDISPINFO notification to retrieve the image index when it is needed.

    MSDN schrieb:

    Defining Button Images by Using Bitmaps
    Each button in a toolbar can include a bitmapped image. A toolbar uses an internal list to store the information that it needs to draw the images. When you call the CreateToolbarEx function, you specify a monochrome or color bitmap that contains the initial images, and the toolbar adds the information to the internal list of images. You can add additional images later by using the TB_ADDBITMAP message.

    Each image has a zero-based index. The first image added to the internal list has an index of 0, the second image has an index of 1, and so on. TB_ADDBITMAP adds images to the end of the list and returns the index of the first new image that it added. To associate the image with a button, you must send a TB_ADDBUTTONS message and specify the image's index after you add bitmaps to the internal image list.

    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.



  • Ahh sorry habe gerade gesehen das im FAQ ein beitrag dazu gibt.
    Trotzdem danke
    MfG schirrmie



  • Also ich habe doch noch ein Problem. Ich beziehe mich jetzt auf das Faq.
    Ich kann jetzt ein Button hinzufügen aber nicht mehr.

    bit.hInst = HINST_COMMCTRL; 
    			bit.nID = IDB_STD_SMALL_COLOR; 
    			SendMessage(hwndToolbar, TB_ADDBITMAP, 0, (LPARAM)&bit); 
    
    			bit.hInst = NULL; 
    			bit.nID   = (UINT_PTR)LoadImage(GetModuleHandle(NULL), 
    				MAKEINTRESOURCE(IDB_PROGGEN), 
    				IMAGE_BITMAP, 
    				GetSystemMetrics(SM_CXSMICON), 
    				GetSystemMetrics(SM_CYSMICON), 
    				LR_DEFAULTCOLOR | LR_LOADMAP3DCOLORS | LR_LOADTRANSPARENT);
    			mypictures[9].iBitmap = SendMessage(hwndToolbar,TB_ADDBITMAP,0,(LPARAM)&bit); 
    
    			bit.hInst = NULL; 
    			bit.nID   = (UINT_PTR)LoadImage(GetModuleHandle(NULL), 
    				MAKEINTRESOURCE(IDB_KOMPILE), 
    				IMAGE_BITMAP, 
    				GetSystemMetrics(SM_CXSMICON), 
    				GetSystemMetrics(SM_CYSMICON), 
    				LR_DEFAULTCOLOR | LR_LOADMAP3DCOLORS | LR_LOADTRANSPARENT);
    			mypictures[10].iBitmap = SendMessage(hwndToolbar,TB_ADDBITMAP,0,(LPARAM)&bit); 
    
    			bit.hInst = NULL; 
    			bit.nID   = (UINT_PTR)LoadImage(GetModuleHandle(NULL), 
    				MAKEINTRESOURCE(IDB_INSERT), 
    				IMAGE_BITMAP, 
    				GetSystemMetrics(SM_CXSMICON), 
    				GetSystemMetrics(SM_CYSMICON), 
    				LR_DEFAULTCOLOR | LR_LOADMAP3DCOLORS | LR_LOADTRANSPARENT);
    			mypictures[11].iBitmap = SendMessage(hwndToolbar,TB_ADDBITMAP,0,(LPARAM)&bit); 
    
    			SendMessage (hwndToolbar, TB_ADDBUTTONS, (WPARAM)sizeof(mypictures)/sizeof(mypictures[0]), (LPARAM)(TBBUTTON*)&mypictures);
    

    So hab ich's versucht aber wie gesagt wird nur das erste angezeigt.
    Irgendwie wenn ich hier

    TBBUTTON mypictures[] = 
    			{ 
    				{STD_FILENEW , ID_TOLLBAR_NEW, TBSTATE_ENABLED, TBSTYLE_AUTOSIZE | TBSTYLE_BUTTON, 0, 0}, 
    				{STD_FILEOPEN, ID_TOOLBAR_OPEN, TBSTATE_ENABLED, TBSTYLE_AUTOSIZE | TBSTYLE_BUTTON, 0, 0}, 
    				{STD_FILESAVE, ID_TOOLBAR_SAVE, TBSTATE_ENABLED, TBSTYLE_AUTOSIZE | TBSTYLE_BUTTON, 0, 0}, 
    
    				{0, 0, TBSTATE_ENABLED, TBSTYLE_SEP, 0, 0}, 
    				{STD_UNDO, ID_TOOLBAR_UNDO, TBSTATE_ENABLED, TBSTYLE_AUTOSIZE | TBSTYLE_BUTTON, 0, 0}, 
    				{STD_REDOW, ID_TOOLBAR_REDOW, TBSTATE_ENABLED, TBSTYLE_AUTOSIZE | TBSTYLE_BUTTON, 0, 0}, 
    				{0, 0, TBSTATE_ENABLED, TBSTYLE_SEP, 0, 0}, 
    				{STD_FIND, ID_TOOLBAR_FIND, TBSTATE_ENABLED, TBSTYLE_AUTOSIZE | TBSTYLE_BUTTON, 0, 0}, 
    				{STD_HELP, ID_TOOLBAR_HELP, TBSTATE_ENABLED, TBSTYLE_AUTOSIZE | TBSTYLE_BUTTON, 0, 0}, 
    
    				{0, 0, TBSTATE_ENABLED, TBSTYLE_SEP, 0, 0}, 
    
    				{0, 0, TBSTATE_ENABLED, TBSTYLE_AUTOSIZE | TBSTYLE_BUTTON, 0, 0}, 
    				{0, 0, TBSTATE_ENABLED, TBSTYLE_AUTOSIZE | TBSTYLE_BUTTON, 0, 0}, 
    				{0, 0, TBSTATE_ENABLED, TBSTYLE_AUTOSIZE | TBSTYLE_BUTTON, 0, 0} 
    
    			};
    

    Halt hinten noch son Seperator reinmach wird nur ein halber angezeigt und wenn ich 2 reinmach wird garnichts mehr angezeigt.
    Hoffe ihr wisst was.

    MfG schirrmie


Anmelden zum Antworten