Solved

OnNcCalcSize...

Posted on 1997-05-12
11
1,104 Views
Last Modified: 2013-11-20
I'm looking for a way to override the OnNcCalcSize member function to only allow my CView derived class (and it's FrameWindow of course!)  to be a certain width -  XWIDTH.  I want to be able to change my resizing values if they are greater than XWIDTH, to equal XWIDTH.  What is the best way to do this?  I attempted to change the values of lpncsp->rgrc[0], and then call the default CWnd::OnNcCalcSize() function with very bizarre results...  Any suggestions?
0
Comment
Question by:salamander
  • 7
  • 4
11 Comments
 
LVL 3

Expert Comment

by:Melange
ID: 1301476
Are you simply attempting to prevent a user from sizing your window too big? Or do you need to do something more complex?

To keep the window within a certain size override the WM_GETMINMAXINFO message for that window (or frame).

For example in an SDI app:

void CMainFrame::OnGetMinMaxInfo( MINMAXINFO *lpMMI )
{
    lpMMI->ptMaxSize.x = 500;
    lpMMI->ptMaxSize.y = 300;

    CFrameWnd::OnGetMinMaxInfo( lpMMI );
}

0
 

Author Comment

by:salamander
ID: 1301477
I added this function to my CView class, with values for lpMMI->ptMaxSize.x and lpMMI->ptMaxSize.y, yet my application allowed resizing past these values.  This is my code:

void CReviewView::OnGetMinMaxInfo(MINMAXINFO FAR* lpMMI)
{
      lpMMI->ptMaxSize.x = 641;
      lpMMI->ptMaxSize.y = 300;

      CWnd::OnGetMinMaxInfo(lpMMI);
}

This is an MDI application.  Any suggestions?
0
 

Author Comment

by:salamander
ID: 1301478
I added this function to my CView class, with values for lpMMI->ptMaxSize.x and lpMMI->ptMaxSize.y, yet my application allowed resizing past these values.  This is my code:

void CReviewView::OnGetMinMaxInfo(MINMAXINFO FAR* lpMMI)
{
      lpMMI->ptMaxSize.x = 641;
      lpMMI->ptMaxSize.y = 300;

      CWnd::OnGetMinMaxInfo(lpMMI);
}

This is an MDI application.  Any suggestions?
0
ScreenConnect 6.0 Free Trial

Discover new time-saving features in one game-changing release, ScreenConnect 6.0, based on partner feedback. New features include a redesigned UI, app configurations and chat acknowledgement to improve customer engagement!

 

Author Comment

by:salamander
ID: 1301479
I added this function to my CView class, with values for lpMMI->ptMaxSize.x and lpMMI->ptMaxSize.y, yet my application allowed resizing past these values.  This is my code:

void CReviewView::OnGetMinMaxInfo(MINMAXINFO FAR* lpMMI)
{
      lpMMI->ptMaxSize.x = 641;
      lpMMI->ptMaxSize.y = 300;

      CWnd::OnGetMinMaxInfo(lpMMI);
}

This is an MDI application.  Any suggestions?
0
 
LVL 3

Expert Comment

by:Melange
ID: 1301480
You need to do it to the frame window for the view. The view window is actually a child window inside the frame window and doesn't include the borders and title bar. It's actually the frame window that you are resizing.
0
 

Author Comment

by:salamander
ID: 1301481
I have removed the CView code and inserted it into my CChildFrame code as such:

void CChildFrame::OnGetMinMaxInfo(MINMAXINFO FAR* lpMMI)
{
      lpMMI->ptMaxSize.x = 641;
      lpMMI->ptMaxSize.y = 300;

      CWnd::OnGetMinMaxInfo(lpMMI);
}

When I run this, it still doesn't work.  The values after calling the default OnGetMinMaxInfo() return to what they were.
0
 

Author Comment

by:salamander
ID: 1301482
It doesn't work if you leave out the default call, either.
0
 
LVL 3

Accepted Solution

by:
Melange earned 50 total points
ID: 1301483
You need to set the MaxTrackSize values in the MINMAXINFO structure. This will do it.

Add these two lines to OnGetMinMaxInfo:

lpMMI->ptMaxTrackSize.x = MaxXValue;
lpMMI->ptMaxTrackSize.y = MaxYValue;

also set the ptMinTrackSize values if you want the window to be at LEAST a certain size.

0
 

Author Comment

by:salamander
ID: 1301484
This works (thank you!)  but how do I change these values on the fly?  For example, how can I check the document associated with this child frame to get the values for MaxX and MaxY?
0
 
LVL 3

Expert Comment

by:Melange
ID: 1301485
The WM_GETMINMAXINFO message keeps getting sent (I believe, but not entirely sure) every time the user attempts to size the window.

To check your current desired size you can use any number of approaches, but the main problem is how do you get access to your document, right? You can call the CFrameWnd function GetActiveDocument which will return a CDocument pointer for the document that the window currently represents. Then, you'll need to cast it to the correct document to access the appropraite class members.

0
 

Author Comment

by:salamander
ID: 1301486
Thanks a lot.
0

Featured Post

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

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

Suggested Solutions

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: Load and Save to file, Document-View interaction inside the SDI. Continuing from the second article about sudoku.   Open the project in visual studio. From the class view select CSudokuDoc and double click to open the header …
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.

773 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