|
|
|
|
@@ -3,25 +3,66 @@
|
|
|
|
|
#pragma comment(linker, "/SUBSYSTEM:windows /ENTRY:mainCRTStartup")
|
|
|
|
|
#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 <iostream>
|
|
|
|
|
#include <sstream>
|
|
|
|
|
#include <shellapi.h>
|
|
|
|
|
#include <commctrl.h>
|
|
|
|
|
#include <strsafe.h>
|
|
|
|
|
|
|
|
|
|
#include "Util.h"
|
|
|
|
|
#include "AudioApi.h"
|
|
|
|
|
#include "resource.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()
|
|
|
|
|
{
|
|
|
|
|
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)
|
|
|
|
|
{
|
|
|
|
|
// sad :(
|
|
|
|
|
hackyDrawData = &drawData;
|
|
|
|
|
hackyAppData = &appData;
|
|
|
|
|
|
|
|
|
|
// Load text font
|
|
|
|
|
ImGuiIO& io = ImGui::GetIO();
|
|
|
|
|
io.Fonts->AddFontFromFileTTF("Montserrat-Regular.ttf", 18.0f);
|
|
|
|
|
@@ -48,12 +89,46 @@ void init(DrawData& drawData, ApplicationData& appData)
|
|
|
|
|
reloadDeviceLists(*appData.audioData);
|
|
|
|
|
|
|
|
|
|
// Set window icon
|
|
|
|
|
HINSTANCE instance = GetModuleHandle(NULL);
|
|
|
|
|
LPWSTR iconId = MAKEINTRESOURCE(IDI_ICON1);
|
|
|
|
|
HANDLE iconLarge = LoadImageW(GetModuleHandle(NULL), iconId, IMAGE_ICON, 64, 64, 0);
|
|
|
|
|
HANDLE iconSmall = LoadImageW(GetModuleHandle(NULL), iconId, IMAGE_ICON, 32, 32, 0);
|
|
|
|
|
HANDLE iconLarge = LoadImageW(instance, iconId, IMAGE_ICON, 64, 64, 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_SMALL, (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)
|
|
|
|
|
@@ -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 size{};
|
|
|
|
|
@@ -93,6 +177,7 @@ ImVec2 menuBar(ApplicationData& appData)
|
|
|
|
|
{
|
|
|
|
|
ImGui::Checkbox("Show Disabled Devices", &appData.settings.showDisabledDevices);
|
|
|
|
|
ImGui::Checkbox("Fit Window Height", &appData.settings.fitWindowHeight);
|
|
|
|
|
ImGui::Checkbox("Minimize To Tray", &appData.settings.minimizeToTray);
|
|
|
|
|
ImGui::EndMenu();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|