Click here to Skip to main content
15,867,686 members
Articles / Programming Languages / C++
Article

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 139.5K   3.1K   43   27
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


Written By
Web Developer
Germany Germany
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions

 
GeneralChange for override Pin
eidylon16-Apr-03 10:55
eidylon16-Apr-03 10:55 
GeneralRe: Change for override Pin
Markus Rollmann16-Apr-03 11:04
Markus Rollmann16-Apr-03 11:04 

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.