Solved

Problem using CWnd::RepositionBars()-method

Posted on 1999-01-15
5
1,485 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
ID: 1327757
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
ID: 1327758
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
ID: 1327759
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
ID: 1327760
I can't read any answer.
0
 
LVL 3

Accepted Solution

by:
plaroche earned 120 total points
ID: 1327761
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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

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.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Detect CR LF to each line 12 170
while loop over for loop 7 115
matchUp  challenge 9 115
x-bar in Google Sheets 2 70
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: Database storage, where is the exe actually on the disc? Playing a game selected randomly (how to generate random numbers).  Error trapping with try..catch to help the code run even if something goes wrong. Continuing from the seve…
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…

856 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