Solved

OnNcCalcSize...

Posted on 1997-05-12
11
1,067 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
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 

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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Windows Drag & Drop Location 2 85
Question regarding Copy/Paste 16 87
post4 challenge 28 83
Annoying "thing" blocks my view 4 53
Introduction: Ownerdraw of the grid button.  A singleton class implentation and usage. Continuing from the fifth article about sudoku.   Open the project in visual studio. Go to the class view – CGridButton should be visible as a class.  R…
Introduction: Dialogs (1) modal - maintaining the database. Continuing from the ninth article about sudoku.   You might have heard of modal and modeless dialogs.  Here with this Sudoku application will we use one of each type: a modal dialog …
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.
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…

747 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

12 Experts available now in Live!

Get 1:1 Help Now