Click here to Skip to main content
15,889,034 members
Articles / Programming Languages / C++

Minimize any window to system tray using Windows Hook

Rate me:
Please Sign up or sign in to vote.
4.68/5 (32 votes)
29 Oct 2003CPOL2 min read 191.8K   5.1K   76   38
If there are some applications you have to run during your work, but need to minimize them to the Task Bar, make your Task Bar become "dirty". This utility will minimize them to the System Tray.

Introduction

There're times when your desktop becomes "dirty" because there're many applications running. Among them, there're some you have to let run during your work (E.g.: I have to let the MS Outlook run all the time). If you minimize them, they will make your task bar crowded. I chose to minimize them to the system tray for my own convenience. So, I decided to write a tiny utility to make all windows minimized to the system tray.

How To?

To solve my problem, I have to answer the following questions:

  1. How to make a particular window be minimized to the system tray?
  2. How to make any window to accept my command (minimized it to system tray)?

The first question is not very difficult. There're many articles about this topic. The second question is not very difficult either. I just use Windows Hooks to intercept some Windows messages when a window menu (system menu) of a window is being displayed, then I append a menu item of my own into this window menu. When a user choose this menu item, Windows will send a message to that hooked application, I intercept this message again, and minimize the application to the system tray. When a user clicks on an icon in the system tray of a hooked application, Windows will send a message to that application, I intercept this message again, and restore that application window, and remove its icon from the system tray. That's all. I have commented so much in my source code, so you can read and understand it easily.

Open Issues

  1. When you exit or disable this utility while there is any application minimized to the system tray, those application will not be restored properly, you must restore all hooked applications before you exit or disable this utility. I'll fix this defect in future, but if someone has any idea about this issue, please share it with me.
  2. If you find any improvement or suggestion, please let me know.

Thank you for reading my article!

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


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

Comments and Discussions

 
GeneralNice work, one suggestion Pin
Vasko3-Nov-03 21:28
Vasko3-Nov-03 21:28 
GeneralRe: Nice work, one suggestion Pin
Chau Nguyen3-Nov-03 21:48
Chau Nguyen3-Nov-03 21:48 
Generalproblem Pin
thienle31-Oct-03 14:12
thienle31-Oct-03 14:12 
GeneralRe: problem Pin
Matt G5-Nov-03 0:40
Matt G5-Nov-03 0:40 
GeneralRe: problem Pin
avenger_sb2531-Mar-04 8:11
avenger_sb2531-Mar-04 8:11 
QuestionDirty? Pin
NGS 54967230-Oct-03 5:32
NGS 54967230-Oct-03 5:32 
AnswerRe: Dirty? Pin
Chau Nguyen30-Oct-03 14:26
Chau Nguyen30-Oct-03 14:26 
AnswerRe: Dirty? Pin
Cristian Amarie3-Nov-03 19:34
Cristian Amarie3-Nov-03 19:34 
GeneralRe: Dirty? Pin
Chau Nguyen3-Nov-03 20:58
Chau Nguyen3-Nov-03 20:58 
GeneralHaving problems with IE Pin
Darren_vms30-Oct-03 0:49
Darren_vms30-Oct-03 0:49 
GeneralRe: Having problems with IE Pin
Chau Nguyen30-Oct-03 14:15
Chau Nguyen30-Oct-03 14:15 
GeneralEasy Way Pin
aamironline29-Oct-03 23:49
aamironline29-Oct-03 23:49 
GeneralRe: Easy Way Pin
Sven Axelsson30-Oct-03 2:51
Sven Axelsson30-Oct-03 2:51 

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.