Solved

Problem using CWnd::RepositionBars()-method

Posted on 1999-01-15
5
1,469 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

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Expand to include initial dialog with two choices. 9 76
iSeries DB2 Query 2 95
sum13 challenge 24 104
My project did see openJDK that I installed. What could be the problem 7 140
Introduction: Hints for the grid button.  Nested classes, templated collections.  Squash that darned bug! Continuing from the sixth article about sudoku.   Open the project in visual studio. First we will finish with the SUD_SETVALUE messa…
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.
Windows 10 is mostly good. However the one thing that annoys me is how many clicks you have to do to dial a VPN connection. You have to go to settings from the start menu, (2 clicks), Network and Internet (1 click), Click VPN (another click) then fi…

816 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

9 Experts available now in Live!

Get 1:1 Help Now