Click here to Skip to main content
15,902,894 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 192.2K   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

 
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 
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 
I try to learn to write this program, but i did not know how to start it... Please help me...

TL A new member of The code Project

write a program that maintains a list of books for a library. The program must accept commands to make insertions and deletions in this list, while simultaneously maintaining the list in alphabetical order for three keys: Subject, Author, and Title.
Input
1. The book information created in previous executions of this program, if any, is stored in text file "books.txt". Each book's information is on three consecutive lines. The format of each line is described in the table below:

Line Information
1 Book Title
2 Author (last name, first name)
3 Subject

2. The program inputs commands from the user (keyboard) to insert, delete, list by key, and quit. You are free to implement the "user interface" part of the program as you wish, as long as it is easy to use.
Output
1. The results of each operation should be written to the screen. In addition, transaction information describing the processing of each command should be written to an output file. (For instance, for an Insert command, the output file should contain the title, author, and subject information, as well as the location where the record was inserted and the location of its entry in each ordering array.) The information in the output file should be neatly formatted and clearly labeled.
2. The "books.txt" text file should be rewritten to contain the updated book information.
Data Structures
The records containing information about each book (subject, author, and title strings) must be stored in an unsorted list. These records may be stored in consecutive array slots in the order in which they are inserted. For example, if the book information is stored in an list called bookData, bookData.info[0] contains information about the first book inserted, bookData.info[1] contains information about the second book inserted and so on.

The list must be maintained in order by title, in order by author, and in order by subject by using arrays of pointers (indexes), one for each key. For instance, suppose the key order information is stored in sorted lists: titleOrder, authorOrder and subjectOrder.
The zero'th array slot contains the index of the first book record with the appropriate key. For example, titleOrder.info[0] indicates the index of the book that comes first alphabetically by title. If titleOrder.info[0] = 5, then bookData.info[5] contains the first alphabetical title. The next book, in alphabetical order by title, would be found in the bookData array at the index indicated by titleOrder.info[1]. For index >= 0, titleOrder.info[index]contains the index in bookData of the next title in the alphabetic ordering. The authorOrder and subjectOrder lists work similarly.
Commands
The program must be able to process the following commands:
Insert a Book
Prompt the user for the author, title, and subject. Add entry for this book in the next available location in the bookData list, then update the titleOrder, authorOrder, and subjectOrder lists. Print a message to the screen and write transaction information to the output file. If the bookData list is full, print an error message and abort the insertion, leaving all of the lists unchanged.

Delete a Book
Prompt the user for the name of the book to delete. (You can assume that this is a unique key.) Search for the title to be deleted. If it is found, all the ordering lists must be updated. Print a message to the screen and write transaction information to the output file. If the book is not found, leave the lists unchanged, and print an error message.

List by Key
Prompt the user to specify which key to use for ordering the output. Print out the information about each book, in the indicated order, to the screen and to the transaction file. Format this information clearly. If the list is empty, print an appropriate message.

Quit
Prompt the user to verify that he or she wants to quit; if so, save the book information to file "books.txt" and terminate the program.


thank....;P

write a program that maintains a list of books for a library. The program must accept commands to make insertions and deletions in this list, while simultaneously maintaining the list in alphabetical order for three keys: Subject, Author, and Title.
Input
1. The book information created in previous executions of this program, if any, is stored in text file "books.txt". Each book's information is on three consecutive lines. The format of each line is described in the table below:

Line In
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.