Solved

Win32 API: Non-resizeable window?

Posted on 2002-07-05
9
423 Views
Last Modified: 2012-08-13
Hello!
I i guess this is quite an easy question. I just recently started to read about Win32 API (c++) and i have been wondering about it for a while.
The question is is there a way to make a regular window that the user isn't able to resize? Or do you need a dialog box for that?
If u CAN make do it with a regular window then how is it done?

All answers are good ones!
thanks
0
Comment
Question by:Matte86
  • 4
  • 3
  • 2
9 Comments
 
LVL 86

Expert Comment

by:jkr
ID: 7132002
All you have to do is removing 'WS_THICKFRAME' from the window's styles - or better, not set it :o)
0
 
LVL 32

Expert Comment

by:jhance
ID: 7132176
Another approach is to handle the WM_SIZE message.
0
 
LVL 86

Expert Comment

by:jkr
ID: 7132344
>>Another approach is to handle the WM_SIZE message

Too late:

WM_SIZE
The WM_SIZE message is sent to a window after its size has changed.

0
Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

 
LVL 32

Accepted Solution

by:
jhance earned 50 total points
ID: 7132347
True, but if you have a "preferred" size, you can just handle the message and put the window back to the size you want with MoveWindow.

It's also fun to do this when you want to just annoy people, since regardless of what they do to size a window, it just snaps back to the original size.
0
 

Author Comment

by:Matte86
ID: 7132488
OK. I tried all of those ways.

First i tried to create the window with no styles at all, but I could still resize the window, so i removed all styles from the window class. Could still resize the window. Is there a part that i've missed? cuz i didn't get the first way to work.

As you said the second way didn't work either, probably because the message is sent after the window is created just as you said.

The third way on the other hand worked real good. But if i use MoveWindow i had to specify an x and y parameter, and if i just choose one then the window will pop up at the specified place every time. What if I want to resize the window and let it stay where it was before i resized it?
0
 
LVL 32

Expert Comment

by:jhance
ID: 7132509
To effectively use MoveWindow as I mentioned you must:

1) Remember the proper size.  This can be hard coded or just read as your app starts up.

2) You said that SIZING was to be prohibited but that MOVING was OK.  So you need to look at the data when WM_SIZE is received and permit a move but not a resize.  Since you know the size, just use the new ORIGIN when WM_SIZE comes but "fix" the size.
0
 

Author Comment

by:Matte86
ID: 7132525
hmm... didn't really get what u meant woth that. probably just my bad english. however I tried to use GetWindowRect to get the x and y coordinates of the window. it worked, but not quite the way i wanted. The window didn't move if i tried to adjust the "right" or "bottom" of the window, but if i move the "top" or "left" then GetWindowRect took the new coordinates and adjusted the window location after that. that resulted in that the window moved a little bit up or to the left.
any other way to do it?
0
 
LVL 32

Expert Comment

by:jhance
ID: 7132626
Try something like this in your WINPROC:


     static int cx, cy;
     static BOOL bInitial = TRUE;




          case WM_SIZE:
               if(bInitial){
                    bInitial = FALSE;
                    cx = LOWORD(lParam);
                    cy = HIWORD(lParam);
                    break;
               }

               RECT r;
               GetWindowRect(hWnd, &r);

               if((r.bottom - r.top) == cy && (r.right - r.left) == cx){
                    break;
               }

               MoveWindow(hWnd, r.left, r.top, cx, cy, TRUE);

               return 0;
0
 

Author Comment

by:Matte86
ID: 7133639
That was pretty much code, and it did just the same thing as the code i explained in my last post. This code does the same thing:

case WM_SIZE:
     GetWindowRect(hwnd, &windowrect);
     MoveWindow(hwnd, windowrect.top, windowrect.left, 400, 400, TRUE);
     break;

so in both ways the window moves when i try to move the upper or the left edge. well.. i guess i can live with that =)
thanks
0

Featured Post

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

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

Suggested Solutions

Written by John Humphreys C++ Threading and the POSIX Library This article will cover the basic information that you need to know in order to make use of the POSIX threading library available for C and C++ on UNIX and most Linux systems.   [s…
This article will show you some of the more useful Standard Template Library (STL) algorithms through the use of working examples.  You will learn about how these algorithms fit into the STL architecture, how they work with STL containers, and why t…
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…

777 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