Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 626
  • Last Modified:

Resizing a snappable dialog

Hi all,
  I have a View which is a parent of a dialog. This view has a grid on it. Whenever someone moves the dialog, it snaps to the grid. I got that part working fine. But what I can't seem to figure out is how to resize the dialog, having it snap to the grid as it is being resized. I have tried overloading the OnSize message handler of my dialog, and putting this sample line of code in there:

this->MoveWindow(nLeft, nTop, cx, cy);  //cx and cy have been modified corresponding to fit grid.

However, this does not work at all. It does not resize; It only flickers.

Does anyone have any suggestions??

0
v3203
Asked:
v3203
  • 6
  • 5
  • 2
  • +1
1 Solution
 
Roshan DavisCommented:
I doubt, something you have done in OnSize that is getting triggered while you are calling the MoveWindow (or SetWindowPos), thatz why the flicker happens. Please check some part of the code is again doing some wrong resize operation...
Good Luck
~Roshan
0
 
v3203Author Commented:
Roshan
  Even when I comment out all the code in OnMove, I still cannot resize the dialog. There is no other place in the code that messes with the size or position. Are you saying that "MoveWindow(nLeft, nTop, cx, cy);"  in OnSize should work??
0
 
Roshan DavisCommented:
Not sure may be some mistake like this is there in the code

void CMyDialog::OnSize(UINT nType, int cx, int cy)
{
      this->MoveWindow(nLeft, nTop, yourCX, yourCY);

      CDialog::OnSize(nType, cx, cy);            <--- Again, parent is resetting the value to the old one...

}

If that is the case, try this way

void CMyDialog::OnSize(UINT nType, int cx, int cy)
{
      //this->MoveWindow(nLeft, nTop, yourCX, yourCY); NO NEED OF MOVE WINDOW HERE

      CDialog::OnSize(nType, yourCX, yourCY);            <--- Again, parent is resetting the value to the old one...

}

Or you can try SetWindowPos, no need to bother abou the position....


void CMyDialog::OnSize(UINT nType, int cx, int cy)
{

    CDialog::OnSize(nType, cx, cy);


    this->SetWindowPos(NULL, 0, 0, newWidth, newHeight, SWP_NOMOVE | SWP_NOZORDER);

}


Good Luck
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
AndyAinscowCommented:
Be very careful with code like this

In the OnSize you call Move which generates a WM_SIZE (calls OnSize) which calls Move which ....
0
 
AndyAinscowCommented:
If I understand correctly you want it to be sized to cells in the grid ON THE PARENT VIEW.

For that you should post a message to the parent view instructing it to snap the dialog to the grid and let that then finalise the size of the dialog.
0
 
itsmeandnobodyelseCommented:
>>>> void CMyDialog::OnSize(UINT nType, int cx, int cy)
The OnSize is the handler for the WM_SIZE message. It was called *after* the window was resized. It is really a *bad* place to make resizing as you can't prevent from flickering and have to watch not to do that infinitely as Andy has told you.

You'd better handle the WM_SIZING message which was called before resizing. And don't call the baseclass function if you handled a message. There are only a few messages where the baseclass handler needs to be called additionally, e. g. WM_INITDIALOG, but WM_SIZE definitively is none of these.
0
 
v3203Author Commented:
Nothing is working. Every time I call "this->SetWindowPos.....", in OnSize it calls OnSize once again.
0
 
AndyAinscowCommented:
>>Every time I call "this->SetWindowPos.....", in OnSize it calls OnSize once again.

Read my very first comment.  Then my second telling you how to one way to get around it.
0
 
v3203Author Commented:
AndyAinscow, if I do that, then I will not have the snapping affect while resizing
0
 
AndyAinscowCommented:
One of us misunderstands the other.

If I understand you then you want the dialog to fit into one (or more cells) on the parent view exactly.  No partial covering of a cell.  If that is the case then do what I suggested, post a message to the parent view and let that resize the dialog appropriately.

If that isn't what you require then please explain what I am missing.


( I have a feeling that your dialog shouldn't even be resized by the user - the view should fake it. )
0
 
v3203Author Commented:
AndyAinscow, yes, that is true, exactly as you say. Whether resizing or moving, to always fit exactly in the cells of a parent view. I don't really know where in the parent view I would do that; Like what event to do it in.
0
 
AndyAinscowCommented:
Do you want the resizing to only happen in 'jumps' ?  
Or can the dialog be partially covering a cell and then fits to the grid after the user has finished the resizing ?
0
 
v3203Author Commented:
AndyAinscow,
  Well, ideally, I would like to happen in jumps.
0
 
AndyAinscowCommented:
The 'difficult' option.

I think I would try the following (there could be better alternatives).

In the view trap the mouse (SetCapture) when it is over the view.
For a left button down on the border of the dialog you implement your own 'resizing' routine.  You monitor when the mouse moves (increase/decrease the size of the dialog) and use MoveWindow to resize the dialog to cover the appropriate cells.  When the left button is released then stop your 'resizing' routine.
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

  • 6
  • 5
  • 2
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now