C++, Win API, minimum resize dimensions?

Associate
Joined
10 Oct 2008
Posts
353
Location
Dundee
Hi, I am working on a Windows application to play about with OpenGL.
Thats not where the issue lies however...

I want my app to be resizable, which isn't hard to achieve. But implementing minimum resize dimensions (to make the application layout easy to create etc) seems to be a bit of a bother.

This page on the msdn seems to be what I am looking for.

So I hopped into my WndProc function and started working on some code:
Code:
LRESULT CALLBACK WndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam){
  switch(message){
    case WM_GETMINMAXINFO: //window size/position is going to change
    /*
        Intercept lParam pointer to MINMAXINFO structure and apply custom 
        dimensions
    */
    lParam->ptMinTrackSize.x = (long)windowMinWidth;
    lParam->ptMinTrackSize.y = (long)windowMinHeight;
    return 0;

    //other cases excluded
  }
}

So, the msdn says that lParam for this event will be a pointer to a MINMAXINFO structure, which among other values, contains a point structure called ptMinTrackSize. The idea is that changing these values before windows takes the structure stops the user from resizing it below your allowable dimensions.

But lParam is simply not a pointer, my compiler says. And I agree, so why does msdn say it is? And why can't I find an example or tutorial for this anywhere? I have searched gamedev.net where these solutions usually lie but nobody seems to have asked before.

As is usual with Windows programming, I need somebody who has overcome the situation before to answer this query - because Microsoft don't seem to bother documenting their development software properly (I think they want people using the high-level bloatware applications which handle this for the programmer).

Any help is greatly appreciated.
 
This is how I do it:

Code:
		case WM_GETMINMAXINFO: 
			{
				MINMAXINFO *sz = (MINMAXINFO*) lParam;
				sz->ptMinTrackSize.x = 350;
				sz->ptMinTrackSize.y = 350;
			}
			break;

Does the job :) While lParam does point to the structure you can't just directly modify it in the way you are.
 
This is how I do it:
Does the job :) While lParam does point to the structure you can't just directly modify it in the way you are.

Ah, so I needed to typecast it :rolleyes:

Don't know how I missed that, thanks for the help it works great now.

One thing though, if that event is called every "frame" the window is resized, does that mean we are setting the same value to the same structure loads of times? Is there a way to get the pointer at app initialisation and set the values once? I could make a check for the first time WM_GETMINMAXINFO is called but that would probably add extra overhead that would compromise the change.
 
Hmm, that message should only be sent when the window's size or position is about to change. It shouldn't be sent every frame unless your opengl code is resizing the window all the time for some reason? (Unless you meant every frame while the resize is in progress?) Essentially that code should only be processed a few times throughout the course of your program's execution. I can't see it introducing performance issues.

Afraid I don't know of a way to set MINMAXINFO outside of the message loop though :(
 
Hmm, that message should only be sent when the window's size or position is about to change. It shouldn't be sent every frame unless your opengl code is resizing the window all the time for some reason? (Unless you meant every frame while the resize is in progress?) Essentially that code should only be processed a few times throughout the course of your program's execution. I can't see it introducing performance issues.

Afraid I don't know of a way to set MINMAXINFO outside of the message loop though :(

Yeah sorry, I meant only while being resized.

Of course, the performance implications are incredibly minor, also it wouldn't matter if the window was being resized anyway. I just like to keep the program execution as clean and efficient as possible.
 
Back
Top Bottom