mirror of
https://git.tartarus.org/simon/putty.git
synced 2025-04-17 19:18:06 -05:00
John Sullivan's patch to recreate the Pageant systray icon if
Explorer crashes and restarts while Pageant is running. [originally from svn r1299]
This commit is contained in:
parent
36e6d63b66
commit
988ef91d5f
76
pageant.c
76
pageant.c
@ -1075,13 +1075,51 @@ static int CALLBACK KeyListProc(HWND hwnd, UINT msg,
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Set up a system tray icon */
|
||||||
|
static BOOL AddTrayIcon(HWND hwnd)
|
||||||
|
{
|
||||||
|
BOOL res;
|
||||||
|
NOTIFYICONDATA tnid;
|
||||||
|
HICON hicon;
|
||||||
|
|
||||||
|
#ifdef NIM_SETVERSION
|
||||||
|
tnid.uVersion = 0;
|
||||||
|
res = Shell_NotifyIcon(NIM_SETVERSION, &tnid);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
tnid.cbSize = sizeof(NOTIFYICONDATA);
|
||||||
|
tnid.hWnd = hwnd;
|
||||||
|
tnid.uID = 1; /* unique within this systray use */
|
||||||
|
tnid.uFlags = NIF_MESSAGE | NIF_ICON | NIF_TIP;
|
||||||
|
tnid.uCallbackMessage = WM_SYSTRAY;
|
||||||
|
tnid.hIcon = hicon = LoadIcon(instance, MAKEINTRESOURCE(201));
|
||||||
|
strcpy(tnid.szTip, "Pageant (PuTTY authentication agent)");
|
||||||
|
|
||||||
|
res = Shell_NotifyIcon(NIM_ADD, &tnid);
|
||||||
|
|
||||||
|
if (hicon) DestroyIcon(hicon);
|
||||||
|
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
|
||||||
static LRESULT CALLBACK WndProc(HWND hwnd, UINT message,
|
static LRESULT CALLBACK WndProc(HWND hwnd, UINT message,
|
||||||
WPARAM wParam, LPARAM lParam)
|
WPARAM wParam, LPARAM lParam)
|
||||||
{
|
{
|
||||||
int ret;
|
int ret;
|
||||||
static int menuinprogress;
|
static int menuinprogress;
|
||||||
|
static UINT msgTaskbarCreated = 0;
|
||||||
|
|
||||||
switch (message) {
|
switch (message) {
|
||||||
|
case WM_CREATE:
|
||||||
|
msgTaskbarCreated = RegisterWindowMessage(_T("TaskbarCreated"));
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
if (message==msgTaskbarCreated) {
|
||||||
|
// Explorer has been restarted, so the tray icon will have been lost
|
||||||
|
AddTrayIcon(hwnd);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
case WM_SYSTRAY:
|
case WM_SYSTRAY:
|
||||||
if (lParam == WM_RBUTTONUP) {
|
if (lParam == WM_RBUTTONUP) {
|
||||||
POINT cursorpos;
|
POINT cursorpos;
|
||||||
@ -1342,37 +1380,15 @@ int WINAPI WinMain(HINSTANCE inst, HINSTANCE prev, LPSTR cmdline, int show)
|
|||||||
100, 100, NULL, NULL, inst, NULL);
|
100, 100, NULL, NULL, inst, NULL);
|
||||||
|
|
||||||
/* Set up a system tray icon */
|
/* Set up a system tray icon */
|
||||||
{
|
AddTrayIcon(hwnd);
|
||||||
BOOL res;
|
|
||||||
NOTIFYICONDATA tnid;
|
|
||||||
HICON hicon;
|
|
||||||
|
|
||||||
#ifdef NIM_SETVERSION
|
systray_menu = CreatePopupMenu();
|
||||||
tnid.uVersion = 0;
|
/* accelerators used: vkxa */
|
||||||
res = Shell_NotifyIcon(NIM_SETVERSION, &tnid);
|
AppendMenu(systray_menu, MF_ENABLED, IDM_VIEWKEYS,
|
||||||
#endif
|
"&View Keys");
|
||||||
|
AppendMenu(systray_menu, MF_ENABLED, IDM_ADDKEY, "Add &Key");
|
||||||
tnid.cbSize = sizeof(NOTIFYICONDATA);
|
AppendMenu(systray_menu, MF_ENABLED, IDM_ABOUT, "&About");
|
||||||
tnid.hWnd = hwnd;
|
AppendMenu(systray_menu, MF_ENABLED, IDM_CLOSE, "E&xit");
|
||||||
tnid.uID = 1; /* unique within this systray use */
|
|
||||||
tnid.uFlags = NIF_MESSAGE | NIF_ICON | NIF_TIP;
|
|
||||||
tnid.uCallbackMessage = WM_SYSTRAY;
|
|
||||||
tnid.hIcon = hicon = LoadIcon(instance, MAKEINTRESOURCE(201));
|
|
||||||
strcpy(tnid.szTip, "Pageant (PuTTY authentication agent)");
|
|
||||||
|
|
||||||
res = Shell_NotifyIcon(NIM_ADD, &tnid);
|
|
||||||
|
|
||||||
if (hicon)
|
|
||||||
DestroyIcon(hicon);
|
|
||||||
|
|
||||||
systray_menu = CreatePopupMenu();
|
|
||||||
/* accelerators used: vkxa */
|
|
||||||
AppendMenu(systray_menu, MF_ENABLED, IDM_VIEWKEYS,
|
|
||||||
"&View Keys");
|
|
||||||
AppendMenu(systray_menu, MF_ENABLED, IDM_ADDKEY, "Add &Key");
|
|
||||||
AppendMenu(systray_menu, MF_ENABLED, IDM_ABOUT, "&About");
|
|
||||||
AppendMenu(systray_menu, MF_ENABLED, IDM_CLOSE, "E&xit");
|
|
||||||
}
|
|
||||||
|
|
||||||
ShowWindow(hwnd, SW_HIDE);
|
ShowWindow(hwnd, SW_HIDE);
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user