Solved

Change toolbar at runtime

Posted on 1998-12-17
12
344 Views
Last Modified: 2013-11-20
How can I change a toolbar at runtime of a program? If I use the following code:
int CMainFrame::ChangeToolBar (UINT id)
{
  return m_wndToolBar.LoadToolBar (id);
}
The buttons of the toolbar will be changed, but the frame of the toolbar won't be changed.
What's going wrong?
0
Comment
Question by:rw5736
12 Comments
 
LVL 6

Expert Comment

by:snoegler
ID: 1326287
What do you mean with 'the frame of the toolbar won't be changed'?
0
 
LVL 15

Expert Comment

by:Tommy Hui
ID: 1326288
Try this

int CMainFrame::ChangeToolBar (UINT id)
{
  int rv = m_wndToolBar.LoadToolBar (id);

  CRect r;
  GetWindowRect(&r);

  MoveWindow(r, FALSE);

  return rv;
}
0
 

Expert Comment

by:LeeRoy
ID: 1326289
Try this:

void CMainFrame::OnToolbar()
{
      CToolBar* pt=(CToolBar*)GetControlBar(AFX_IDW_TOOLBAR);
      pt->LoadToolBar(IDR_TOOLBAR1);
      CSize s=pt->CalcFixedLayout(FALSE,TRUE);
      pt->MoveWindow(0,-2,s.cx,s.cy,TRUE);
      pt->Invalidate();
}

0
 

Author Comment

by:rw5736
ID: 1326290
Hi thui!
Your suggestion won't be work. I think this causes on following thing. GetWindowRect returns the dimensions in screen coordinates and MoveWindow needs the dimensions relative to the upper-left corner of the parent window's client area (in this context).
Thanks

Hi snoegler!
If there are a different count of buttons in the origin and new toolbar the new toolbar got a new size. But the size of the frame which enclose the toolbar will be unchanged.

Hi LeeRoy!
Your solution works principally. But if I change the position of a floating toolbar the toolbar always will be placed at the upper-left corner.

Bye René
0
 

Author Comment

by:rw5736
ID: 1326291
The solution doesn't work. I think this causes on followng thing. GetWindowRect returns the dimensions related to the screen and MoveWindow need dimensions related to the upper-left corner of the parent window's area.
0
 
LVL 12

Expert Comment

by:migel
ID: 1326292
Hi!

Try this:

int CMainFrame::ChangeToolBar (UINT id)
    {
      m_wndToolBar.LoadToolBar (id);
     RecalcLayout(FALSE)
     }
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

Author Comment

by:rw5736
ID: 1326293
Hi migel!

It works. Thanks a lot.
0
 
LVL 12

Expert Comment

by:migel
ID: 1326294
Can i answer?
0
 

Author Comment

by:rw5736
ID: 1326295
I would you give the points, but I don't know how can I do this. My options are
  1. Increase points to ...
  2. Have a comment to add?
What should I do to give you the points?
0
 
LVL 12

Accepted Solution

by:
migel earned 100 total points
ID: 1326296
Just accept this answer:
int CMainFrame::ChangeToolBar (UINT id)
          {
            m_wndToolBar.LoadToolBar (id);
           RecalcLayout(FALSE)
           }
0
 

Author Comment

by:rw5736
ID: 1326297
I would you give the points, but I don't know how can I do this. My options are
  1. Increase points to ...
  2. Have a comment to add?
What should I do to give you the points?
0
 

Author Comment

by:rw5736
ID: 1326298
Okay
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
List out all word 7 259
centeredAverage challenge 8 131
fizzArray  challenge 1 63
wordappend challenge 8 147
Here is how to use MFC's automatic Radio Button handling in your dialog boxes and forms.  Beginner programmers usually start with a OnClick handler for each radio button and that's just not the right way to go.  MFC has a very cool system for handli…
If you use Adobe Reader X it is possible you can't open OLE PDF documents in the standard. The reason is the 'save box mode' in adobe reader X. Many people think the protected Mode of adobe reader x is only to stop the write access. But this fe…
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.

910 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

27 Experts available now in Live!

Get 1:1 Help Now