From 50ad10f2c4eaf4f11d0d109b184b0653a9968da0 Mon Sep 17 00:00:00 2001 From: Hendrik Langer Date: Wed, 18 Jul 2018 23:55:55 +0200 Subject: [PATCH] tray icon behaviour --- windows-snapshot-tool/src/main.cpp | 16 +++++++++++++--- windows-snapshot-tool/src/resource.h | 3 ++- 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/windows-snapshot-tool/src/main.cpp b/windows-snapshot-tool/src/main.cpp index 22a60cc..0c052cc 100644 --- a/windows-snapshot-tool/src/main.cpp +++ b/windows-snapshot-tool/src/main.cpp @@ -14,6 +14,7 @@ const wchar_t* szClassName = L"IUL Snapshot Tool."; LRESULT CALLBACK WindowProcedure (HWND, UINT, WPARAM, LPARAM); void minimize(); void restore(); +void doScreenshot(); void InitNotifyIconData(); int CaptureImage(HWND hWnd, const wchar_t* filename); void getRaspiStorage(LPWSTR out); @@ -110,7 +111,8 @@ LRESULT CALLBACK WindowProcedure (HWND hwnd, UINT message, WPARAM wParam, LPARAM ShowWindow(Hwnd, SW_HIDE); Hmenu = CreatePopupMenu(); - AppendMenu(Hmenu, MF_STRING, ID_TRAY_EXIT, TEXT( "Exit The Demo" ) ); + AppendMenu(Hmenu, MF_STRING, ID_TRAY_OPEN, TEXT( "Open" ) ); + AppendMenu(Hmenu, MF_STRING, ID_TRAY_EXIT, TEXT( "Exit" ) ); break; @@ -146,7 +148,7 @@ LRESULT CALLBACK WindowProcedure (HWND hwnd, UINT message, WPARAM wParam, LPARAM if (lParam == WM_LBUTTONUP) { - restore(); + doScreenshot(); } else if (lParam == WM_RBUTTONDOWN) { @@ -162,6 +164,10 @@ LRESULT CALLBACK WindowProcedure (HWND hwnd, UINT message, WPARAM wParam, LPARAM SendMessage(hwnd, WM_NULL, 0, 0); // send benign message to window to make sure the menu goes away. + if (clicked == ID_TRAY_OPEN) + { + restore(); + } if (clicked == ID_TRAY_EXIT) { // quit the application. @@ -175,7 +181,7 @@ LRESULT CALLBACK WindowProcedure (HWND hwnd, UINT message, WPARAM wParam, LPARAM case WM_HOTKEY_FREEZE: { - restore(); + doScreenshot(); } break; @@ -216,6 +222,10 @@ void minimize() void restore() { ShowWindow(Hwnd, SW_SHOW); +} + +void doScreenshot() +{ WCHAR path[12]; getRaspiStorage(path); CaptureImage(Hwnd, L"file.bmp"); diff --git a/windows-snapshot-tool/src/resource.h b/windows-snapshot-tool/src/resource.h index 7a4d8ce..632d43c 100644 --- a/windows-snapshot-tool/src/resource.h +++ b/windows-snapshot-tool/src/resource.h @@ -3,6 +3,7 @@ #define ICO1 101 #define ID_TRAY_APP_ICON 1001 -#define ID_TRAY_EXIT 1002 +#define ID_TRAY_OPEN 1002 +#define ID_TRAY_EXIT 1003 #define WM_SYSICON (WM_USER + 1) #define WM_HOTKEY_FREEZE (WM_USER + 2)