Overlapping toolbars

This is a discussion on Overlapping toolbars within the Windows Programming forums, part of the Platform Specific Boards category; I have an application with two toolbars. However, regardless of what coordinate values I use in CreateWindowEx, the second toolbar ...

  1. #1
    Funniest man in this seat minesweeper's Avatar
    Join Date
    Mar 2002
    Posts
    801

    Overlapping toolbars

    I have an application with two toolbars. However, regardless of what coordinate values I use in CreateWindowEx, the second toolbar always overlays the first. How can I correct this? I have seen possible solutions using MFC but I am just using the straight API.

    Thanks.
    Last edited by minesweeper; 06-14-2003 at 03:10 PM.

  2. #2
    erstwhile
    Join Date
    Jan 2002
    Posts
    2,227
    You might want to try putting the toolbars onto bands of a rebar control.

    Alternatively you could just handle the WM_SIZE message for the parent window and set the dimensions of each toolbar from there with MoveWindow or SetWindowPos.

    edit: link
    Last edited by Ken Fitlike; 06-14-2003 at 03:11 PM.

  3. #3
    Funniest man in this seat minesweeper's Avatar
    Join Date
    Mar 2002
    Posts
    801
    Thanks for the info. I am going for the rebar method. Most of the following code is taken from various sites such as MSDN and Ken Fitlikes site. It is the code to create my toolbars, rebar and status bar.

    Code:
    INITCOMMONCONTROLSEX iccx;
            TBADDBITMAP          tbab, tbabmove;
            TBBUTTON             tbb[4];
    		TBBUTTON			 tbbmove [3];
            //first load in the common controls dll, specifying the toolbar control wnd class
            iccx.dwSize=sizeof(INITCOMMONCONTROLSEX);
            iccx.dwICC=ICC_BAR_CLASSES;
            InitCommonControlsEx(&iccx);
    
    		htool = CreateWindowEx(0, TOOLBARCLASSNAME, NULL, WS_CHILD | WS_VISIBLE, 0, 0, 0, 0,
    			hwndRB, (HMENU)IDC_MAIN_TOOL, GetModuleHandle(NULL), NULL);
    
    		htoolMove = CreateWindowEx(0, TOOLBARCLASSNAME, NULL, WS_CHILD | WS_VISIBLE, 0, 0, 0, 0,
    			hwndRB, (HMENU)ID_MOVE_TOOLBAR, GetModuleHandle(NULL), NULL);
    
    		hstatus = CreateWindowEx(0, STATUSCLASSNAME, NULL,
    			WS_CHILD | WS_VISIBLE | SBARS_SIZEGRIP, 0, 0, 0, 0,
    			hwnd, (HMENU)IDC_MAIN_STATUS, GetModuleHandle(NULL), NULL);
    
    		hMultiFont = CreateFont(24,12,0,0,700,0,0,0,0,0,0,0,0,TEXT("Times New Roman"));
    		hMultiFont1 = CreateFont(14,12,0,0,700,0,0,0,0,0,0,0,0,TEXT("Times New Roman"));
    		hFont = CreateFont(14,0,0,0,FW_BOLD,0,0,0,ANSI_CHARSET,OUT_DEFAULT_PRECIS,CLIP_DEFAULT_PRECIS, DEFAULT_QUALITY,DEFAULT_PITCH | FF_DONTCARE, "Arial");
    
    		SendMessage (hwnd, WM_SETFONT, (WPARAM)hFont,0);
    
    		   
    		icex.dwSize = sizeof(INITCOMMONCONTROLSEX);
    		icex.dwICC   = ICC_COOL_CLASSES|ICC_BAR_CLASSES;
    		InitCommonControlsEx(&icex);
    		hwndRB = CreateWindowEx(WS_EX_TOOLWINDOW,
                               REBARCLASSNAME,
                               NULL,
                               WS_CHILD|WS_VISIBLE|WS_CLIPSIBLINGS|
                               WS_CLIPCHILDREN|RBS_VARHEIGHT|
                               CCS_NODIVIDER,
                               0,0,0,0,
                               hwnd,
                               NULL,
                               GetModuleHandle (NULL),
                               NULL);
    		if(!hwndRB)
    		   return NULL;
    		// Initialize and send the REBARINFO structure.
    		rbi.cbSize = sizeof(REBARINFO);  // Required when using this
                                        // structure.
    		rbi.fMask  = 0;
    		rbi.himl   = (HIMAGELIST)NULL;
    		if(!SendMessage(hwndRB, RB_SETBARINFO, 0, (LPARAM)&rbi))
    		   return NULL;
    		// Initialize structure members that both bands will share.
    		rbBand.cbSize = sizeof(REBARBANDINFO);  // Required
    		rbBand.fMask  = RBBIM_COLORS | RBBIM_TEXT | RBBIM_STYLE | RBBIM_CHILD  | RBBIM_CHILDSIZE | 
    		                RBBIM_SIZE;
    		rbBand.fStyle = RBBS_CHILDEDGE ;
    
    		htoolMove=CreateWindowEx(0,
                                    TEXT("BUTTON"),
                                    TEXT("Button"),WS_CHILD|WS_VISIBLE,
                                    164,4,100,20,hwndRB,0,hInstance,0);
    
    
    			              	
    		GetClientRect(htoolMove, &rc);
    		rbBand.lpText     = "Tool Bar";
    		rbBand.hwndChild  = htoolMove;
    		rbBand.cxMinChild = 0;
    		rbBand.cyMinChild = rc.bottom - rc.top;
    		rbBand.cx         = 200;
       
    		
    		SendMessage(hwndRB, RB_INSERTBAND, (WPARAM)-1, (LPARAM)&rbBand);
       
    		
    		htool=CreateWindowEx(0,
                                      TEXT("COMBOBOX"),
                                      0,WS_CHILD|WS_VISIBLE|CBS_DROPDOWN,
                                      40,4,100,60,hwndRB,0,hInstance,0);
    
    			
    		GetClientRect(htool, &rc);
    		rbBand.lpText     = "Tool Bar";
    		rbBand.hwndChild  = htool;
    		rbBand.cxMinChild = 0;
    		rbBand.cyMinChild = rc.bottom - rc.top;
    		rbBand.cx         = 300;
    
    		
    		SendMessage(hwndRB, RB_INSERTBAND, (WPARAM)-1, (LPARAM)&rbBand);
    		
    		SendMessage(htool, TB_BUTTONSTRUCTSIZE, (WPARAM)sizeof(TBBUTTON), 0);
    		SendMessage(htoolMove, TB_BUTTONSTRUCTSIZE, (WPARAM)sizeof(TBBUTTON), 0);
    
    
            tbabmove.hInst = GetModuleHandle(NULL);
            tbabmove.nID = IDB_MOVE_TOOL;
            SendMessage(htoolMove, TB_ADDBITMAP, 3, (LPARAM)&tbabmove);
    
    
            ZeroMemory(tbbmove, sizeof(tbbmove));
            tbbmove[0].iBitmap = 0;
            tbbmove[0].fsState = TBSTATE_INDETERMINATE;
            tbbmove[0].fsStyle = TBSTYLE_BUTTON;
            tbbmove[0].idCommand = CM_PLUS;
    
    
            tbbmove[1].iBitmap = 1;
            tbbmove[1].fsState = TBSTATE_INDETERMINATE;
            tbbmove[1].fsStyle = TBSTYLE_BUTTON;
            tbbmove[1].idCommand = CM_PREV;
    
    
    		tbbmove[2].iBitmap = 2;
            tbbmove[2].fsState = TBSTATE_INDETERMINATE;
            tbbmove[2].fsStyle = TBSTYLE_BUTTON;
            tbbmove[2].idCommand = CM_NEXT;
    
    		SendMessage(htoolMove, TB_ADDBUTTONS, 3, (LPARAM)&tbbmove);
    
    		tbab.hInst = HINST_COMMCTRL;
    		tbab.nID = IDB_STD_SMALL_COLOR;
    		SendMessage(htool, TB_ADDBITMAP, 0, (LPARAM)&tbab);
    
    		ZeroMemory(tbb, sizeof(tbb));
    		tbb[0].iBitmap = STD_FILENEW;
    		tbb[0].fsState = TBSTATE_ENABLED;
    		tbb[0].fsStyle = TBSTYLE_BUTTON;
    		tbb[0].idCommand = ID_NEW;
    
    		tbb[1].iBitmap = STD_FILEOPEN;
    		tbb[1].fsState = TBSTATE_ENABLED;
    		tbb[1].fsStyle = TBSTYLE_BUTTON;
    		tbb[1].idCommand = ID_ADDRESS_OPEN;
    
    		tbb[2].iBitmap = STD_FILESAVE;
    		tbb[2].fsState = TBSTATE_INDETERMINATE ;
    		tbb[2].fsStyle = TBSTYLE_BUTTON;
    		tbb[2].idCommand = ID_FILE_ADDRESS_SAVE_AS;
    
    		tbb[3].iBitmap = STD_FIND;
    		tbb[3].fsState = TBSTATE_INDETERMINATE ;
    		tbb[3].fsStyle = TBSTYLE_BUTTON;
    		tbb[3].idCommand = ID_RECORD_SEARCH;
    
    		SendMessage(htool, TB_ADDBUTTONS, sizeof(tbb)/sizeof(TBBUTTON), (LPARAM)&tbb);
    
    		
    		GetClientRect (hwnd, &rc);
    		statwidths [0] = rc.right / 3;
    		statwidths [1] = 1 * rc.right / 3;
    		statwidths [2] = -1;
    		SendMessage(hstatus, SB_SETPARTS, sizeof(statwidths)/sizeof(int), (LPARAM)statwidths);
    		SendMessage(hstatus, SB_SETTEXT, 0, (LPARAM)"Address Book");
    Not this works fine in that it displays a rebar with a button and a combobox as expected. However when I try and introduce my toolbars to the rebar by replacing the lines:

    Code:
    htoolMove=CreateWindowEx(0,
                                    TEXT("BUTTON"),
                                    TEXT("Button"),WS_CHILD|WS_VISIBLE,
                                    164,4,100,20,hwndRB,0,hInstance,0);
    and

    Code:
    htool=CreateWindowEx(0,
                                      TEXT("COMBOBOX"),
                                      0,WS_CHILD|WS_VISIBLE|CBS_DROPDOWN,
                                      40,4,100,60,hwndRB,0,hInstance,0);
    with

    Code:
    htoolMove = CreateWindowEx(0, TOOLBARCLASSNAME, NULL, WS_CHILD | WS_VISIBLE, 0, 0, 0, 0,
    			hwndRB, (HMENU)IDC_MAIN_TOOL, GetModuleHandle(NULL), NULL);
    and

    Code:
     htool = CreateWindowEx(0, TOOLBARCLASSNAME, NULL, WS_CHILD | WS_VISIBLE, 0, 0, 0, 0,
    			hwndRB, (HMENU)IDC_MOVE_TOOLBAR, GetModuleHandle(NULL), NULL);
    it all starts to go wrong. Basically, the rebar no longer seems to appear. Instead there are just the toolbars as before. And also as before, one is over the top of the other. Anyone know why this is?

    EDIT: I realise that the code I am substituting in is actually repeated further up the code. The whole thing is a bit messy at the minute until I can work out how this rebar stuff works

    Thanks
    Last edited by minesweeper; 06-14-2003 at 06:29 PM.

  4. #4
    erstwhile
    Join Date
    Jan 2002
    Posts
    2,227
    Create the toolbars with the CCS_NORESIZE and CCS_NODIVIDER styles. The latter is optional; it just stops a line being drawn at the top of the toolbar.

    Also set the cyMinChild parameter of the REBARBANDINFO struct to some suitable value to accomodate each toolbar - using GetClientRect is no good because you are creating the toolbars with dimensions (0,0,0,0).

    edit: making sense of 'latter'
    Last edited by Ken Fitlike; 06-15-2003 at 12:43 AM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Rebar and ToolBars
    By underline_bruce in forum Windows Programming
    Replies: 4
    Last Post: 05-25-2007, 09:48 PM
  2. Text Only Toolbars
    By b00l34n in forum Windows Programming
    Replies: 2
    Last Post: 03-11-2005, 01:49 PM
  3. How do I implement Toolbars?
    By shanedudddy2 in forum C++ Programming
    Replies: 0
    Last Post: 01-26-2003, 08:23 PM
  4. Dynamic Toolbars
    By nvoigt in forum Windows Programming
    Replies: 1
    Last Post: 01-11-2002, 09:21 AM
  5. Toolbars ... Rebars... whatever!... ...
    By Unregistered in forum Windows Programming
    Replies: 2
    Last Post: 11-19-2001, 07:44 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21