• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 556
  • Last Modified:

How to allow resize of a dialog but limit the size to muliples of 253 pixels

I'm using VS 6.0 with MFC and have a dialog that can be resized.

I want to set the Client area size to multiples of 253 pixels in the X direction.

Example: If the user drags the size to be  520 pixels wide and lets go of the mouse button,  the program should force a client area of 506 pixels.


As I'm using MFC I'm not sure where I need to call SetWindowsPos()  

Is it in the OnSize() ?
0
hansw77041
Asked:
hansw77041
  • 3
  • 2
1 Solution
 
kaylanreilorCommented:
Of course, OnSize() which handles WM_SIZE.
0
 
hansw77041Author Commented:
Well Yes of course is not much help   !

OnSize() has these words in the help file.

Quote" If you call the base-class implementation of this function, that implementation will use the parameters originally passed with the message and not the parameters you supply to the function." end quote

So I'm confused about when and where and if I should be using SetWindowsPos() from within the OnSize()
0
 
hansw77041Author Commented:
Using   SetWindowPos(0,0,0,506,cy, SWP_NOMOVE | SWP_NOZORDER);  form inside of OnSize() blows the stack. !

So it's NOT      Yes Of Course      

Please don't reply if you don't know the answer and save us all some time...
0
Receive 1:1 tech help

Solve your biggest tech problems alongside global tech experts with 1:1 help.

 
kaylanreilorCommented:
WM_SIZE is followed by WM_PAINT, so probably you could store the coordinates in OnSize to draw your window in OnPaint().
0
 
alb66Commented:
You can handle WM_SIZING message instead without any call to SetWindowPos:

BEGIN_MESSAGE_MAP(CMainFrame, CFrameWnd)
      ON_WM_SIZING()
END_MESSAGE_MAP()

void CMainFrame::OnSizing(UINT fwSide, LPRECT pRect)
{
      CFrameWnd::OnSizing(fwSide, pRect);

      int nWidth = pRect->right - pRect->left;
      
      nWidth = ( nWidth / 253 ) * 253;

      switch ( fwSide )
      {
      case WMSZ_BOTTOMRIGHT:
      case WMSZ_RIGHT:
      case WMSZ_TOPRIGHT:
            pRect->right = pRect->left + nWidth;
            break;
      default:
            pRect->left = pRect->right - nWidth;
            break;
      }
}
0
 
hansw77041Author Commented:
Thanks that did the trick.
0

Featured Post

Receive 1:1 tech help

Solve your biggest tech problems alongside global tech experts with 1:1 help.

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now