Advertisement

stopping resizing of windows

Started by March 22, 2000 04:38 AM
15 comments, last by deakin 24 years, 7 months ago
Personally, I think that overriding the WM_SIZING message is the best option. There are instances that you want the maximize action to do something, yet keep the client area in a particular dimension. Think MS Freecell. However, I don''t believe that WM_SIZING messages are sent in Win NT 3.1 or 3.5x. On those platforms you need to override the WM_NCHITTEST, WM_NCLBUTTONDOWN, WM_MOUSEMOVE, and WM_LBUTTONDOWN messages. See the RESIZE app on MSDN.
Anonymous Poster: If you'll kindly read the original post, you'll find that all he asked for was a flag. So, I did answer his question most adequately in my second reply. The first reply involved checking whether he looked in the docs or not. I spent the last 3 replies (including this one) trying to correct your (obviously) wrong information.

The solution is so simple that you don't have to show it -- just look at the above post and figure out which window styles you want and OR them together! Here's sample code to create a few different styles of windows:


HWND hWndPopup; // we'll create this one with no border, title, or system menu
HWND hWndProgram; // we'll create this one like a typical office app window
HWND hWndDialog; // we'll create this one with a border, a minimize button, and a title

// Assuming you've registered identical WNDCLASSes for each of them, called "My Window Class"

hWndPopup = CreateWindow("My Window Class", "", WS_VISIBLE / WS_POPUP, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, NULL, hInstance, NULL);

hWndApp = CreateWindow("My Window Class", "My Program", WS_VISIBLE / WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, NULL, hInstance, NULL);

hWndDialog = CreateWindow("My Window Class", "My Dialog", WS_VISIBLE / WS_BORDER / WS_MINIMIZEBOX / WS_CAPTION, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, NULL, hInstance, NULL);



The only things that I changed in those examples were the flags and the title text (merely for aesthetic reasons). The only thing the original poster asked for (and needed) was a flag. He didn't ask for a code example, and I assumed from the way he talked that he knew what a flag was.

When all you need is to choose the right flags, and each flag has an excellent description in the docs, it's rather hard to come up with source code, even for people who aren't the original poster and who don't ask nicely. For example, the WS_VISIBLE flag makes a window visible. The WS_BORDER adds a border to the window. And on, and on... The docs explain all this adequately -- it would have taken you 2 minutes to look at your window styles and know absolutely, 100%, without a doubt, that the styles you chose either did or didn't include the WS_MAXIMIZEBOX. Example:

quote:
WS_OVERLAPPEDWINDOW Creates an overlapped window with the WS_OVERLAPPED, WS_CAPTION, WS_SYSMENU, WS_THICKFRAME, WS_MINIMIZEBOX, and WS_MAXIMIZEBOX styles. Same as the WS_TILEDWINDOW style.


That means:

#define WS_OVERLAPPEDWINDOW (WS_OVERLAPPED / WS_CAPTION / WS_SYSMENU / WS_THICKFRAME / WS_MINIMIZEBOX / WS_MAXIMIZEBOX)

So, if you're using the WS_OVERLAPPEDWINDOW style, you know it has a caption, a system menu (the little icon on the top left corner), a thick resizeable frame, a minimize box, and a maximize box.

You also said that everything I posted was not true, which was why I then posted directly from the help files. All you needed to do was to look up CreateWindow, and read the description of WS_MAXIMIZEBOX. I don't think that warranted a post demonstrating the use of CreateWindow(). I assumed the poster knew what flags were when he asked about them; I assumed you knew as much, too. If you don't know, just ask (nicely).

SiCrane: I don't agree, but perhaps I'm wrong. I don't like the way the card and board games are usually programmed on the computer -- it's generally considered good programming to make something that looks the same act the same. Changing what the minimize and maximize buttons do is just like overloading the operator+() to do multiplication. If you want a button that does something else, create another button. Your way just seems to confuse the user (even if it's kind of nifty ).

Good Luck!


- null_pointer


Edited by - null_pointer on 3/24/00 5:48:34 PM
Advertisement
quote:
If you''ll kindly read the original post, you''ll find that all he asked
for was a flag. So, I did answer his question most adequately in my
second reply.


You dumped the entire docs into the post. You didn''t give him the
flag he requested, because there is none that stops a window from
maximizing.

quote:
I spent the last 3 replies (including this one) trying to correct your
(obviously) wrong information.


The only thing wrong with my post is that I had a typo:

The inverse operator is ~.
So it should look like:

flags = flags & ~WS_MAXIMIZEBOX;

This works fine. Yes, it is true that''s not required if you
choose the right flags, but I don''t care about dissecting my window
flags piece by piece.

And just a note, if you use CW_USEDEFAULT with WS_POPUP, the
coordinates are set to zero, which means your window will be
at (0,0)-(0,0) and you won''t be able to see it. So use real
numbers if you want to see your popup window on creation or call
MoveWindow afterwards.

quote:
If he''s trying to prevent the user from maximizing the window, it
makes NO difference whether the maximize box is disabled! Also, that
does NOT affect whether you can resize the window.


Are you saying you can resize my window example after you run it? How?
Here, compile this somewhere and try to resize it.

#define STRICT#define WIN32_LEAN_AND_MEAN#include "windows.h"HINSTANCE hMainInstance=NULL;HWND hMainWindow=NULL;static char szAppName[64] = "AppName";static char szAppTitle[64] = "AppTitle";bool Init_MainWindow();LRESULT CALLBACK UserWndProc(HWND hWnd, UINT actual_message, WPARAM wParam, LPARAM lParam);int PASCAL WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, INT nCmdShow);int PASCAL WinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance,LPSTR lpCmdLine,INT nCmdShow) { MSG msg; (void)hInstance; (void)hPrevInstance; (void)lpCmdLine; (void)nCmdShow; hMainInstance = hInstance; if(!Init_MainWindow()) {       return FALSE; } while (GetMessage(&msg, NULL, 0, 0)) {    TranslateMessage(&msg);    DispatchMessage(&msg); } return msg.wParam;}boolInit_MainWindow() { WNDCLASSEX wcx;  wcx.cbSize         = sizeof(WNDCLASSEX); wcx.hCursor        = LoadCursor(NULL, IDC_ARROW); wcx.hIcon          = LoadIcon(NULL, IDI_APPLICATION); wcx.lpszMenuName   = NULL; wcx.lpszClassName  = szAppName;  wcx.hbrBackground  = (HBRUSH)GetStockObject(WHITE_BRUSH); wcx.hInstance      = hMainInstance; wcx.style          = CS_VREDRAW / CS_HREDRAW /                      CS_OWNDC / CS_DBLCLKS; wcx.lpfnWndProc    = UserWndProc; wcx.cbWndExtra     = 0; wcx.cbClsExtra     = 0; wcx.hIconSm        = NULL; if (!RegisterClassEx(&wcx))     return 0; //// DWORD flags; flags = WS_POPUP / WS_BORDER / WS_SYSMENU / WS_CAPTION / WS_VISIBLE; flags = flags & ~WS_MAXIMIZEBOX; hMainWindow = CreateWindow(               szAppName,               szAppTitle,                flags,               0, 0,               400, 300, 	       (HWND)NULL,                 (HMENU)NULL,                hMainInstance,                (LPVOID)NULL); if(hMainWindow == NULL)     return 0; return 1;}LRESULT CALLBACKUserWndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam) { PAINTSTRUCT ps; HDC hDC; switch (msg) {     case WM_PAINT:         hDC = BeginPaint(hWnd, &ps);         EndPaint(hWnd, &ps);         return 0;    case WM_DESTROY:         PostQuitMessage(0);         return 0; } return DefWindowProc(hWnd, msg, wParam, lParam);} 


Anonymous Poster: "The only thing wrong with my post is that I had a typo:" Where should I start?


quote:
You dumped the entire docs into the post. You didn't give him the flag he requested, because there is none that stops a window from maximizing.


Wrong here. If you'll re-read the post, you'll find that I gave the flag in my second reply.

Also, the post with the (rather large) excerpt from the docs had YOUR NAME on it! That was NOT meant for the original poster!

The ONLY reason I suggested in my first reply that the original poster look it up in the docs is because there are many people who simply try Windows programming from a tutorial where they just cut and paste someone else's code. There are many occasions when the don't even know the docs exist!


quote:
The only thing wrong with my post is that I had a typo:


Most definitely wrong. Allow me to elaborate:

quote:
There are no specific flags to stop a window from maximizing. The docs will not help you.


Yikes! What in the world are you saying here? That's what the docs were MADE FOR! And if you don't know what WS_MAXIMIZEBOX does, just ask!

There is no flag to stop a window from maximizing -- but you said incorrectly that there weren't any flags to stop that. That wasn't true, because all you have to do is NOT include the WS_MAXIMIZEBOX style or any styles that include it implicitly.


quote:
Maybe so, but if you do it the above way, the maximize menu
and button will be grayed out so you can't resize it in the
first place.


Wrong again. See below for your example.


quote:
And I think it is better to setup your flags this way so
you won't run into problems:

DWORD flags = WS_POPUP / WS_BORDER / WS_CAPTION / WS_SYSMENU / WS_VISIBLE;
flags = flags & ^WS_MAXIMIZEBOX;

Better to AND it after you have all the flags ORed together,
just in case.


You went to all that trouble so you didn't have to look it up in the docs? An old Chinese proverb once said "Programmer without docs is dead duck" or something like that. You will be continually wrong here if you don't read the docs.


quote:
And just a note, if you use CW_USEDEFAULT with WS_POPUP, the
coordinates are set to zero, which means your window will be
at (0,0)-(0,0) and you won't be able to see it. So use real
numbers if you want to see your popup window on creation or call MoveWindow afterwards.


Yes, I forgot about that. I was trying to put together some examples quickly and was worried mainly with the flags.


quote:
This works fine. Yes, it is true that's not required if you
choose the right flags, but I don't care about dissecting my window flags piece by piece.

Are you saying you can resize my window example after you run it? How? Here, compile this somewhere and try to resize it.


If you would have read the docs, you would've prevented your error, which was not including the WS_SIZINGBOX (or WS_THICKFRAME) style. Maximizing is totally different from resizing to both Windows, the user, and the programmer. Unfortunately, CreateWindow() is a big function which does an exceptionally large task; you must look it up in the docs if you want to know what you are getting!


In the future, I would recommend that you post your questions instead of wasting our time debating over something like that. We're arguing over a stupid window style here!!!!! Just ask, if you don't understand. And if you have to give advice about something you don't know, start the sentence with "I not sure about this, but..." or "I can't check the docs right now, but I remember..." or something like that.

Good Luck!


- null_pointer



Edited by - null_pointer on 3/25/00 6:57:48 AM
Just a word here....

I have printed off the CreateWindow() section of the MSDN docs and I will go through it to get the right flags.

null_pointer: you were right - i was using a tutorial (actually a book) and just copying/pasting code. I hadn''t checked the docs but I will do that in future

Thanks to everyone who tried to help

- Daniel
http://sw.mtx.net/daniel/
- DanielMy homepage
lol
Advertisement
Another quick note - the flags I have used are:

WS_OVERLAPPED / WS_CAPTION / WS_SYSMENU / WS_MINIMIZEBOX / WS_VISIBLE

Thanks again!

- Daniel
http://sw.mtx.net/daniel/
- DanielMy homepage

This topic is closed to new replies.

Advertisement