Click here to Skip to main content
15,886,788 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 255.2K   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

 
Generalwindowsizer Pin
Praetorian19-Aug-02 14:43
Praetorian19-Aug-02 14:43 
GeneralRe: windowsizer Pin
Nish Nishant25-Aug-02 23:43
sitebuilderNish Nishant25-Aug-02 23:43 
Generalwindowsizer Pin
Praetorian19-Aug-02 14:37
Praetorian19-Aug-02 14:37 
GeneralWonderful Program Pin
Josykatz18-Aug-02 0:22
Josykatz18-Aug-02 0:22 
GeneralRe: Wonderful Program Pin
Nish Nishant18-Aug-02 15:51
sitebuilderNish Nishant18-Aug-02 15:51 
Generaldream-shot Pin
christoph brändle8-Aug-02 7:56
christoph brändle8-Aug-02 7:56 
GeneralRe: dream-shot Pin
Nish Nishant8-Aug-02 14:37
sitebuilderNish Nishant8-Aug-02 14:37 
GeneralRe: Use this app if you want to break your monitor Pin
Nish Nishant8-Aug-02 0:54
sitebuilderNish Nishant8-Aug-02 0:54 
StephaneRodriguez wrote:
Nishant, just reread your introductory "overview" paragraph. It's just full of "switch", "screen resolutions", and so on. Doesn't this kind of terminology belongs to resolution switching rather than window sizing ?

I just re-read it. It says that I got fed up of regularly having to switch my screen resolutions and thus ended up writing this app. I wrote this app to *avoid* regular screen resolution changes. In fact in the rest of the article [which is a very short one by the way] I have explained as clearly as is possible, what the program does.

What you did was to read the first paragraph, grossly misunderstand what the app does, and then you posted a totally invalid comment on my program using very strong language on the article's forum. I am not saying you shouldn't have done that, because what you post is your business, but I am saying that if you think about it for a while you might see why I responded the way I did.

Thousands of people visit CP every day and a percentage of them would probably see my article. At least some of them might read your comment and wrongly pass judgement on my application. Is that fair? I ask you, is that fair at all?

Of course, everyone is free to act as they please here. But it would be a very good thing if people would refrain from hasty mispostings.

This post was not meant to be rude or impolite at all. If at all it did that, I apologize for my lack of command over the english language which must have brought in a touch of unintended harshness to this post.

Regards,
Nish


Author of the romantic comedy

Summer Love and Some more Cricket [New Win]

Review by Shog9
Click here for review[NW]

GeneralRe: Use this app if you want to break your monitor Pin
Nish Nishant8-Aug-02 16:00
sitebuilderNish Nishant8-Aug-02 16:00 
GeneralRe: Use this app if you want to break your monitor Pin
James T. Johnson8-Aug-02 0:01
James T. Johnson8-Aug-02 0:01 
GeneralRe: Use this app if you want to break your monitor Pin
Nish Nishant8-Aug-02 0:07
sitebuilderNish Nishant8-Aug-02 0:07 
GeneralWonderful! Pin
Shog97-Aug-02 19:16
sitebuilderShog97-Aug-02 19:16 
GeneralRe: Wonderful! Pin
ColinDavies7-Aug-02 19:22
ColinDavies7-Aug-02 19:22 
GeneralRe: Wonderful! Pin
Nish Nishant7-Aug-02 20:22
sitebuilderNish Nishant7-Aug-02 20:22 
GeneralRe: Wonderful! Pin
Nish Nishant7-Aug-02 20:20
sitebuilderNish Nishant7-Aug-02 20:20 
GeneralRe: Wonderful! Pin
Obliterator18-Dec-02 7:59
Obliterator18-Dec-02 7:59 
GeneralThat was quick Pin
David Wulff7-Aug-02 6:33
David Wulff7-Aug-02 6:33 
GeneralRe: That was quick Pin
Nish Nishant7-Aug-02 7:34
sitebuilderNish Nishant7-Aug-02 7:34 
GeneralRe: That was quick Pin
Nnamdi Onyeyiri7-Aug-02 8:52
Nnamdi Onyeyiri7-Aug-02 8:52 
GeneralRe: That was quick Pin
Nish Nishant7-Aug-02 15:57
sitebuilderNish Nishant7-Aug-02 15:57 
GeneralRe: That was quick Pin
Nnamdi Onyeyiri7-Aug-02 21:35
Nnamdi Onyeyiri7-Aug-02 21:35 
GeneralRe: That was quick Pin
Jörgen Sigvardsson14-Dec-02 11:57
Jörgen Sigvardsson14-Dec-02 11:57 
GeneralRe: That was quick Pin
Nish Nishant14-Dec-02 23:42
sitebuilderNish Nishant14-Dec-02 23:42 
GeneralRe: That was quick Pin
Jörgen Sigvardsson15-Dec-02 1:02
Jörgen Sigvardsson15-Dec-02 1:02 
GeneralWow Pin
Rama Krishna Vavilala7-Aug-02 4:53
Rama Krishna Vavilala7-Aug-02 4:53 

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.