Click here to Skip to main content
15,885,366 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.6K   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

 
Generalanybody know how to track clicks to the upper left icon Pin
RogerPack30-Mar-09 9:52
RogerPack30-Mar-09 9:52 
GeneralRe: anybody know how to track clicks to the upper left icon Pin
RogerPack7-Apr-09 10:36
RogerPack7-Apr-09 10:36 
GeneralRe: anybody know how to track clicks to the upper left icon Pin
RogerPack23-Apr-09 8:20
RogerPack23-Apr-09 8:20 
QuestionCan I handle events other than "Tray Me"? Pin
'¯`°²¤ zee ¤²°`¯'6-Sep-07 12:51
'¯`°²¤ zee ¤²°`¯'6-Sep-07 12:51 
Generaljust what I wanted. Pin
guoxu31-Aug-07 15:54
guoxu31-Aug-07 15:54 
GeneralThx Pin
xgo20-Mar-07 2:28
xgo20-Mar-07 2:28 
GeneralWindow movement restriction Pin
AKG20-Feb-07 21:59
AKG20-Feb-07 21:59 
Hi,

I am working on an application which can restrict notepad application from moving. For that, I am writing a HOOK dll and using WH_CALLWNDPROC to trap WM_WINDOWPOSCHANGED & WM_WINDOWPOSCHANGING messages. As per the MSDN we can not modify the message in WH_CALLWNDPROC hook.

Is there any way to restrict a window(Notepad, Word, IE) movement ?

Regards

Anuj

GeneralThanks Pin
mike34711-Feb-07 21:53
mike34711-Feb-07 21:53 
GeneralSimple and Neat Pin
SRV_Bala27-Sep-06 1:38
SRV_Bala27-Sep-06 1:38 
GeneralAdds multiple "Tray Me" entries [modified] Pin
Gondola7-Aug-06 12:02
Gondola7-Aug-06 12:02 
GeneralThankyou Pin
rimblock18-Jul-06 14:02
rimblock18-Jul-06 14:02 
GeneralThank you! Pin
nico8031-May-06 22:57
nico8031-May-06 22:57 
GeneralC# Example Pin
XWreckage24-May-06 6:39
XWreckage24-May-06 6:39 
General"Free minimized windows" suggestion Pin
anat0lik15-May-06 4:55
anat0lik15-May-06 4:55 
GeneralRe: "Free minimized windows" suggestion Pin
RogerPack7-Apr-09 10:39
RogerPack7-Apr-09 10:39 
GeneralRequires two clicks with many apps like IE, etc Pin
tiecoon1-Aug-05 14:22
tiecoon1-Aug-05 14:22 
QuestionNot working with XP Media Center Edition? Pin
tiecoon4-Jun-05 8:44
tiecoon4-Jun-05 8:44 
GeneralNovell GroupWise Pin
meink15-Mar-05 11:20
meink15-Mar-05 11:20 
QuestionWhy doesn't it work with CMD windows? Pin
Rabbej12-Feb-05 3:41
Rabbej12-Feb-05 3:41 
AnswerRe: Why doesn't it work with CMD windows? Pin
nosek13-Dec-05 3:58
nosek13-Dec-05 3:58 
GeneralRe: Why doesn't it work with CMD windows? Pin
kalantir12-Nov-07 20:53
kalantir12-Nov-07 20:53 
GeneralCan't compile code Pin
Member 162008329-Dec-04 12:38
Member 162008329-Dec-04 12:38 
GeneralNot working properly in Win98 Pin
Somersault606-Dec-04 4:23
Somersault606-Dec-04 4:23 
QuestionHow do I use this App Pin
Joseph Franklin S27-Jan-04 4:38
professionalJoseph Franklin S27-Jan-04 4:38 
AnswerRe: How do I use this App Pin
Ash Lux18-Apr-04 16:35
Ash Lux18-Apr-04 16:35 

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.