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:
- Struct
Traydata
- {
Hwnd
Hwnd;
Uint
UID;
Uint
Ucallbackmessage;
DWORD
Reserved [2];
Hicon
Hicon;
// Handle of the tray icon
- };
To get this hicon, it is actually very simple:
- // Allocate virtual memory
- Lngaddress = virtualallocex (hprocess, null,
Sizeof
(Tbbutton), mem_commit, page_readwrite );
- // Get the content (size: sizeof (tbbutton) in the hprocess whose address is lngaddress to TB
- Ret =: readprocessmemory (hprocess, lpvoid (
Long
(Lngaddress), & TB,
Sizeof
(Tbbutton), 0 );
- // Get the content in the hprocess whose address is TB. dwdata (size: sizeof (traydata) to tray.
- 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:
- M_imagelist.create (16, 16, ilc_color24, 16, 16 );
- M_listctl.setimagelist (& m_imagelist, lvsil_small );
- M_listctl.setextendedstyle (lvs_ex_fullrowselect );
- M_listctl.insertcolumn (0,
"Icon"
, Lvcfmt_left, 50 );
- M_listctl.insertcolumn (1,
"Application Path"
, Lvcfmt_left, 500 );
- M_listctl.insertcolumn (2,
"Prompt information"
, Lvcfmt_left, 300 );
Finally, enter the obtained information in the control:
- LV. isubitem = 0;
- LV. Mask = lvif_image;
- LV. iItem = m_listctl.getitemcount ();
If
(Geticoninfo (tray. hicon, & icon_info )! = 0)
- {
- LV. iimage = m_imagelist.add (tray. hicon );
- : Zeromemory (& icon_info,
Sizeof
(Iconinfo ));
- }
- M_tifovec.push_back (tifo );
Int
Index = m_listctl.insertitem (& LV );
- M_listctl.setitemtext (index, 1, getfilenamefrompid (dwprocessid ));
If
(! (Tb. fsstate & tbstate_hidden ))
- {
- Ret =: readprocessmemory (hprocess,
Lpvoid
(Tb. istring), & strbuff );
- Uses_conversion;
- M_listctl.setitemtext (index, 2, ole2t (lpolestr) (strbuff )));
- }
Else
- {
- M_listctl.setitemtext (index, 2,
"[Hidden icon]"
);
- }
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.
.