Solved

Win32 API: Non-resizeable window?

Posted on 2002-07-05
9
426 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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

  Included as part of the C++ Standard Template Library (STL) is a collection of generic containers. Each of these containers serves a different purpose and has different pros and cons. It is often difficult to decide which container to use and …
IntroductionThis article is the second in a three part article series on the Visual Studio 2008 Debugger.  It provides tips in setting and using breakpoints. If not familiar with this debugger, you can find a basic introduction in the EE article loc…
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.

679 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