Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

OnNcCalcSize...

Posted on 1997-05-12
11
1,114 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
Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 

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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Introduction: Finishing the grid – keyboard support for arrow keys to manoeuvre, entering the numbers.  The PreTranslateMessage function is to be used to intercept and respond to keyboard events. Continuing from the fourth article about sudoku. …
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.

828 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