Solved

Change toolbar at runtime

Posted on 1998-12-17
12
347 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

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
 

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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
MFC Dialog 9 54
ASCII Non-Printable characters/codes and their HTML equivalents 6 159
ffmpeg - "rtsp://...... Operation not permitted" 4 92
canBalance challenge 34 112
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.

759 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