Solved

Change toolbar at runtime

Posted on 1998-12-17
12
343 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
Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

 

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

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Replacement selected text 2 47
Tab names are off by one 5 49
sum28 challenge 31 96
Line meaning 9 77
Introduction: The undo support, implementing a stack. Continuing from the eigth article about sudoku.   We need a mechanism to keep track of the digits entered so as to implement an undo mechanism.  This should be a ‘Last In First Out’ collec…
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
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.
This video discusses moving either the default database or any database to a new volume.

744 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

13 Experts available now in Live!

Get 1:1 Help Now