Solved

Problem using CWnd::RepositionBars()-method

Posted on 1999-01-15
5
1,493 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Complete beginner needs help making a cron job 9 131
WinWaitActive parameters 12 31
sameEnds challenge 3 187
how to use laptop or pad camera in vb.net windows application 2 108
Here is how to use MFC's automatic Radio Button handling in your dialog boxes and forms.  Beginner programmers usually start with a OnClick handler for each radio button and that's just not the right way to go.  MFC has a very cool system for handli…
Introduction: Finishing the grid – keyboard support for arrow keys to manoeuvre, entering the numbers.  The PreTranslateMessage function is to be used to intercept and respond to keyboard events. Continuing from the fourth article about sudoku. …
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.

726 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