Hide the Windows tray icon

Source: Internet
Author: User

I have written an article on task bar icon programming in windows.
In fact, that article is about how to minimize our programs to pallets and operate on programming methods. I saw the Forum two days ago.
Someone talked about how to hide the tray icon. I remember I wrote a program for a friend to hide the big smart software. The method is to minimize the window and hide the icon of the big smart on the tray, however, this is not the case because it involves keyboard hooks. Instead, you can add a virtual desktop.
Method To achieve the effect.

See this post
I vaguely think of some of my previous attempts. I usually don't have the motivation to sort out a few pieces of code. This is a chance for myself.
First, use Spy ++ to find the window class of the system tray:

We can see that the toolbarwindow32 we need is actually hierarchical, but we cannot directly use findwindow to obtain the toolbarwindow32 handle. Instead, we should look for it in depth like the following code.

  1. Hwnd =: findwindow (
    "Shell_traywnd"
    , Null );
  2. Hwnd =: find1_wex (hwnd, 0,
    "Traypolicywnd"
    , Null );
  3. Hwndtmp =: find1_wex (hwnd, 0,
    "Syspager"
    , Null );
  4. If
    (! Hwndtmp)
  5. Hwnd =: find1_wex (hwnd, 0,
    "Toolbarwindow32"
    , Null );
  6. Else
  7. Hwnd =: find1_wex (hwndtmp, 0,
    "Toolbarwindow32"
    , Null );

Our goal is to hide the system tray icon, which is obviously a cross-process operation. Therefore, we need to know which process is maintaining these icons and the window handle, it is easier to obtain the process behind it:

  1. Ret =: getwindowthreadprocessid (hwnd, & lngpid );
  2. Hprocess =: OpenProcess (process_all_access
  3. | Process_vm_operation
  4. | Process_vm_read
  5. | Process_vm_write,
  6. 0,
  7. Lngpid );

First obtain the process ID, then open the process and obtain the process handle.
Then, allocate a memory segment in the process:

  1. Lngaddress = virtualallocex (hprocess, 0, 0x4096, mem_commit, page_readwrite );
  2. Ret =: sendmessage (hwnd, tb_getbutton, I,
    Long
    (Lngaddress ));

Send the tb_getbutton message to the window to obtain the information of the tray button. Here, the lngaddress stores the tbbutton structure, and its content is as follows:

  1. Typedef
     
    Struct
    _ Tbbutton {
  2. Int
    Ibitmap;
    // Zero-based index of Button Image
  3. Int
    Idcommand;
    // Command to be sent when button pressed
  4. Byte
    Fsstate;
    // Button state -- see below
  5. Byte
    Fsstyle;
    // Button style -- see below
  6. DWORD
    Dwdata;
    // Application-defined value
  7. Int
    Istring;
    // Zero-based index of Button label string
  8. } Tbbutton;

When you move the mouse over the system tray icon, some prompts will be displayed, which are saved in dwdata, while idcommand is the ID of tbbutton. We need to hide or display the icon, you must perform operations on the icon ID:

  1. Ret =: readprocessmemory (hprocess,
    Lpvoid
    (Lngtextadr), strbuff, 1024, 0 );
  2. Ret =: readprocessmemory (hprocess,
    Lpvoid
    (
    Long
    (Lngaddress) + 4), & lngbuttonid, 4, 0 );

The prompt information is stored in strbuffer, And the ID is stored in lngbuttonid. With this information, it is very easy to operate the tray icon. For example, I can
Match strbuffer according to certain conditions, and then hide the icon according to the corresponding lngbuttonid. The hidden or display icon sends the tb_hidebutton message.

  1. : Sendmessage (hwnd, tb_hidebutton, bid, makelong (
    True
    , 0 ));
    // Hide the icon
  2. : Sendmessage (hwnd, tb_hidebutton, bid, makelong (
    False
    , 0 ));
    // Display the icon

After the operation is complete, remember to clean up:

  1. : Virtualfreeex (hprocess, lngaddress, 0x4096, mem_release );
  2. : Closehandle (hprocess );

The above is only an operation on an icon. In fact, you can send a tb_buttoncount message, get the number of icons, and then process them cyclically. Here
I wrote
Sample, the first column shows the icon ID, and the second column shows the icon prompt information. Select the icon in ListBox, and click hide to restore.

To sum up, the basic steps for hiding the Windows System Tray Icon are as follows:

1: Get the window handle

2: Open the system process

3: allocate virtual memory and read the process memory to obtain the relevant information.

4: Operation

5: Release the memory and close the process handle.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.