win7下默认显示托盘图标的
文章转自王牌软件
站长推荐:NSetup一键部署软件
一键式完成美化安装包制作,自动增量升级,数据统计,数字签名。应对各种复杂场景,脚本模块化拆分,常规复杂的脚本代码,图形化设置。无需专业的研发经验,轻松完成项目部署。(www.nsetup.cn)
只回答业务咨询
站长推荐:NSetup一键部署软件
一键式完成美化安装包制作,自动增量升级,数据统计,数字签名。应对各种复杂场景,脚本模块化拆分,常规复杂的脚本代码,图形化设置。无需专业的研发经验,轻松完成项目部署。(www.nsetup.cn)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 |
#include "stdafx.h" #include <conio.h> #include <windows.h> #include <Shlwapi.h> #pragma comment(lib, "shlwapi.lib") typedef struct tagNOTIFYITEM { PWSTR pszExeName; PWSTR pszTip; HICON hIcon; HWND hWnd; DWORD dwPreference; UINT uID; GUID guidItem; } NOTIFYITEM, *PNOTIFYITEM; class __declspec(uuid("D782CCBA-AFB0-43F1-94DB-FDA3779EACCB")) INotificationCB : public IUnknown { virtual HRESULT __stdcall Notify (ULONG, NOTIFYITEM *) = 0; }; class __declspec(uuid("FB852B2C-6BAD-4605-9551-F15F87830935")) ITrayNotify : public IUnknown { public: virtual HRESULT __stdcall RegisterCallback(INotificationCB* callback) = 0; virtual HRESULT __stdcall SetPreference(const NOTIFYITEM* notify_item) = 0; virtual HRESULT __stdcall EnableAutoTray(BOOL enabled) = 0; }; class __declspec(uuid("D133CE13-3537-48BA-93A7-AFCD5D2053B4")) ITrayNotifyWindows8 : public IUnknown { public: virtual HRESULT __stdcall RegisterCallback(INotificationCB* callback, unsigned long*) = 0; virtual HRESULT __stdcall UnregisterCallback(unsigned long*) = 0; virtual HRESULT __stdcall SetPreference(NOTIFYITEM const*) = 0; virtual HRESULT __stdcall EnableAutoTray(BOOL) = 0; virtual HRESULT __stdcall DoAction(BOOL) = 0; }; const CLSID CLSID_TrayNotify = {0x25DEAD04, 0x1EAC, 0x4911, {0x9E, 0x3A, 0xAD, 0x0A, 0x4A, 0xB5, 0x60, 0xFD}}; class NotificationMgr : public INotificationCB { public: NotificationMgr(){ m_pTrayNotify = NULL; } HRESULT __stdcall QueryInterface ( REFIID riid, PVOID *ppv) { if (ppv == NULL) return E_POINTER; if (riid == __uuidof (INotificationCB)) { *ppv = (INotificationCB *) this; }else if (riid == IID_IUnknown) { *ppv = (IUnknown *) this; }else{ return E_NOINTERFACE; } ((IUnknown *) *ppv) -> AddRef (); return S_OK; } ULONG __stdcall AddRef (VOID) { return 1; } ULONG __stdcall Release (VOID) { return 1; } HRESULT __stdcall Notify (ULONG Event, NOTIFYITEM * NotifyItem){ printf("event:%d Preference:%d id:%d path:%ls\n", Event, NotifyItem->dwPreference, NotifyItem->uID, NotifyItem->pszExeName); if (StrStrIW(NotifyItem->pszExeName, L"qq.exe")){ if (m_pTrayNotify){ NotifyItem->dwPreference = 2; m_pTrayNotify->SetPreference(NotifyItem); } } return S_OK; } public: ITrayNotify * m_pTrayNotify; }; int _tmain(int argc, _TCHAR* argv[]) { ITrayNotify *pTrayNotify; NOTIFYITEM NotifyItem = {0}; NotificationMgr NotiMgr; CoInitialize(NULL); // // for win7 // HRESULT hr = CoCreateInstance ( CLSID_TrayNotify, NULL, CLSCTX_LOCAL_SERVER, __uuidof(ITrayNotify), (PVOID *)&pTrayNotify); if (!SUCCEEDED(hr)){ printf("create instance of ITrayNotify error\n"); return -1; } // // register callback // NotiMgr.m_pTrayNotify = pTrayNotify; hr = pTrayNotify->RegisterCallback(&NotiMgr); printf("over\n"); pTrayNotify->RegisterCallback(NULL); pTrayNotify->Release(); _getch(); return 0; } |
之前
之后
http://bbs.pediy.com/thread-202658.htm
学习日记,兼职软件设计,软件修改,毕业设计。
本文出自 学习日记,转载时请注明出处及相应链接。
本文永久链接: https://www.softwareace.cn/?p=1684