Thread: cannot insert toolbar into rebar

  1. #1
    Registered User
    Join Date
    Mar 2009
    Posts
    8

    cannot insert toolbar into rebar

    Hi there, I'm trying to insert a toolbar into a rebar and I can't seem to do it properly. This is my code so far...

    Code:
    //common controls are initiated in the main function
    
    HWND CreateToolbar(HWND hwnd)
    {
    
    
        // Create the toolbar.
        HWND hToolbar = CreateWindowEx(0, TOOLBARCLASSNAME, NULL, 
            WS_CHILD | TBSTYLE_WRAPABLE | CCS_NORESIZE ,
            0, 0, 0, 0,
            hwnd, NULL, (HINSTANCE)GetWindowLong( hwnd, GWL_HINSTANCE), NULL);
        if (hToolbar == NULL)
        {
    		MessageBoxW( hwnd, L"Toolbar not created", NULL, MB_OK );	 //Check return value of status bar to make sure it's been created
    		return false;
        }
    
    
        // Tell the toolbar to resize itself, and show it.
        SendMessage(hToolbar, TB_AUTOSIZE, 0, 0); 
        ShowWindow(hToolbar, TRUE);
    
            
        return hToolbar;
    }
    
    
    HWND CreateRebar (HWND hwnd) 
    {
        // Create the rebar.
        HWND hRebar = CreateWindowEx(WS_EX_TOOLWINDOW,
            REBARCLASSNAME,
            NULL,
            WS_CHILD | WS_VISIBLE | WS_CLIPSIBLINGS |
            WS_CLIPCHILDREN | RBS_VARHEIGHT |
            CCS_NODIVIDER | RBS_BANDBORDERS,
            0,0,0,0,
            hwnd,
            NULL,
            (HINSTANCE)GetWindowLong( hwnd, GWL_HINSTANCE ),
            NULL);
    
    	if (hRebar == NULL)
            {
    		MessageBoxW( hwnd, L"Rebar not created", NULL, MB_OK );	 //Check return value of status bar to make sure it's been created
    		return false;
            }
    
    
    	REBARINFO ri;
    	ri.cbSize	= sizeof (ri);
    	ri.fMask	= 0;
    	ri.himl		= NULL;
    
    	SendMessage( hRebar, RB_SETBARINFO, 0, (LPARAM)&ri);
    
    	HWND hToolbar = CreateToolbar(hRebar);
    
    	if (hToolbar == NULL)
            {
    		MessageBoxW( hwnd, L"Toolbar not created (rebar function)", NULL, MB_OK );	 //Check return value of status bar to make sure it's been created
    		return false;
            }
    
    
    	REBARBANDINFO rbBand;
    
    	rbBand.cbSize = sizeof(REBARBANDINFO);
    	rbBand.fMask = RBBIM_CHILDSIZE | RBBIM_CHILD;
    	rbBand.hwndChild = hToolbar;
            rbBand.cyMaxChild	= 500;	
    	rbBand.cyMinChild	= 100;
    	rbBand.cyChild	= 200;
    	rbBand.cx		= 200;
    
    	
    	if(!SendMessage(hRebar, RB_INSERTBAND, (WPARAM)-1, (LPARAM)&rbBand))
    		MessageBeep(0);	
    
    
    	return hRebar;
    }

    When I run this code I cannot see the toolbar. I get a message beep so I know the problem must be when I insert the band. What am I doing wrong?

    EDIT:

    If I add this to my main.cpp before WinMain...

    Code:
    #define VC_EXTRALEAN
    #define _WIN32_WINNT 0x0501
    #define WINVER 0x0501
    I no longer get the error beep but I still can't see the rebar.
    Last edited by supernater; 05-30-2009 at 07:01 PM.

  2. #2
    Registered User
    Join Date
    Apr 2007
    Posts
    137
    It's a Win32 FAQ (See Google Groups, Win32)

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. toolbar button question
    By supernater in forum Windows Programming
    Replies: 1
    Last Post: 05-25-2009, 08:24 PM
  2. How to insert an item to a ListView
    By ysabelle in forum C++ Programming
    Replies: 2
    Last Post: 05-07-2007, 07:03 AM
  3. Dockable Toolbar (Like taskbar or office toolbar)
    By om3ga in forum Windows Programming
    Replies: 2
    Last Post: 11-20-2005, 03:09 AM
  4. Insert unique record into database
    By groorj in forum C Programming
    Replies: 4
    Last Post: 12-29-2004, 11:06 AM
  5. Tooltip won't display over toolbar button
    By minesweeper in forum Windows Programming
    Replies: 5
    Last Post: 06-20-2003, 01:21 AM