Solved

Change toolbar at runtime

Posted on 1998-12-17
12
345 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
ScreenConnect 6.0 Free Trial

Discover new time-saving features in one game-changing release, ScreenConnect 6.0, based on partner feedback. New features include a redesigned UI, app configurations and chat acknowledgement to improve customer engagement!

 

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

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
mixString challenge 36 124
Prevent this page from creating additional dialogs. 3 537
sum67 challenge 35 102
zeroMAx challenge 20 105
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…
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.
In a recent question (https://www.experts-exchange.com/questions/28997919/Pagination-in-Adobe-Acrobat.html) here at Experts Exchange, a member asked how to add page numbers to a PDF file using Adobe Acrobat XI Pro. This short video Micro Tutorial sh…

832 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