Solved

Change toolbar at runtime

Posted on 1998-12-17
12
346 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
Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 

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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Introduction: Dynamic window placements and drawing on a form, simple usage of windows registry as a storage place for information. Continuing from the first article about sudoku.  There we have designed the application and put a lot of user int…
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.
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

820 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