Click here to Skip to main content
Licence 
First Posted 5 Aug 2002
Views 100,712
Bookmarked 36 times

X-Window Manager like dragging and resizing of windows

By | 21 Sep 2005 | Article
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 :)

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 :) ), 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

About the Author

Markus Rollmann

Web Developer

Germany Germany

Member



Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
You must Sign In to use this message board. (secure sign-in)
 
Search this forum  
 FAQ
    Noise  Layout  Per page   
  Refresh
QuestionOK to fork? Pinmemberfoobarz11:31 29 Dec '08  
AnswerRe: OK to fork? PinmemberMarkus Rollmann20:40 29 Dec '08  
GeneralWorks in Vista! PinmemberJXON19:49 4 Sep '08  
GeneralGreat! PinmemberMwob22:18 2 May '07  
GeneralRe: Great! PinmemberAlexHaan0:38 3 May '07  
GeneralAwesome Pinmemberaijfisuhhtrtl3:34 16 Apr '07  
GeneralPrevent Users from Resizing Windows Pinmembermrtm305011:14 9 Mar '07  
Generalis snapping possible Pinmembermmanson1329:26 19 Jan '07  
GeneralTwo suggestions PinsussAnonymous1:02 5 Oct '05  
GeneralRe: Two suggestions PinmemberMarkus Rollmann1:16 5 Oct '05  
Anonymous wrote:
> I works great, thanks!
 
Thank you, I always welcome feedback Wink | ;)
 
[...]
> (example: open notepad and select file->open) it is not possible to
> move the window under the dialog with WM.
 
You're right- I just tried it. I didnt' notice it before.
[...]
 
> Venv was able to do this. Do you think this would be possible to
> implement to WM? (Unfortunately, I don't have the source code for
> venv.exe).
 
Mmmh... i don't know exactly what causes this behavior. WM should be
able to find the window underlying the modal dialog just like any
other with the WindowFromPoint() function.
 
The SetWindowPos() function I'm using just fails to move a window
below a modal dialog. Maybe some special flags allows it to do
so... I'll have to experiment a bit more.
 
> I also have a few utilities of my own. One of them pastes text with
> shift- click. Perhaps this would be useful in
> WM, too? After all, it's an X Windows like feature.
 
Yes, it seems like a good idea. I'll have a look into it.
 
regards,
Markus

GeneralCursor shape PinmemberEric Lapouge21:32 22 Sep '05  
GeneralBugs and Improvements PinmemberTwink13:54 7 Sep '05  
GeneralRe: Bugs and Improvements PinmemberMarkus Rollmann0:30 10 Sep '05  
GeneralRe: Bugs and Improvements PinmemberTwink14:47 11 Sep '05  
Questionbug? Pinmemberp1ayer19:27 7 Jul '03  
AnswerRe: bug? PinmemberMarkus Rollmann20:23 7 Jul '03  
GeneralGreat technique PinmemberVernero Cifagni2:26 17 Apr '03  
Generalvery creative, so 5 points! PinmemberZhefu Zhang2:13 17 Apr '03  
General(update) PinmemberMarkus Rollmann1:59 17 Apr '03  
GeneralRe: (update) PinmemberWhosit3:37 17 Apr '03  
GeneralDoesnt forget right away PinmemberWhosit10:31 16 Apr '03  
GeneralRe: Doesnt forget right away PinmemberMarkus Rollmann10:40 16 Apr '03  
GeneralRe: Doesnt forget right away PinmemberWhosit10:47 16 Apr '03  
GeneralRe: Doesnt forget right away PinmemberMarkus Rollmann10:59 16 Apr '03  
GeneralChange for override PinmemberWhosit10:55 16 Apr '03  

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.

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