Codejock Forums Homepage
Forum Home Forum Home > Codejock Products > Visual C++ MFC > Command Bars
  New Posts New Posts RSS Feed - Modifying ToolBar During Runtime
  FAQ FAQ  Forum Search   Events   Register Register  Login Login

Modifying ToolBar During Runtime

 Post Reply Post Reply
Author
Message
nguyena1 View Drop Down
Groupie
Groupie


Joined: 28 November 2005
Status: Offline
Points: 16
Post Options Post Options   Thanks (0) Thanks(0)   Quote nguyena1 Quote  Post ReplyReply Direct Link To This Post Topic: Modifying ToolBar During Runtime
    Posted: 08 May 2006 at 3:00pm

What I'm trying to do is have a combo box on the tool bar that I can some what destroy and create during runtime in order to switch styles between CBS_DROPDOWN and CBS_DROPDOWNLIST. 

Problem is:  After its changed, i have to make a mousemove inorder for the combo box to actually come up instead of a grey area. 

What I have inside of CMainFrame::OnCreateControl(LPCREATECONTROLSTRUCT lpCreateControl) for this works great on start up.  FYI:  I make a CXTPControlCustom and do lpCreateControl->pControl = pControlEntry.  I save a pointer to this CXTPControlCustom in my custom combo class.(call it m_pControlEntry)

Here is the code for how I change the combo box. for example from dropdown to dropdown list

//////////////////////////////////////////////////////////// /////////////////////////

 ModifyStyle(CBS_DROPDOWN, CBS_DROPDOWNLIST | WS_VSCROLL);
 
if (this == NULL)
  return FALSE;
 if (this->GetSafeHwnd() == NULL)
  return FALSE;
 CWnd* pParent = this->GetParent();
 if (pParent == NULL)
  return FALSE;
 DWORD dwStyle = this->GetStyle();
 DWORD dwStyleEx = this->GetExStyle();
 CRect rc;
 this->GetDroppedControlRect(&rc);
 pParent->ScreenToClient(&rc);
 UINT nID = this->GetDlgCtrlID();
 CFont* pFont = this->GetFont();
 CWnd* pWndAfter = this->GetNextWindow(GW_HWNDPREV);

 CComboBox comboNew;
 if (!comboNew.CreateEx(dwStyleEx, _T("COMBOBOX"), _T(""),
  dwStyle, rc, AfxGetMainWnd(), nID, lpParam))
  return FALSE;

    comboNew.ShowWindow(SW_HIDE);

    SetOwner(AfxGetMainWnd());

    comboNew.SetFont(pFont);
 this->DestroyWindow();
 HWND hWnd = comboNew.Detach();
 this->Attach(hWnd);

    if (m_pControlEntry)
    {
        m_pControlEntry->SetControl(this);
    }

//////////////////////////////////////////////////////////// ////////////////

So afterwards, theres a grey area until a little after i move my mouse, is there some kind of update i can call?  m_ComboBox for example is the name of the combobox.

I've tried m_ComboBox.RedrawWindow(), Invalidate(), Redraw(), SetVisible, and none of those will do it.

Tony

Back to Top
nguyena1 View Drop Down
Groupie
Groupie


Joined: 28 November 2005
Status: Offline
Points: 16
Post Options Post Options   Thanks (0) Thanks(0)   Quote nguyena1 Quote  Post ReplyReply Direct Link To This Post Posted: 09 May 2006 at 12:28pm

Here is a sample project i've done this to.  For Codejock version 10.1.

Open up ..samples\commandbars\commoncontrols and please replace the mainfrm.cpp, mainfrm.h, and resource.h files and in the res folder, replace OptionsBar.bmp with the 4 files attached here.

What I've done is added a combo box to the options tool bar.  When you click on Hide Vertically, I recreate the combo box to a dropdownlist(see line 633 of mainfrm.cpp).  When you click on Show vertically(see line 683 of mainfrm.cpp), I recreate the combo box to a dropdown style. 

Whats even funnier with this is that, when it does get recreated, the combo box doesnt show any more. If you maximize or minimize, the combo box will show up with the right attributes.  What is the key call that makes this combo box show up?

2006-05-09_122708_FourFiles.zip

Back to Top
 Post Reply Post Reply
  Share Topic   

Forum Jump Forum Permissions View Drop Down

Forum Software by Web Wiz Forums® version 12.04
Copyright ©2001-2021 Web Wiz Ltd.

This page was generated in 0.203 seconds.