Click here to Skip to main content
15,396,210 members
Articles / Programming Languages / C++
Article
Posted 5 Aug 2002

Stats

134K views
3K downloads
43 bookmarked

X-Window Manager like dragging and resizing of windows

Rate me:
Please Sign up or sign in to vote.
4.88/5 (33 votes)
21 Sep 20051 min read
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

Share

About the Author

Markus Rollmann
Web Developer
Germany Germany
No Biography provided

Comments and Discussions

 
QuestionOK to fork? Pin
foobarz29-Dec-08 11:31
Memberfoobarz29-Dec-08 11:31 
AnswerRe: OK to fork? Pin
Markus Rollmann29-Dec-08 20:40
MemberMarkus Rollmann29-Dec-08 20:40 
AnswerRe: OK to fork? Pin
Mixelpit27-Apr-21 23:07
MemberMixelpit27-Apr-21 23:07 
GeneralWorks in Vista! Pin
JXON4-Sep-08 19:49
MemberJXON4-Sep-08 19:49 
GeneralGreat! Pin
Mwob2-May-07 22:18
MemberMwob2-May-07 22:18 
GeneralRe: Great! Pin
AlexHaan3-May-07 0:38
MemberAlexHaan3-May-07 0:38 
GeneralAwesome Pin
Member 399521416-Apr-07 3:34
MemberMember 399521416-Apr-07 3:34 
GeneralPrevent Users from Resizing Windows Pin
mrtm30509-Mar-07 11:14
Membermrtm30509-Mar-07 11:14 
Generalis snapping possible Pin
mmanson13219-Jan-07 9:26
Membermmanson13219-Jan-07 9:26 
GeneralTwo suggestions Pin
Anonymous5-Oct-05 1:02
MemberAnonymous5-Oct-05 1:02 
GeneralRe: Two suggestions Pin
Markus Rollmann5-Oct-05 1:16
MemberMarkus Rollmann5-Oct-05 1:16 
GeneralCursor shape Pin
Eric Lapouge22-Sep-05 21:32
MemberEric Lapouge22-Sep-05 21:32 
I was waiting after a small tool like this, which will also work with WinRoll which I like a lot... And this is the case.

I didn't experienced any trouble with my virtual desktop setting so it's also great!

Could you change the shape of the mouse, accordingly with the underlying action?
Thanks a lot!

regards,
Eric
GeneralBugs and Improvements Pin
7-Sep-05 13:54
suss7-Sep-05 13:54 
GeneralRe: Bugs and Improvements Pin
Markus Rollmann10-Sep-05 0:30
MemberMarkus Rollmann10-Sep-05 0:30 
GeneralRe: Bugs and Improvements Pin
bzBetty11-Sep-05 14:47
MemberbzBetty11-Sep-05 14:47 
Questionbug? Pin
p1ayer7-Jul-03 19:27
Memberp1ayer7-Jul-03 19:27 
AnswerRe: bug? Pin
Markus Rollmann7-Jul-03 20:23
MemberMarkus Rollmann7-Jul-03 20:23 
GeneralGreat technique Pin
Member 20158717-Apr-03 2:26
MemberMember 20158717-Apr-03 2:26 
Generalvery creative, so 5 points! Pin
Zhefu Zhang17-Apr-03 2:13
MemberZhefu Zhang17-Apr-03 2:13 
General(update) Pin
Markus Rollmann17-Apr-03 1:59
MemberMarkus Rollmann17-Apr-03 1:59 
GeneralRe: (update) Pin
eidylon17-Apr-03 3:37
Membereidylon17-Apr-03 3:37 
GeneralDoesnt forget right away Pin
eidylon16-Apr-03 10:31
Membereidylon16-Apr-03 10:31 
GeneralRe: Doesnt forget right away Pin
Markus Rollmann16-Apr-03 10:40
MemberMarkus Rollmann16-Apr-03 10:40 
GeneralRe: Doesnt forget right away Pin
eidylon16-Apr-03 10:47
Membereidylon16-Apr-03 10:47 
GeneralRe: Doesnt forget right away Pin
Markus Rollmann16-Apr-03 10:59
MemberMarkus Rollmann16-Apr-03 10:59 

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.