Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Win32 API: Non-resizeable window?

Posted on 2002-07-05
9
Medium Priority
?
434 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
LVL 32

Accepted Solution

by:
jhance earned 150 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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

Templates For Beginners Or How To Encourage The Compiler To Work For You Introduction This tutorial is targeted at the reader who is, perhaps, familiar with the basics of C++ but would prefer a little slower introduction to the more ad…
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 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…

715 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