Click here to Skip to main content
15,867,686 members
Articles / Desktop Programming / MFC
Article

Window Sizer

Rate me:
Please Sign up or sign in to vote.
4.88/5 (43 votes)
7 Aug 2002CPOL2 min read 254.5K   4.5K   82   69
A hot-key based program that lets you resize your current window to any size. Useful for web designers and GUI developers as it helps avoid frequent screen-resolution changes.

Image 1

Overview

Window Sizer is a little program that I wrote when I was having to frequently change screen resolutions when testing web pages or GUI applications to make sure that they worked alright in other resolutions than my default one. Often we also had requests from clients with weird specifications like a maximum window size of 600 x 600 or something equally bizarre. Then I found that when I was editing CP articles I had to switch to 800 x 600 to make sure that the article looked fine in that resolution too. All this culminated in this little app that you see.

Usage

Just run the app once, probably at windows startup. Just drag a short cut to the Start-Menu's Startup-folder. You'll see a green tree icon on your system tray. That's to let you know that Window Sizer is active. Now just make your window active by clicking on it and press CTRL-ALT-F12 which is the keyboard shortcut that brings up Window Sizer. Now you can choose one of the resolutions from the list box or use a custom resolution, and then click on Resize to resize the window to that size. If you close the Window Sizer window the program won't exit, it simply hides itself. The resolution list in the list box will never exceed your screen resolution. Thus if you are on 800 x 600, don't expect to see 720 x 720 in the list box. But you can type what you feel like into the Custom size text boxes at your own risk of course. You can exit the program by right clicking on the task tray and choosing Exit.

Technical details

Basically we use GetForegroundWindow() to get the current window. This usually works better than GetActiveWindow() on XP and 2K because they have some kind of funny option that when set prevents windows from taking over the focus. This means we end up with crazy situations where the foreground window may not be the active window and vice versa. Now we use MoveWindow() to resize the window. If the resizing gets the window out of screen, we center the window on the screen. We also remove the WS_MAXIMIZE if it is set because otherwise the OS will not know that the window has been un-maximized. Initially I had over-looked such a contingency and had experienced some weird side effects.

Conclusion

I'd like to thank David Wulff and Roger Wright for doing some quick testing for me. It was okay when I alone was using it, but when I thought of CP-ing it, I wanted some external testing and these two gentlemen helped me by testing out the application. Of course there might be a few bugs left for all I know. But I am hoping on getting some quality feedback and suggestions as usual.

Updates

  • Aug 08 2002 - Added an MSI Installer

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
United States United States
Nish Nishant is a technology enthusiast from Columbus, Ohio. He has over 20 years of software industry experience in various roles including Chief Technology Officer, Senior Solution Architect, Lead Software Architect, Principal Software Engineer, and Engineering/Architecture Team Leader. Nish is a 14-time recipient of the Microsoft Visual C++ MVP Award.

Nish authored C++/CLI in Action for Manning Publications in 2005, and co-authored Extending MFC Applications with the .NET Framework for Addison Wesley in 2003. In addition, he has over 140 published technology articles on CodeProject.com and another 250+ blog articles on his WordPress blog. Nish is experienced in technology leadership, solution architecture, software architecture, cloud development (AWS and Azure), REST services, software engineering best practices, CI/CD, mentoring, and directing all stages of software development.

Nish's Technology Blog : voidnish.wordpress.com

Comments and Discussions

 
QuestionNo download link pops up!! Pin
Member 955539629-Oct-12 8:30
Member 955539629-Oct-12 8:30 
AnswerRe: No download link pops up!! Pin
Nish Nishant29-Oct-12 8:38
sitebuilderNish Nishant29-Oct-12 8:38 
QuestionWindow Sizer Pin
wwmjava18-Oct-12 14:49
wwmjava18-Oct-12 14:49 
QuestionNot working in windows 7 Pin
Deepak.Prahlad15-Aug-11 20:10
Deepak.Prahlad15-Aug-11 20:10 
AnswerRe: Not working in windows 7 Pin
vvqboy5-Aug-14 21:15
vvqboy5-Aug-14 21:15 
GeneralNeed to set a size for the windows contents, excluding the window border Pin
Adam Reece16-May-11 6:20
Adam Reece16-May-11 6:20 
GeneralMy vote of 4 Pin
Patrick Kalkman23-Jan-11 5:00
Patrick Kalkman23-Jan-11 5:00 
GeneralGreat Article Pin
Gaurav Dudeja India19-Apr-10 0:47
Gaurav Dudeja India19-Apr-10 0:47 
Questionis there a newer or similar free version out now? Pin
july churches10-Oct-08 8:15
july churches10-Oct-08 8:15 
although this works fantastic on both xp 32-bit and vista 64-bit...i would love to see a "save custom size" Smile | :) .

im trying to add a few of my own default window sizes (have to type them in manually in this version, apart from the defaults)
GeneralCtrl+Alt+F12 Does Not Work Pin
Kirill Osipov9-Oct-07 20:05
Kirill Osipov9-Oct-07 20:05 
GeneralRe: Ctrl+Alt+F12 Does Not Work Pin
Deepak.Prahlad15-Aug-11 20:12
Deepak.Prahlad15-Aug-11 20:12 
GeneralVery Cool Nish Pin
Jeffrey Walton15-Dec-06 12:53
Jeffrey Walton15-Dec-06 12:53 
Generalactive window Pin
krishnachandran18-Dec-05 18:25
krishnachandran18-Dec-05 18:25 
GeneralProblem related to COM Wrapper Pin
paresh_vs15-Nov-04 3:02
paresh_vs15-Nov-04 3:02 
QuestionCan not resize Yahoo Messenger 6.0 window Pin
JList9-Oct-04 7:16
JList9-Oct-04 7:16 
GeneralWindow Sizer Pin
waymonc5-Dec-03 8:53
waymonc5-Dec-03 8:53 
GeneralBitmap stretching Pin
collincode15-Sep-03 19:49
collincode15-Sep-03 19:49 
GeneralRe: Bitmap stretching Pin
Nish Nishant15-Sep-03 21:18
sitebuilderNish Nishant15-Sep-03 21:18 
GeneralResizing IE Pin
Uwe Keim19-Jul-03 21:41
sitebuilderUwe Keim19-Jul-03 21:41 
GeneralGreat work! Pin
Ryan Binns26-Mar-03 18:44
Ryan Binns26-Mar-03 18:44 
GeneralWindow Sizer Predefined sizes Pin
Paul Farry13-Mar-03 17:15
professionalPaul Farry13-Mar-03 17:15 
GeneralRe: Window Sizer Predefined sizes Pin
Nish Nishant13-Mar-03 19:46
sitebuilderNish Nishant13-Mar-03 19:46 
GeneralThis is what I was looking for Pin
WillemM3-Mar-03 20:39
WillemM3-Mar-03 20:39 
GeneralRe: This is what I was looking for Pin
Nish Nishant8-Mar-03 5:15
sitebuilderNish Nishant8-Mar-03 5:15 
GeneralStandard Window Sizes Pin
IanL19-Feb-03 22:58
IanL19-Feb-03 22:58 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.