Solved

OnSize questions

Posted on 2002-07-18
5
559 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
VB.NET how to use the Vertical ScrollBar 5 90
conditional code and condition difference 9 77
withoutTen challenge 14 99
unix example issues 18 75
This is to be the first in a series of articles demonstrating the development of a complete windows based application using the MFC classes.  I’ll try to keep each article focused on one (or a couple) of the tasks that one may meet.   Introductio…
Introduction: Dialogs (2) modeless dialog and a worker thread.  Handling data shared between threads.  Recursive functions. Continuing from the tenth article about sudoku.   Last article we worked with a modal dialog to help maintain informat…
This Micro Tutorial will give you a basic overview how to record your screen with Microsoft Expression Encoder. This program is still free and open for the public to download. This will be demonstrated using Microsoft Expression Encoder 4.
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.

910 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

20 Experts available now in Live!

Get 1:1 Help Now