Solved

OnNcCalcSize...

Posted on 1997-05-12
11
1,088 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
 

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
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.

 

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

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
Separate files macro - Errors on larger data set 18 65
sum13 challenge 24 90
either24  challenge 19 90
My project did see openJDK that I installed. What could be the problem 7 122
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. …
Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
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.
This is used to tweak the memory usage for your computer, it is used for servers more so than workstations but just be careful editing registry settings as it may cause irreversible results. I hold no responsibility for anything you do to the regist…

911 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

16 Experts available now in Live!

Get 1:1 Help Now