Hide the Windows System Tray Icon)

Source: Internet
Author: User

In the previous article
, Write a sample
, Used to hide the icon, but some netizens suggested whether the current tray icon can be displayed on the program interface, which is more intuitive. I have thought of this, and I know the mysteries in the dwdata FIELD OF THE tbbutton struct. Unfortunately, the structure of this domain is in the msdn
. I also tried to send the tb_getimagelist message to get the image list handle, and then loaded it into cimagelist with cimagelist: fromhandle, but all failed.

In csdn
With the help of netizens, I figured out the structure of dwdata and improved the program accordingly. The following figure shows the running of the Community version.

In fact, dwdata has a mechanism named traydata:

  1. Struct
    Traydata
  2. {

  3. Hwnd
    Hwnd;

  4. Uint
    UID;

  5. Uint
    Ucallbackmessage;

  6. DWORD
    Reserved [2];

  7. Hicon
    Hicon;
    // Handle of the tray icon
  8. };

To get this hicon, it is actually very simple:

  1. // Allocate virtual memory
  2. Lngaddress = virtualallocex (hprocess, null,
    Sizeof
    (Tbbutton), mem_commit, page_readwrite );
  3. // Get the content (size: sizeof (tbbutton) in the hprocess whose address is lngaddress to TB
  4. Ret =: readprocessmemory (hprocess, lpvoid (
    Long
    (Lngaddress), & TB,
    Sizeof
    (Tbbutton), 0 );

  5. // Get the content in the hprocess whose address is TB. dwdata (size: sizeof (traydata) to tray.
  6. Ret =: readprocessmemory (hprocess, lpvoid (Tb. dwdata), & tray,
    Sizeof
    (Traydata), 0 );

Then you can use tray. hicon indexes the icon handle, and we can also use tray. hwnd obtains the execution path of the process in which it is located. Finally, we add a clistcontrol control and initialize the control during oninitdialog:

  1. M_imagelist.create (16, 16, ilc_color24, 16, 16 );
  2. M_listctl.setimagelist (& m_imagelist, lvsil_small );
  3. M_listctl.setextendedstyle (lvs_ex_fullrowselect );
  4. M_listctl.insertcolumn (0,
    "Icon"
    , Lvcfmt_left, 50 );
  5. M_listctl.insertcolumn (1,
    "Application Path"
    , Lvcfmt_left, 500 );
  6. M_listctl.insertcolumn (2,
    "Prompt information"
    , Lvcfmt_left, 300 );

Finally, enter the obtained information in the control:

  1. LV. isubitem = 0;
  2. LV. Mask = lvif_image;
  3. LV. iItem = m_listctl.getitemcount ();

  4. If
    (Geticoninfo (tray. hicon, & icon_info )! = 0)
  5. {
  6. LV. iimage = m_imagelist.add (tray. hicon );
  7. : Zeromemory (& icon_info,
    Sizeof
    (Iconinfo ));
  8. }
  9. M_tifovec.push_back (tifo );

  10. Int
    Index = m_listctl.insertitem (& LV );
  11. M_listctl.setitemtext (index, 1, getfilenamefrompid (dwprocessid ));

  12. If
    (! (Tb. fsstate & tbstate_hidden ))
  13. {
  14. Ret =: readprocessmemory (hprocess,
    Lpvoid
    (Tb. istring), & strbuff );
  15. Uses_conversion;
  16. M_listctl.setitemtext (index, 2, ole2t (lpolestr) (strbuff )));
  17. }

  18. Else
  19. {
  20. M_listctl.setitemtext (index, 2,
    "[Hidden icon]"
    );
  21. }

In addition, because we can get the process ID, we can have more applications, which will not be demonstrated here. The code of this release version can be downloaded here.
.

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.