tray icon
This commit is contained in:
@@ -41,6 +41,7 @@ class ApplicationSettings {
|
|||||||
public:
|
public:
|
||||||
bool showDisabledDevices = false;
|
bool showDisabledDevices = false;
|
||||||
bool fitWindowHeight = true;
|
bool fitWindowHeight = true;
|
||||||
|
bool minimizeToTray = true;
|
||||||
};
|
};
|
||||||
|
|
||||||
class ApplicationData {
|
class ApplicationData {
|
||||||
|
|||||||
@@ -3,25 +3,66 @@
|
|||||||
#pragma comment(linker, "/SUBSYSTEM:windows /ENTRY:mainCRTStartup")
|
#pragma comment(linker, "/SUBSYSTEM:windows /ENTRY:mainCRTStartup")
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
// we need commctrl v6 for LoadIconMetric()
|
||||||
|
// see https://github.com/microsoft/Windows-classic-samples/blob/main/Samples/Win7Samples/winui/shell/appshellintegration/NotificationIcon/NotificationIcon.cpp
|
||||||
|
#pragma comment(linker,"/manifestdependency:\"type='win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' processorArchitecture='*' publicKeyToken='6595b64144ccf1df' language='*'\"")
|
||||||
|
#pragma comment(lib, "comctl32.lib")
|
||||||
|
|
||||||
#include <windows.h>
|
#include <windows.h>
|
||||||
|
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
|
#include <shellapi.h>
|
||||||
|
#include <commctrl.h>
|
||||||
|
#include <strsafe.h>
|
||||||
|
|
||||||
#include "Util.h"
|
#include "Util.h"
|
||||||
#include "AudioApi.h"
|
#include "AudioApi.h"
|
||||||
#include "resource.h"
|
#include "resource.h"
|
||||||
#include "AsuroTool.h"
|
#include "AsuroTool.h"
|
||||||
|
|
||||||
|
class __declspec(uuid("3bc52579-15fd-43bb-9686-6273c238535e")) TrayGUID;
|
||||||
|
|
||||||
|
UINT const WMAPP_NOTIFYCALLBACK = WM_APP + 1;
|
||||||
|
UINT const WMAPP_HIDEFLYOUT = WM_APP + 2;
|
||||||
|
|
||||||
|
DrawData* hackyDrawData;
|
||||||
|
ApplicationData* hackyAppData;
|
||||||
|
|
||||||
int main()
|
int main()
|
||||||
{
|
{
|
||||||
ApplicationData applicationData{};
|
ApplicationData applicationData{};
|
||||||
|
|
||||||
startImgui<ApplicationData>(applicationData, init, draw, "Asuro's Tool", 600, 400);
|
startImgui<ApplicationData>(applicationData, init, draw, cleanup, "Asuro's Tool", 600, 400);
|
||||||
|
}
|
||||||
|
|
||||||
|
LRESULT CALLBACK trayIconEventHandler(int code, WPARAM wParam, LPARAM lParam)
|
||||||
|
{
|
||||||
|
if (code >= 0)
|
||||||
|
{
|
||||||
|
CWPSTRUCT* data = (CWPSTRUCT*)lParam;
|
||||||
|
|
||||||
|
if (data->message == WMAPP_NOTIFYCALLBACK)
|
||||||
|
{
|
||||||
|
switch (data->lParam)
|
||||||
|
{
|
||||||
|
case NIN_SELECT:
|
||||||
|
glfwShowWindow(hackyDrawData->window);
|
||||||
|
glfwRestoreWindow(hackyDrawData->window);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return CallNextHookEx(NULL, code, wParam, lParam);
|
||||||
}
|
}
|
||||||
|
|
||||||
void init(DrawData& drawData, ApplicationData& appData)
|
void init(DrawData& drawData, ApplicationData& appData)
|
||||||
{
|
{
|
||||||
|
// sad :(
|
||||||
|
hackyDrawData = &drawData;
|
||||||
|
hackyAppData = &appData;
|
||||||
|
|
||||||
// Load text font
|
// Load text font
|
||||||
ImGuiIO& io = ImGui::GetIO();
|
ImGuiIO& io = ImGui::GetIO();
|
||||||
io.Fonts->AddFontFromFileTTF("Montserrat-Regular.ttf", 18.0f);
|
io.Fonts->AddFontFromFileTTF("Montserrat-Regular.ttf", 18.0f);
|
||||||
@@ -48,12 +89,46 @@ void init(DrawData& drawData, ApplicationData& appData)
|
|||||||
reloadDeviceLists(*appData.audioData);
|
reloadDeviceLists(*appData.audioData);
|
||||||
|
|
||||||
// Set window icon
|
// Set window icon
|
||||||
|
HINSTANCE instance = GetModuleHandle(NULL);
|
||||||
LPWSTR iconId = MAKEINTRESOURCE(IDI_ICON1);
|
LPWSTR iconId = MAKEINTRESOURCE(IDI_ICON1);
|
||||||
HANDLE iconLarge = LoadImageW(GetModuleHandle(NULL), iconId, IMAGE_ICON, 64, 64, 0);
|
HANDLE iconLarge = LoadImageW(instance, iconId, IMAGE_ICON, 64, 64, 0);
|
||||||
HANDLE iconSmall = LoadImageW(GetModuleHandle(NULL), iconId, IMAGE_ICON, 32, 32, 0);
|
HANDLE iconSmall = LoadImageW(instance, iconId, IMAGE_ICON, 32, 32, 0);
|
||||||
SendMessage(drawData.window_handle, WM_SETICON, ICON_BIG, (LPARAM)iconLarge);
|
SendMessage(drawData.window_handle, WM_SETICON, ICON_BIG, (LPARAM)iconLarge);
|
||||||
SendMessage(drawData.window_handle, WM_SETICON, ICON_SMALL, (LPARAM)iconSmall);
|
SendMessage(drawData.window_handle, WM_SETICON, ICON_SMALL, (LPARAM)iconSmall);
|
||||||
SendMessage(drawData.window_handle, WM_SETICON, ICON_SMALL2, (LPARAM)iconSmall);
|
SendMessage(drawData.window_handle, WM_SETICON, ICON_SMALL2, (LPARAM)iconSmall);
|
||||||
|
|
||||||
|
// Set tray icon
|
||||||
|
NOTIFYICONDATA nid = { sizeof(nid) };
|
||||||
|
nid.hWnd = drawData.window_handle;
|
||||||
|
nid.uFlags = NIF_ICON | NIF_TIP | NIF_MESSAGE | NIF_SHOWTIP | NIF_GUID;
|
||||||
|
nid.guidItem = __uuidof(TrayGUID);
|
||||||
|
nid.uCallbackMessage = WMAPP_NOTIFYCALLBACK;
|
||||||
|
|
||||||
|
HRESULT iconResult;
|
||||||
|
iconResult = LoadIconMetric(instance, iconId, LIM_SMALL, &nid.hIcon);
|
||||||
|
isError(iconResult, "Failed to load tray icon image: ");
|
||||||
|
|
||||||
|
iconResult = LoadString(instance, IDS_STRING_TOOLTIP, nid.szTip, ARRAYSIZE(nid.szTip));
|
||||||
|
isError(iconResult, "Failed to load tray icon text: ");
|
||||||
|
|
||||||
|
Shell_NotifyIcon(NIM_ADD, &nid);
|
||||||
|
|
||||||
|
nid.uVersion = NOTIFYICON_VERSION_4;
|
||||||
|
Shell_NotifyIcon(NIM_SETVERSION, &nid);
|
||||||
|
|
||||||
|
// TODO: Add a different kind of hook, that gets mouse events (or other?)
|
||||||
|
if (!SetWindowsHookEx(WH_CALLWNDPROC, trayIconEventHandler, instance, GetCurrentThreadId()))
|
||||||
|
{
|
||||||
|
std::cout << "Failed to hook tray icon events: " << std::hex << GetLastError() << std::endl;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Set window minimize behavior
|
||||||
|
glfwSetWindowIconifyCallback(drawData.window, [](GLFWwindow* window, int isIconified) {
|
||||||
|
if (isIconified == GLFW_TRUE && hackyAppData->settings.minimizeToTray)
|
||||||
|
{
|
||||||
|
glfwHideWindow(window);
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
void draw(DrawData& drawData, ApplicationData& appData)
|
void draw(DrawData& drawData, ApplicationData& appData)
|
||||||
@@ -83,6 +158,15 @@ void draw(DrawData& drawData, ApplicationData& appData)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void cleanup(DrawData& drawData, ApplicationData& appData)
|
||||||
|
{
|
||||||
|
// Remove tray icon
|
||||||
|
NOTIFYICONDATA nid = { sizeof(nid) };
|
||||||
|
nid.uFlags = NIF_GUID;
|
||||||
|
nid.guidItem = __uuidof(TrayGUID);
|
||||||
|
bool test = Shell_NotifyIcon(NIM_DELETE, &nid);
|
||||||
|
}
|
||||||
|
|
||||||
ImVec2 menuBar(ApplicationData& appData)
|
ImVec2 menuBar(ApplicationData& appData)
|
||||||
{
|
{
|
||||||
ImVec2 size{};
|
ImVec2 size{};
|
||||||
@@ -93,6 +177,7 @@ ImVec2 menuBar(ApplicationData& appData)
|
|||||||
{
|
{
|
||||||
ImGui::Checkbox("Show Disabled Devices", &appData.settings.showDisabledDevices);
|
ImGui::Checkbox("Show Disabled Devices", &appData.settings.showDisabledDevices);
|
||||||
ImGui::Checkbox("Fit Window Height", &appData.settings.fitWindowHeight);
|
ImGui::Checkbox("Fit Window Height", &appData.settings.fitWindowHeight);
|
||||||
|
ImGui::Checkbox("Minimize To Tray", &appData.settings.minimizeToTray);
|
||||||
ImGui::EndMenu();
|
ImGui::EndMenu();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -7,6 +7,7 @@
|
|||||||
|
|
||||||
void init(DrawData& drawData, ApplicationData& customData);
|
void init(DrawData& drawData, ApplicationData& customData);
|
||||||
void draw(DrawData& drawData, ApplicationData& customData);
|
void draw(DrawData& drawData, ApplicationData& customData);
|
||||||
|
void cleanup(DrawData& drawData, ApplicationData& appData);
|
||||||
ImVec2 menuBar(ApplicationData& appData);
|
ImVec2 menuBar(ApplicationData& appData);
|
||||||
ImVec2 audioDeviceWindow(ApplicationData& appData, std::vector<AudioDevice>& deviceList, const char* title);
|
ImVec2 audioDeviceWindow(ApplicationData& appData, std::vector<AudioDevice>& deviceList, const char* title);
|
||||||
void drawCircle(float radius, ImU32 color);
|
void drawCircle(float radius, ImU32 color);
|
||||||
|
|||||||
@@ -64,6 +64,17 @@ LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_UK
|
|||||||
// remains consistent on all systems.
|
// remains consistent on all systems.
|
||||||
IDI_ICON1 ICON "kaiju.ico"
|
IDI_ICON1 ICON "kaiju.ico"
|
||||||
|
|
||||||
|
|
||||||
|
/////////////////////////////////////////////////////////////////////////////
|
||||||
|
//
|
||||||
|
// String Table
|
||||||
|
//
|
||||||
|
|
||||||
|
STRINGTABLE
|
||||||
|
BEGIN
|
||||||
|
IDS_STRING_TOOLTIP "uwu"
|
||||||
|
END
|
||||||
|
|
||||||
#endif // English (United Kingdom) resources
|
#endif // English (United Kingdom) resources
|
||||||
/////////////////////////////////////////////////////////////////////////////
|
/////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
|||||||
@@ -3,12 +3,14 @@
|
|||||||
// Used by AsuroTool.rc
|
// Used by AsuroTool.rc
|
||||||
//
|
//
|
||||||
#define IDI_ICON1 109
|
#define IDI_ICON1 109
|
||||||
|
#define IDS_STRING112 112
|
||||||
|
#define IDS_STRING_TOOLTIP 112
|
||||||
|
|
||||||
// Next default values for new objects
|
// Next default values for new objects
|
||||||
//
|
//
|
||||||
#ifdef APSTUDIO_INVOKED
|
#ifdef APSTUDIO_INVOKED
|
||||||
#ifndef APSTUDIO_READONLY_SYMBOLS
|
#ifndef APSTUDIO_READONLY_SYMBOLS
|
||||||
#define _APS_NEXT_RESOURCE_VALUE 112
|
#define _APS_NEXT_RESOURCE_VALUE 113
|
||||||
#define _APS_NEXT_COMMAND_VALUE 40001
|
#define _APS_NEXT_COMMAND_VALUE 40001
|
||||||
#define _APS_NEXT_CONTROL_VALUE 1001
|
#define _APS_NEXT_CONTROL_VALUE 1001
|
||||||
#define _APS_NEXT_SYMED_VALUE 101
|
#define _APS_NEXT_SYMED_VALUE 101
|
||||||
|
|||||||
@@ -15,6 +15,7 @@
|
|||||||
|
|
||||||
class DrawData {
|
class DrawData {
|
||||||
public:
|
public:
|
||||||
|
GLFWwindow* window = nullptr;
|
||||||
HWND window_handle = nullptr;
|
HWND window_handle = nullptr;
|
||||||
ImVec4 clear_color = {};
|
ImVec4 clear_color = {};
|
||||||
ImVec2 window_size = {};
|
ImVec2 window_size = {};
|
||||||
@@ -344,7 +345,7 @@ static void glfw_error_callback(int error, const char* description)
|
|||||||
}
|
}
|
||||||
|
|
||||||
template<typename D>
|
template<typename D>
|
||||||
int startImgui(D& customState, void (*const initFunc)(DrawData&, D&), void (*const drawFunc)(DrawData&, D&), const char* title, int windowWidth, int windowHeight)
|
int startImgui(D& customState, void (*const initFunc)(DrawData&, D&), void (*const drawFunc)(DrawData&, D&), void (*const cleanupFunc)(DrawData&, D&), const char* title, int windowWidth, int windowHeight)
|
||||||
{
|
{
|
||||||
// Setup GLFW window
|
// Setup GLFW window
|
||||||
glfwSetErrorCallback(glfw_error_callback);
|
glfwSetErrorCallback(glfw_error_callback);
|
||||||
@@ -421,6 +422,7 @@ int startImgui(D& customState, void (*const initFunc)(DrawData&, D&), void (*con
|
|||||||
|
|
||||||
// Our state
|
// Our state
|
||||||
DrawData drawData{};
|
DrawData drawData{};
|
||||||
|
drawData.window = window;
|
||||||
drawData.window_handle = glfwGetWin32Window(window);
|
drawData.window_handle = glfwGetWin32Window(window);
|
||||||
drawData.window_size = getWindowSize(window);
|
drawData.window_size = getWindowSize(window);
|
||||||
|
|
||||||
@@ -511,6 +513,7 @@ int startImgui(D& customState, void (*const initFunc)(DrawData&, D&), void (*con
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Cleanup
|
// Cleanup
|
||||||
|
cleanupFunc(drawData, customState);
|
||||||
err = vkDeviceWaitIdle(g_Device);
|
err = vkDeviceWaitIdle(g_Device);
|
||||||
check_vk_result(err);
|
check_vk_result(err);
|
||||||
ImGui_ImplVulkan_Shutdown();
|
ImGui_ImplVulkan_Shutdown();
|
||||||
|
|||||||
@@ -12,7 +12,7 @@ int main()
|
|||||||
{
|
{
|
||||||
ApplicationData applicationData{};
|
ApplicationData applicationData{};
|
||||||
|
|
||||||
startImgui<ApplicationData>(applicationData, init, draw, "Node Test", 1280, 720);
|
startImgui<ApplicationData>(applicationData, init, draw, nullptr, "Node Test", 1280, 720);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|||||||
Reference in New Issue
Block a user