CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 1 of 1
  1. #1
    Join Date
    Apr 2005
    Posts
    1,828

    Repositioning a toolbar

    I have developed an Internet Explorer Addin using this link

    http://www.codeproject.com/KB/shell/...d&fr=726#xx0xx

    I have added multiple buttons along with the search button. Now my aim is to display those buttons before the searchbar (except of the search button).

    In order to accompalish this, the best solution that I could possibly think of is is making 2 toolbar objects and in the onsize handler moving them correctly and sizing them correctly within the deskband.

    So at OnCreate function this is how the buttons and toolbar are getting added

    Code:
    LRESULT CMFToolbar::OnCreate(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
    {
    // buttons with images and text
    	SendMessage(m_hWnd, TB_SETEXTENDEDSTYLE, 0, (LPARAM)TBSTYLE_EX_MIXEDBUTTONS);
    	// Sets the size of the TBBUTTON structure.
    	SendMessage(m_hWnd, TB_BUTTONSTRUCTSIZE, sizeof(TBBUTTON), 0);
    	// Set the maximum number of text rows and bitmap size.
    	SendMessage(m_hWnd, TB_SETMAXTEXTROWS, 1, 0L);
    
    	SendMessage(m_hWnd, TB_SETROWS, MAKEWPARAM(1, 0), (LPARAM)NULL);
    
    	SendMessage(m_hWnd, TB_SETEXTENDEDSTYLE, 0, (LPARAM)TBSTYLE_EX_DRAWDDARROWS);
    
    // add our button's caption to the toolbar window
    	TCHAR* pCaption = _T("Members");
    	int iIndex = ::SendMessage(m_hWnd, TB_ADDSTRING, 0,(LPARAM)pCaption);	
    
    	TCHAR* pCaption1 = _T("Forums");
    	int iIndex1 = ::SendMessage(m_hWnd, TB_ADDSTRING, 0,(LPARAM)pCaption1);
    
    	TCHAR* pCaption3 = _T("U-2-Me help");
    	int iIndex3 = ::SendMessage(m_hWnd, TB_ADDSTRING, 0,(LPARAM)pCaption3);
    
    HICON hMotley = LoadIcon(_Module.GetResourceInstance(), MAKEINTRESOURCE(IDI_ICON_RESEARCH));
    	m_hImageList = ImageList_Create(16,16, ILC_COLOR32, 1, 0);
    	int iImageIndex = ImageList_AddIcon(m_hImageList, hMotley);
    
    	// Forums
    	HICON hForums = LoadIcon(_Module.GetResourceInstance(), MAKEINTRESOURCE(IDI_ICON_FORUMS));
    	int iImageIndex1 = ImageList_AddIcon(m_hImageList, hForums);
    
    	// Help
    	HICON hhelp = LoadIcon(_Module.GetResourceInstance(), MAKEINTRESOURCE(IDI_ICON_HELP));
    	int iImageIndex3 = ImageList_AddIcon(m_hImageList, hhelp);
    
    
    DestroyIcon(hMotley);
    	DestroyIcon(hForums);
    	DestroyIcon(hhelp);
    
    // Set the toolbar's image
    	::SendMessage(m_hWnd, TB_SETIMAGELIST, 0, (LPARAM)m_hImageList);
    
    	// add the button for the toolbar to the window
    	TBBUTTON Button;
    	ZeroMemory((void*)&Button, sizeof(TBBUTTON));
    	Button.idCommand = IDM_GETQUOTE;
    	Button.fsState = TBSTATE_ENABLED;
    	Button.fsStyle = TBSTYLE_BUTTON | TBSTYLE_AUTOSIZE | TBSTYLE_DROPDOWN;
    	Button.dwData = 0;
    	Button.iString = NULL;
    	Button.iBitmap = iImageIndex;
    	::SendMessage(m_hWnd, TB_INSERTBUTTON, 0, (LPARAM)&Button);	
    
    	TBBUTTON Button1;
    	ZeroMemory((void*)&Button1, sizeof(TBBUTTON));
    	Button1.idCommand = IDM_FORUM;
    	Button1.fsState = TBSTATE_ENABLED;
    	Button1.fsStyle = BTNS_BUTTON | BTNS_AUTOSIZE | BTNS_SHOWTEXT | TBSTYLE_TRANSPARENT/*| BTNS_DROPDOWN*/;
    	Button1.dwData = 0;
    	Button1.iString = iIndex1;
    	Button1.iBitmap = iImageIndex1;
    	::SendMessage(m_hWnd, TB_INSERTBUTTON, 1, (LPARAM)&Button1);
    
    	TBBUTTON Button4;
    	ZeroMemory((void*)&Button4, sizeof(TBBUTTON));
    	Button4.idCommand = IDM_MEMBERS;
    	Button4.fsState = TBSTATE_ENABLED;
    	Button4.fsStyle = BTNS_BUTTON | BTNS_AUTOSIZE | BTNS_SHOWTEXT | TBSTYLE_TRANSPARENT/*| BTNS_DROPDOWN*/;
    	Button4.dwData = 0;
    	Button4.iString = iIndex4;
    	Button4.iBitmap = iImageIndex4;
    	::SendMessage(m_hWnd, TB_INSERTBUTTON, 4, (LPARAM)&Button4);
    
    // create our EditQuote window and set the font.
    	RECT rect = {0,0,0,0};
    	m_EditWnd.Create(m_hWnd, rect, NULL, WS_CHILD|WS_VISIBLE, WS_EX_CLIENTEDGE);
    	m_EditWnd.SetFont(static_cast<HFONT>(GetStockObject(DEFAULT_GUI_FONT)));
    
    // 2nd Toolbar
    	RECT rect1 = {0,0,0,0};
    	m_EditWnd1.Create (m_hWnd, rect1, NULL, WS_CHILD|WS_VISIBLE, WS_EX_CLIENTEDGE);
    	m_EditWnd1.SetFont(static_cast<HFONT>(GetStockObject(DEFAULT_GUI_FONT)));
    	return 0;
    }

    Now at OnSize method, this is how I position the toolbar

    Code:
    LRESULT CMFToolbar::OnSize(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
    {
    	// based on the size of the window area minus the size of the toolbar button, 
    	// indent the toolbar so that we can place the edit box before the toolbar 
    	// button. This will right justify the toolbar button in the toolbar and the 
    	// edit box will use the vaction space to the left of the button but after the 
    	// toolbar text as it's usable space.
    	
    	RECT wndRect, wndRect1, btnRect;
    	GetClientRect(&wndRect);
    	::SendMessage(m_hWnd, TB_GETITEMRECT, 0, (LPARAM)&btnRect);
    	SendMessage(TB_SETINDENT, 300);
    	SendMessage(TB_SETROWS,1);
    	// put a small spacing gap between the edit box's right edge and the toolbar button's left edge
    
    	wndRect1 = wndRect;
    	wndRect.right = 1050;
    	wndRect.left = 750;
    
    	wndRect1.right = 300;
    
    	btnRect.left = wndRect.left;
    	m_EditWnd.MoveWindow(&wndRect, FALSE);
    	m_EditWnd1.MoveWindow(&wndRect1, FALSE);
    
    	return 0;
    }
    But if you look at the result (first image), this is not what I want. The toolbar should be the way mentioned in 2nd image. Where the member's searchbar and the editbox should be in the end and all the buttons should be polaced first

    So what all changes do I have to make in order to get the desired result?

    Thanks in Advance
    Last edited by maverick786us; July 12th, 2010 at 01:18 AM.

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