Solved

Win32 API: Non-resizeable window?

Posted on 2002-07-05
9
425 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
Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

 
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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Errors will happen. It is a fact of life for the programmer. How and when errors are detected have a great impact on quality and cost of a product. It is better to detect errors at compile time, when possible and practical. Errors that make their wa…
This article shows you how to optimize memory allocations in C++ using placement new. Applicable especially to usecases dealing with creation of large number of objects. A brief on problem: Lets take example problem for simplicity: - I have a G…
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 viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.

809 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