[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now

x
?
Solved

Problem using CWnd::RepositionBars()-method

Posted on 1999-01-15
5
Medium Priority
?
1,550 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 360 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

Ask an Anonymous Question!

Don't feel intimidated by what you don't know. Ask your question anonymously. It's easy! Learn more and upgrade.

Question has a verified solution.

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

In this article, I'll describe -- and show pictures of -- some of the significant additions that have been made available to programmers in the MFC Feature Pack for Visual C++ 2008.  These same feature are in the MFC libraries that come with Visual …
Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
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 this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…

650 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