Solved

OnSize questions

Posted on 2002-07-18
5
558 Views
Last Modified: 2013-11-20
I'm using OnSize to make a dialog resizeable.
So, in OnSize I compute where the various
buttons, etc need to be, given the size of the
panel.  Its working except for details.  

A few questions:

1) How can I call my OnSize code once when the
   panel is popped.  All the widgets in the panel
   jump just a bit when you first start to resize
   it.  If I could just resize once when the dialog
   is brought up, it would be fine.  Note: bad idea
   to call OnSize in OnInitDialog.

2) I  must be missing something simple, but I don't
   get this:  In Visual Studio, when I am laying out
   a panel, it shows (near lower right) the position
   and size of the control in pixels.  However, If
   I use those pixels values in my OnSize code, the
   control doesn't move to the same place.  By
   experimenting, I found that if I use 1.5 times
   the value I recorded while in dialog design, it
   works fine.  What is this factor of 1.5?

3) I declared the border of the dialog to be "resizing"
   and it works, but there's no visual clue (in the style
   of the border) that it is resizeable.  How do you get
   that little "textured triangle" at the lower right
   of the border, as I see on many applications? (e.g.
   on the IE window that I'm staring at now)

Thanks!
0
Comment
Question by:tullhead
  • 3
  • 2
5 Comments
 
LVL 37

Expert Comment

by:zzynx
ID: 7164406
1) I use the following 'trick' in OnInitDialog():

  WINDOWPLACEMENT wndpl;
  CRect rect;
  GetWindowPlacement(&wndpl);
  rect = wndpl.rcNormalPosition;
  rect.right++;

2) What you see in VS are Dialog base units.

 // Dialog base unit -> pixel unit conversion macros
 #define DLGUNIT_TO_PIXEL_X(dlgX)     \
  ( (dlgX * LOWORD( ::GetDialogBaseUnits() )) / 4)

 #define DLGUNIT_TO_PIXEL_Y(dlgY)     \
  ( (dlgY * HIWORD( ::GetDialogBaseUnits() )) / 8)

 Also read the info in MSDN on MapDialogRect()

3) For me it works when adding as the last command in my OnSize() function:

m_pWnd->RepositionBars(AFX_IDW_CONTROLBAR_FIRST, AFX_IDW_CONTROLBAR_LAST, 0);
0
 

Author Comment

by:tullhead
ID: 7165570
zzynx --

1) This 'trick' doesn't have any effect for me.  I still
   see a jump when I first resize the window.

2) thanks, I didn't know about "dialog base units" so
   it still seems a bit bizarre, at least I know about
   the issue.

3) The "RepositionBars" didn't have any noticable effect.
   The look of the border on my window stays the same,
   and is just a simple thin border -- the user would not
   suspect that it is resizeable.  There must be some way
   to set the "Style" of the window border....?

You got 1 of 3 and I think you for that, but I'm not
giving the points quite yet.....
0
 
LVL 37

Accepted Solution

by:
zzynx earned 150 total points
ID: 7168712
Hi tullhead,

1) Of course it doesn't have any effect!
   I forgot the most important line.
   Let's try it again:

   WINDOWPLACEMENT wndpl;
   CRect rect;
   GetWindowPlacement(&wndpl);
   rect = wndpl.rcNormalPosition;
   rect.right++;
   MoveWindow(&rect);

   So, in fact you size it 'programmatically'.

3) Of course you have to set the Border Style of your dialog to 'Resizing' ('Styles' tab, combo box: 'Border')
   [But I guess you did that already. Or didn't you?]

Success
0
 

Author Comment

by:tullhead
ID: 7168723
OK, it worked ( #1 )

So you got 2 out of 3 and you get the points!

Still, my dialog's border looks plain (sigh).  Yes,
I did set it to 'resizing' under styles...
Any other idea on this?
0
 
LVL 37

Expert Comment

by:zzynx
ID: 7168745
Hi tullhead,

    >So you got 2 out of 3 and you get the points!
Thank you! Glad I could help you.

    >Yes, I did set it to 'resizing' under styles...
That's what I was afraid of...

    >Any other idea on this?
Maybe the small details make the difference:

In fact this is the Resize() function in which that line is added:

void CMyDialog::Resize()
{
  if (m_first)
  {
    m_bFirst = FALSE;
    return;
  }
  ...
  m_pWnd->RepositionBars(AFX_IDW_CONTROLBAR_FIRST, AFX_IDW_CONTROLBAR_LAST, 0);
}

And this function is called in

BOOL CMyDlg::OnInitDialog()
{
  ...
  Resize();
}

and in

void CMyDlg::OnSize(UINT nType, int cx, int cy)
{
  CDialog::OnSize(nType, cx, cy);
  Resize();
}

m_bFirst is set TRUE in the constructor of CMyDlg.

So, in fact I think this results in what I first told you.

Did you already had a look with 'gripper' or the like in MSDN?
0

Featured Post

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
MFC Dialog 9 47
repeatEnd java challenge 42 83
java ^ examples 8 57
child constructor and parent constructor, overriding and overloading 6 72
Introduction: Dynamic window placements and drawing on a form, simple usage of windows registry as a storage place for information. Continuing from the first article about sudoku.  There we have designed the application and put a lot of user int…
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.
This video discusses moving either the default database or any database to a new volume.

747 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

13 Experts available now in Live!

Get 1:1 Help Now