Solved

Problem using CWnd::RepositionBars()-method

Posted on 1999-01-15
5
1,429 Views
Last Modified: 2013-11-20
I am trying to use a CToolBar in a dialog based app. I followed the hints I found on the MSDN library, but the result is quite strange.
I used the following code in the dialogs OnInitDialog-method:
...
if (!m_toolBar.Create(this) ||
      !m_toolBar.LoadToolBar(IDR_TOOLBAR))
    return -1;

m_toolBar.SetBarStyle(m_toolBar.GetBarStyle()     | CBRS_TOOLTIPS | CBRS_FLYBY | CBRS_SIZE_DYNAMIC);

  CRect rcClientStart;
  CRect rcClientNow;
  GetClientRect(rcClientStart);
  /* the following line is the problem !! */
  RepositionBars(AFX_IDW_CONTROLBAR_FIRST,
                 AFX_IDW_CONTROLBAR_LAST,
                 reposQuery, 0, rcClientNow);

  CPoint ptOffset(rcClientStart.left - rcClientNow.left,
                  rcClientStart.top - rcClientNow.top);
  ptOffset.y += ::GetSystemMetrics(SM_CYMENU);
  CRect rcChild;
  CWnd* pwndChild = GetWindow(GW_CHILD);
  while (pwndChild)
  {
    pwndChild->GetWindowRect(rcChild);
    rcChild.OffsetRect(ptOffset);
    pwndChild->MoveWindow(rcChild, FALSE);
    pwndChild = pwndChild->GetNextWindow();
  }

  CRect rcWindow;
  GetWindowRect(rcWindow);
  rcWindow.right += rcClientStart.Width() - rcClientNow.Width();
  rcWindow.bottom += rcClientStart.Height() - rcClientNow.Height();
  MoveWindow(rcWindow, FALSE);

  RepositionBars(AFX_IDW_CONTROLBAR_FIRST,
                 AFX_IDW_CONTROLBAR_LAST,
                 0);

The result is that the window gets very very big and none of the other controls on the dialog is displayed. Only the toolbar appears. When I used the debugger to figure out the problem I saw that the CWnd::RepositionBars()-method returns very strange values in the CRect object (rcClientNow).
They were -85726373 to 87637362 or something like that. Do you know what I made wrong?

Regards

Thorsten
0
Comment
Question by:klusi
  • 3
  • 2
5 Comments
 
LVL 3

Expert Comment

by:plaroche
Comment Utility
Your rcClientNow variable is not initialized.

The values you see are for an unitilialized CRect. Check the code for yourself.
0
 

Author Comment

by:klusi
Comment Utility
I changed initialization of the CRect objects as follows:
  CRect rcClientStart(0,0,0,0);
  CRect rcClientNow(0,0,0,0);

The result is, that I now can see the other controls in the dialog but the window is still much too big. And the debugger shows that the CRect rcClientNow contains 0,0,0,0. But if I look into the documentation for RepositionBars, it tells me that in the parameter lpRectParam the new size of the client area should be stored.
0
 
LVL 3

Expert Comment

by:plaroche
Comment Utility
You're missing one argument I think, here's the doc I have for repositionbars:

void RepositionBars( UINT nIDFirst, UINT nIDLast, UINT nIDLeftOver, UINT nFlag = CWnd::reposDefault, LPRECT lpRectParam = NULL, LPCRECT lpRectClient = NULL, BOOL bStretch = TRUE );


nIDLeftOver is the argument you're missing.

Your code looks like nIDLeftOver will be reposQuery, that might be the mistake.
0
 

Author Comment

by:klusi
Comment Utility
I can't read any answer.
0
 
LVL 3

Accepted Solution

by:
plaroche earned 120 total points
Comment Utility
Here's my answer again. Try REFRESH on your browser. If you click on the link in your mail reader it won't always reload the page. But why am I writing this? If you can read it you've surely done it!

You're missing one argument I think, here's the doc I have for repositionbars:

void RepositionBars( UINT nIDFirst, UINT nIDLast, UINT nIDLeftOver, UINT nFlag = CWnd::reposDefault, LPRECT lpRectParam = NULL, LPCRECT lpRectClient = NULL, BOOL bStretch = TRUE );


nIDLeftOver is the argument you're missing.

Your code looks like nIDLeftOver will be reposQuery, that might be the mistake.

0

Featured Post

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Introduction: Displaying information on the statusbar.   Continuing from the third article about sudoku.   Open the project in visual studio. Status bar – let’s display the timestamp there.  We need to get the timestamp from the document s…
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…
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.
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

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

18 Experts available now in Live!

Get 1:1 Help Now