CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Join Date
    Jun 2013
    Posts
    20

    Rebar not visible

    I am making a paint program and I created a toolbar with my own images that works fine but I tried adding a rebar to it everything compiles fine but only the toolbar shows up not the rebar.

    Code:
     #define NUMBUTTONS 3
    
    HWND CreateToolBar(HWND hWndParent)
    {
    	
    	TBBUTTON buttons[NUMBUTTONS];
    
    	HIMAGELIST himlToolBar = ImageList_LoadImage(
    		m_hInst,
    		MAKEINTRESOURCE(IDB_BITMAP1),
    		16,
    		1,
    		RGB(255, 0, 255),
    		IMAGE_BITMAP,
    		LR_CREATEDIBSECTION);
    
    	
    	hWndToolBar = CreateWindowEx(0, TOOLBARCLASSNAME, NULL,WS_CHILD | WS_VISIBLE |TBSTYLE_FLAT  , 0, 0, 1, 1, hWndParent, NULL, m_hInst, NULL);
    
    	SendMessage(hWndToolBar, TB_SETIMAGELIST, 0, (LPARAM)himlToolBar);
    
    	for(int i = 0; i < NUMBUTTONS; ++i)
    	{
    		buttons[i].iBitmap = i;
    		buttons[i].fsState = TBSTATE_ENABLED;
    		buttons[i].fsStyle = TBSTYLE_BUTTON;
    		buttons[i].dwData = 0L;
    		buttons[i].iString = (INT_PTR)L"New";
    		buttons[i].idCommand = 0;
    	}
    
    	SendMessage(hWndToolBar, TB_BUTTONSTRUCTSIZE, (WPARAM)sizeof(TBBUTTON), 0);
    
    	SendMessage(hWndToolBar, TB_ADDBUTTONS, (WPARAM)NUMBUTTONS, (LPARAM)&buttons);
    
    	SendMessage(hWndToolBar, TB_AUTOSIZE, 0, 0);
    
    	return hWndToolBar;
    }

    Code:
    HWND CreateRebar(HWND hWndOwner, HWND hWndToolbar)
    {
    	if(hWndToolbar == NULL)
    	{
    		return NULL;
    	}
    
    	INITCOMMONCONTROLSEX icex;
    	icex.dwSize = sizeof(INITCOMMONCONTROLSEX);
    	icex.dwICC = ICC_COOL_CLASSES | ICC_BAR_CLASSES;
    	InitCommonControlsEx(&icex);
    
    	hWndRebar = CreateWindowEx(WS_EX_TOOLWINDOW,
    		REBARCLASSNAME,
    		NULL,
    		WS_CHILD | WS_VISIBLE | WS_CLIPSIBLINGS |
    		WS_CLIPCHILDREN | RBS_VARHEIGHT |
    		CCS_NODIVIDER | RBS_BANDBORDERS,
    		0, 0, 0, 0,
    		hWndOwner,
    		NULL,
    		m_hInst,
    		NULL);
    
    	if(!hWndRebar)
    	{
    		return NULL;
    	}
    
    	REBARBANDINFO rbBand = { sizeof(REBARBANDINFO) };
    	rbBand.fMask = 
    		RBBIM_STYLE
    		| RBBIM_TEXT
    		| RBBIM_CHILD
    		| RBBIM_CHILDSIZE
    		| RBBIM_SIZE;
    	rbBand.fStyle = RBBS_CHILDEDGE | RBBS_GRIPPERALWAYS;
    
    	DWORD dwBtnSize = (DWORD)SendMessage(hWndToolbar, TB_GETBUTTONSIZE, 0, 0);
    
    	rbBand.lpText = TEXT("");
    	rbBand.hwndChild = hWndToolbar;
    	rbBand.cyChild = LOWORD(dwBtnSize);
    	rbBand.cxMinChild = NUMBUTTONS * HIWORD(dwBtnSize);
    	rbBand.cyMinChild = LOWORD(dwBtnSize);
    
    	rbBand.cx = 0;
    
    	SendMessage(hWndRebar, RB_INSE*****D, (WPARAM)-1, (LPARAM)&rbBand);
    
    	return (hWndRebar);
    
    }

    Code:
    HRESULT InitializeWindow(HINSTANCE hInstance)
    {
    
        HRESULT hr = S_OK;
    	m_hInst = hInstance;
        // Create WIC factory
        hr = CoCreateInstance(
            CLSID_WICImagingFactory,
            NULL,
            CLSCTX_INPROC_SERVER,
            IID_PPV_ARGS(&m_pIWICFactory)
            );
    
        // Register window class
        WNDCLASS wcex;
        if (SUCCEEDED(hr))
        {
    	
            wcex.style         = CS_HREDRAW | CS_VREDRAW;
    		wcex.lpfnWndProc   = (WNDPROC)WndProc;
            wcex.cbClsExtra    = 0;
            wcex.cbWndExtra    = sizeof(LONG_PTR);
            wcex.hInstance     = hInstance;
    		wcex.hIcon         = NULL;
            wcex.hCursor       = LoadCursor(NULL, IDC_ARROW);
    		wcex.hbrBackground = (HBRUSH)::GetStockObject(WHITE_BRUSH);
    		wcex.lpszMenuName  = 0;
            wcex.lpszClassName = L"WICViewerGDI";
           
    
    
          
    
            hr = RegisterClass(&wcex) ? S_OK : E_FAIL;
        }
    
        if (SUCCEEDED(hr))
        {
    
    		
            // Create window
             ghMainWnd = CreateWindow(
                L"WICViewerGDI",
                L"PaintProgram",
                WS_OVERLAPPEDWINDOW | WS_VISIBLE,
                CW_USEDEFAULT,
                CW_USEDEFAULT,
                1920,
                1080,
                NULL,
    			NULL,
                hInstance,
                0
                );
    
    		 hr = ghMainWnd ? S_OK : E_FAIL;
    
    		 ShowWindow(ghMainWnd, SW_SHOW);
    		 UpdateWindow(ghMainWnd);
    
    		 
        }
    
    	CreateRebar(ghMainWnd, hWndToolBar);
    	CreateToolBar(ghMainWnd);
    	
        return hr;
    }

    I cant seem to figure it out any help is appreciated.

  2. #2
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,396

    Re: Rebar not visible

    Did you debug your code?
    What does the CreateRebar() function return? Is it, perhaps, NULL? Then you have to call GetLastError to get the extended error information.
    Victor Nijegorodov

  3. #3
    Join Date
    Jun 2013
    Posts
    20

    Re: Rebar not visible

    Quote Originally Posted by VictorN View Post
    Did you debug your code?
    What does the CreateRebar() function return? Is it, perhaps, NULL? Then you have to call GetLastError to get the extended error information.

    I figured it out it was
    Code:
     REBARBANDINFO rbBand = { sizeof(REBARBANDINFO) };
    the msdn example I followed stated to do it this way but it is older code and someone stated it has to be done like this
    Code:
    REBARBANDINFO rbBand = { sizeof(REBARBANDINFO_V3_SIZE) };
    when used on operating system greater than XP because it doesn't return the same value.

    also I had to set the REBARBANDINFOS'S cbsize variable to REBARBANDINFO_V3_SIZE.

    I swear everytime I follow an example on msdn I always have to spend hours trying to fix the code because it is all older code.



    Thanks anyway.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured