Click here to Skip to main content
Click here to Skip to main content

X-Window Manager like dragging and resizing of windows

, 21 Sep 2005
Rate this:
Please Sign up or sign in to vote.
This article shows how to make use of a mouse hook to allow simple dragging and resizing of windows.

Introduction

Hooks are a powerful feature of Windows and can be used to trap nearly all events in the Windows environment. This example shows how to trap mouse events and implements a simple window manager. It allows you to move and resize windows, easily following the style of many window managers in the UNIX X-Window environment.

With this tool, any window on your Desktop can easily be dragged with the left-mouse button while holding down the ALT key, starting anywhere in the window's client area. In the same way, it is possible to resize any window while dragging with the right mouse-button, holding down ALT. That's in my opinion far more comfortable than aiming with the mouse for the border or a corner of the window Smile | :)

The tool consists of two parts. First the main program that loads the second part - a DLL that will subsequently be injected in other processes to trap mouse events. For details about this, you may refer to other great articles at CodeProject as for example Hooks and DLLs by Joseph M. Newcomer in the DLL-section. The main program further installs a tray icon (warning: programmer's art Smile | :) ), that allows the user to quit the tool.

History

  • 06.08.2003

    Initial version.

  • 17.04.2003

    Bug fix: proper handling of Alt-key release while dragging or sizing (thanks Whosit).

  • 10.09.2005

    Bug fix: don't move or resize windows that are maximized (thanks TWink).

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here

Share

About the Author

Markus Rollmann
Web Developer
Germany Germany
No Biography provided

Comments and Discussions

 
QuestionOK to fork? Pinmemberfoobarz29-Dec-08 12:31 
Thank you Markus for making Windows a better place! This software provides functionality Windows should have out of box. I like it very much. However, there were a couple of annoying features: I didn't understand the code and it didn't compile on MinGW.
 
I ported the code to MinGW and rewrote it in C (because I can't write C++ and could not get g++ to generate working binaries). I added a check to discard WM_RBUTTONUP when alt is down to prevent context menus from popping up. I stripped the tray icon (because I didn't feel like learning to to use windres). Because I stripped the tray icon I also wrote a killer app to tell the DLL host to exit.
 
I'd like to post the code in a new article here on CodeProject if it's OK with you, Markus. I'd also like to rename the software to WindowShifter to avoid confusion (or create it, you could mistake that for an Alt-Tab replacement for example). The string WindowShifter turns up very few matches on Google so it's pretty unique.
 
Perhaps in the future I'll look into implementing the last missing feature---scroll focus under cursor just like in most X11 window managers. Windows' scroll focus policy has always frustrated me and I think it's time to remedy that. I have a hook application that came with a mouse, LwbWheel.exe, that does just what I want but it's not open source.
AnswerRe: OK to fork? PinmemberMarkus Rollmann29-Dec-08 21:40 
GeneralWorks in Vista! PinmemberJXON4-Sep-08 20:49 
GeneralGreat! PinmemberMwob2-May-07 23:18 
GeneralRe: Great! PinmemberAlexHaan3-May-07 1:38 
GeneralAwesome Pinmemberaijfisuhhtrtl16-Apr-07 4:34 
GeneralPrevent Users from Resizing Windows Pinmembermrtm30509-Mar-07 12:14 
Generalis snapping possible Pinmembermmanson13219-Jan-07 10:26 
GeneralTwo suggestions PinsussAnonymous5-Oct-05 2:02 
GeneralRe: Two suggestions PinmemberMarkus Rollmann5-Oct-05 2:16 
GeneralCursor shape PinmemberEric Lapouge22-Sep-05 22:32 
GeneralBugs and Improvements PinmemberTwink7-Sep-05 14:54 
GeneralRe: Bugs and Improvements PinmemberMarkus Rollmann10-Sep-05 1:30 
GeneralRe: Bugs and Improvements PinmemberTwink11-Sep-05 15:47 
Questionbug? Pinmemberp1ayer7-Jul-03 20:27 
AnswerRe: bug? PinmemberMarkus Rollmann7-Jul-03 21:23 
GeneralGreat technique PinmemberVernero Cifagni17-Apr-03 3:26 
Generalvery creative, so 5 points! PinmemberZhefu Zhang17-Apr-03 3:13 
General(update) PinmemberMarkus Rollmann17-Apr-03 2:59 
GeneralRe: (update) PinmemberWhosit17-Apr-03 4:37 
GeneralDoesnt forget right away PinmemberWhosit16-Apr-03 11:31 
GeneralRe: Doesnt forget right away PinmemberMarkus Rollmann16-Apr-03 11:40 
GeneralRe: Doesnt forget right away PinmemberWhosit16-Apr-03 11:47 
GeneralRe: Doesnt forget right away PinmemberMarkus Rollmann16-Apr-03 11:59 
GeneralChange for override PinmemberWhosit16-Apr-03 11:55 

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

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

| Advertise | Privacy | Terms of Use | Mobile
Web01 | 2.8.1411022.1 | Last Updated 21 Sep 2005
Article Copyright 2002 by Markus Rollmann
Everything else Copyright © CodeProject, 1999-2014
Layout: fixed | fluid