Solved

Win32 API: Non-resizeable window?

Posted on 2002-07-05
9
420 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
 
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
What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

 

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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Introduction This article is the first in a series of articles about the C/C++ Visual Studio Express debugger.  It provides a quick start guide in using the debugger. Part 2 focuses on additional topics in breakpoints.  Lastly, Part 3 focuses on th…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
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.

760 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now