From c73736dc76e116ddd95e23f9d7cc0aecb182f7c8 Mon Sep 17 00:00:00 2001 From: Ronny Fretel Date: Mon, 25 Jul 2016 15:47:15 -0500 Subject: [PATCH 1/8] Systray implementation --- audio-router-gui/app_list.cpp | 140 +++++---- audio-router-gui/audio-router-gui.vcxproj | 12 +- .../audio-router-gui.vcxproj.filters | 6 + audio-router-gui/clsSysTray.cpp | 91 ++++++ audio-router-gui/clsSysTray.h | 27 ++ audio-router-gui/dialog_main.cpp | 4 +- audio-router-gui/main.cpp | 265 +++++++++--------- audio-router-gui/resource.h | Bin 3176 -> 3502 bytes audio-router-gui/window.cpp | 30 +- audio-router-gui/window.h | 12 +- audio-router/audio-router.vcxproj | 10 +- audio-router/patcher.h | 172 ++++++------ bootstrapper/bootstrapper.vcxproj | 10 +- do/do.vcxproj | 10 +- 14 files changed, 469 insertions(+), 320 deletions(-) create mode 100644 audio-router-gui/clsSysTray.cpp create mode 100644 audio-router-gui/clsSysTray.h diff --git a/audio-router-gui/app_list.cpp b/audio-router-gui/app_list.cpp index 1f920b3..fe03bd1 100644 --- a/audio-router-gui/app_list.cpp +++ b/audio-router-gui/app_list.cpp @@ -1,114 +1,100 @@ #include "app_list.h" -#include -#include +#include < Psapi.h > +#include < algorithm > -bool app_list::populate_list(bool x86, const filters_t& filters) -{ - DWORD processes[1024], needed; - if(!EnumProcesses(processes, sizeof(processes), &needed)) - return false; +bool app_list::populate_list(bool x86, const filters_t & filters) { + DWORD processes[1024], needed; + if ( ! EnumProcesses(processes, sizeof(processes), & needed)) + return false; - for(DWORD i = 0; i < (needed / sizeof(DWORD)); i++) - { - app_info info; - info.id = processes[i]; - if(this->get_app_info(info, filters, x86, true)) - this->apps.push_back(info); + for (DWORD i = 0; i < (needed / sizeof(DWORD)); i++) { + app_info info; + info.id = processes[i]; + if (this->get_app_info(info, filters, x86, true)) + this->apps.push_back(info); } - return true; + return true; } -bool app_list::populate_list() -{ - filters_t filters; - filters.push_back(L"mmdevapi.dll"); - return this->populate_list(filters); +bool app_list::populate_list() { + filters_t filters; + filters.push_back(L"mmdevapi.dll"); + return this->populate_list(filters); } -bool app_list::populate_list(const filters_t& filters) -{ - this->apps.clear(); +bool app_list::populate_list(const filters_t & filters) { + this->apps.clear(); - if(!this->populate_list(true, filters)) - return false; + if ( ! this-> populate_list(true, filters)) + return false; #ifdef _WIN64 - return this->populate_list(false, filters); + return this - > populate_list(false, filters); #else - return true; + return true; #endif } -bool app_list::get_app_info(app_info& info, const filters_t& filters, bool x86, bool query_name) -{ - HMODULE hmodules[1024]; - DWORD needed; +bool app_list::get_app_info(app_info & info, const filters_t & filters, bool x86, bool query_name) { + HMODULE hmodules[1024]; + DWORD needed; HANDLE hprocess = OpenProcess( - PROCESS_QUERY_INFORMATION | PROCESS_VM_READ, - FALSE, info.id); - if(hprocess == NULL) - return false; + PROCESS_QUERY_INFORMATION | PROCESS_VM_READ, + FALSE, info.id); + if (hprocess == NULL) + return false; #ifdef _WIN64 - BOOL px86; - if(!IsWow64Process(hprocess, &px86)) - { - CloseHandle(hprocess); - return false; + BOOL px86; + if ( ! IsWow64Process(hprocess, & px86)) { + CloseHandle(hprocess); + return false; } - info.x86 = px86; + info.x86 = px86; #else - info.x86 = true; + info.x86 = true; #endif - if(query_name && EnumProcessModulesEx( - hprocess, hmodules, sizeof(hmodules), - &needed, x86 ? LIST_MODULES_32BIT : LIST_MODULES_64BIT)) - { - WCHAR name[MAX_PATH] = {0}; - std::wstring exename; - if(GetModuleBaseName(hprocess, hmodules[0], name, sizeof(name) / sizeof(WCHAR))) - { - _wcslwr(name); - exename = name; + if (query_name && EnumProcessModulesEx( + hprocess, hmodules, sizeof(hmodules), & needed, x86?LIST_MODULES_32BIT:LIST_MODULES_64BIT)) { + WCHAR name[MAX_PATH] = {0}; + std::wstring exename; + if (GetModuleBaseName(hprocess, hmodules[0], name, sizeof(name)/sizeof(WCHAR))) { + _wcslwr(name); + exename = name; // skip filter - if(filters.empty()) - { - info.name = exename; - CloseHandle(hprocess); - return true; + if (filters.empty()) { + info.name = exename; + CloseHandle(hprocess); + return true; } - for(DWORD j = 0; j < (needed / sizeof(HMODULE)); j++) - { - WCHAR name[MAX_PATH] = {0}; - if(GetModuleBaseName(hprocess, hmodules[j], name, sizeof(name) / sizeof(WCHAR))) - { - _wcslwr(name); - for(filters_t::const_iterator it = filters.begin(); it != filters.end(); it++) - if(*it == name) - { - info.name = exename; - CloseHandle(hprocess); - return true; - }; + for (DWORD j = 0; j < (needed / sizeof(HMODULE)); j++) { + WCHAR name[MAX_PATH] = {0}; + if (GetModuleBaseName(hprocess, hmodules[j], name, sizeof(name)/sizeof(WCHAR))) { + _wcslwr(name); + for (filters_t::const_iterator it = filters.begin(); it != filters.end(); it++) + if ( * it == name) { + info.name = exename; + CloseHandle(hprocess); + return true; + }; } } } } - CloseHandle(hprocess); - return !query_name; + CloseHandle(hprocess); + return ! query_name; } -bool app_list::get_app_info(app_info& info, const filters_t& filters, bool query_name) -{ - if(get_app_info(info, filters, true, query_name)) - return true; +bool app_list::get_app_info(app_info & info, const filters_t & filters, bool query_name) { + if (get_app_info(info, filters, true, query_name)) + return true; #ifdef _WIN64 - return get_app_info(info, filters, false, query_name); + return get_app_info(info, filters, false, query_name); #else - return false; + return false; #endif } \ No newline at end of file diff --git a/audio-router-gui/audio-router-gui.vcxproj b/audio-router-gui/audio-router-gui.vcxproj index 1523f64..b738164 100644 --- a/audio-router-gui/audio-router-gui.vcxproj +++ b/audio-router-gui/audio-router-gui.vcxproj @@ -1,5 +1,5 @@  - + Debug @@ -26,26 +26,26 @@ Application true - v120 + v140 Unicode Application true - v120 + v140 Unicode Application false - v120 + v140 true Unicode Application false - v120 + v140 true Unicode @@ -159,6 +159,7 @@ + @@ -182,6 +183,7 @@ + diff --git a/audio-router-gui/audio-router-gui.vcxproj.filters b/audio-router-gui/audio-router-gui.vcxproj.filters index de1426e..7245f82 100644 --- a/audio-router-gui/audio-router-gui.vcxproj.filters +++ b/audio-router-gui/audio-router-gui.vcxproj.filters @@ -69,6 +69,9 @@ Header Files + + Header Files + @@ -127,6 +130,9 @@ Source Files + + Source Files + diff --git a/audio-router-gui/clsSysTray.cpp b/audio-router-gui/clsSysTray.cpp new file mode 100644 index 0000000..16b91f1 --- /dev/null +++ b/audio-router-gui/clsSysTray.cpp @@ -0,0 +1,91 @@ +#include "clsSysTray.h" +#include "resource.h" + + +clsSysTray::clsSysTray() +{ + bInTray = false; + NotifyIconData.cbSize = sizeof(NotifyIconData); + NotifyIconData.uID = uID = 2; + NotifyIconData.uFlags = NIF_ICON | NIF_TIP | NIF_MESSAGE; + NotifyIconData.uCallbackMessage = WM_TRAYNOTIFY; + NotifyIconData.hIcon = LoadIcon(GetModuleHandle(NULL), MAKEINTRESOURCE(IDR_MAINFRAME)); + NotifyIconData.szTip[0] = '\0'; + NotifyIconData.hWnd = NULL; + + +} + + +clsSysTray::~clsSysTray() +{ +} + +BOOL clsSysTray::SetIcon(HICON hNewIcon) +{ + NotifyIconData.hIcon = hNewIcon; + if (bInTray) + { + BOOL iRetVal; + iRetVal = Shell_NotifyIcon(NIM_MODIFY, &NotifyIconData); + if (iRetVal) + { + bInTray = true; + } + return iRetVal; + } + else + return (1); +} + +HICON clsSysTray::GetIcon() +{ + return NotifyIconData.hIcon; +} + +BOOL clsSysTray::SetTipText(char *lpstrNewTipText) +{ + //strncpy(NotifyIconData.szTip, lpstrNewTipText); + if (bInTray) + { + BOOL iRetVal; + iRetVal = Shell_NotifyIcon(NIM_MODIFY, &NotifyIconData); + if (iRetVal) + { + bInTray = true; + } + return iRetVal; + } + else + return (1); +} + +char *clsSysTray::GetTipText() +{ + return "test"; // NotifyIconData.szTip; +} + +BOOL clsSysTray::AddIcon() +{ + BOOL iRetVal; + NotifyIconData.hWnd = hWnd; + NotifyIconData.uID = uID; + iRetVal = Shell_NotifyIcon(NIM_ADD, &NotifyIconData); + if (iRetVal) + { + bInTray = true; + + } + return iRetVal; +} + +BOOL clsSysTray::RemoveIcon() +{ + BOOL iRetVal; + iRetVal = Shell_NotifyIcon(NIM_DELETE, &NotifyIconData); + if (iRetVal) + { + bInTray = false; + } + return iRetVal; +} diff --git a/audio-router-gui/clsSysTray.h b/audio-router-gui/clsSysTray.h new file mode 100644 index 0000000..8ea7ab2 --- /dev/null +++ b/audio-router-gui/clsSysTray.h @@ -0,0 +1,27 @@ +#pragma once +#pragma warning(disable: 4996) + +#include + +#define WM_TRAYNOTIFY 0XA44C +#include + +class clsSysTray +{ +public: + clsSysTray(); + ~clsSysTray(); + BOOL SetIcon(HICON hNewIcon); + HICON GetIcon(); + BOOL SetTipText(char *lpstrNewTipText); + char *GetTipText(); + BOOL AddIcon(); + BOOL RemoveIcon(); + HWND hWnd; + UINT uID; +protected: + NOTIFYICONDATA NotifyIconData; + bool bInTray; +}; + + diff --git a/audio-router-gui/dialog_main.cpp b/audio-router-gui/dialog_main.cpp index 17aa13b..d4496de 100644 --- a/audio-router-gui/dialog_main.cpp +++ b/audio-router-gui/dialog_main.cpp @@ -15,9 +15,7 @@ dialog_main::~dialog_main() void dialog_main::clear_dialog_arrays() { - for(auto it = this->dialog_arrays.begin(); - it != this->dialog_arrays.end(); - it++) + for (auto it = this->dialog_arrays.begin(); it != this->dialog_arrays.end(); it++) { delete *it; } diff --git a/audio-router-gui/main.cpp b/audio-router-gui/main.cpp index d27a44c..d8cfff8 100644 --- a/audio-router-gui/main.cpp +++ b/audio-router-gui/main.cpp @@ -11,137 +11,144 @@ CAppModule _Module; HANDLE audio_router_mutex; + int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) { - /*srand(time(NULL));*/ - - /*global_routing_params* params = new global_routing_params; - params->version = 0; - params->local.module_name_ptr = (uint64_t)new wchar_t[wcslen(L"full\\path\\to\\module.dll") + 1]; - wcscpy((wchar_t*)params->local.module_name_ptr, L"full\\path\\to\\module.dll"); - params->local.device_id_ptr = (uint64_t)new wchar_t[wcslen(L"device id") + 1]; - wcscpy((wchar_t*)params->local.device_id_ptr, L"device id"); - - global_routing_params* params2 = new global_routing_params; - params2->version = 0; - params2->local.module_name_ptr = (uint64_t)new wchar_t[wcslen(L"full\\path\\to\\module.dll") + 1]; - wcscpy((wchar_t*)params2->local.module_name_ptr, L"full\\path\\to\\module.dll"); - params2->local.device_id_ptr = (uint64_t)new wchar_t[wcslen(L"device id") + 1]; - wcscpy((wchar_t*)params2->local.device_id_ptr, L"device id"); - params->next_global_ptr = (uint64_t)params2; - - global_routing_params* params3 = new global_routing_params; - params3->version = 0; - params3->local.module_name_ptr = (uint64_t)new wchar_t[wcslen(L"full\\path\\to\\module.dll") + 1]; - wcscpy((wchar_t*)params3->local.module_name_ptr, L"full\\path\\to\\module.dll"); - params3->local.device_id_ptr = NULL; - params2->next_global_ptr = (uint64_t)params3; - params3->next_global_ptr = NULL; - - unsigned char* serialized = serialize(params); - free(params); - global_routing_params* serialized_params = rebase(serialized); - - MessageBox(NULL, (wchar_t*)serialized_params->local.module_name_ptr, NULL, 0); - MessageBox(NULL, (wchar_t*)((global_routing_params*)serialized_params->next_global_ptr)->local.device_id_ptr, NULL, 0); - - delete [] serialized_params;*/ - - if(GetModuleHandle(L"Audio Router.exe") == NULL) - { - MessageBox( - NULL, L"Wrong application name. Audio Router will close.", NULL, MB_ICONERROR); - return 0; - } - - { - security_attributes sec(GENERIC_ALL, security_attributes::DEFAULT); - assert(sec.get() != NULL); - audio_router_mutex = CreateMutex(sec.get(), FALSE, L"Local\\audio-router-mutex"); - } - if(audio_router_mutex == NULL) - { - MessageBox( - NULL, L"Mutex creation failed. Audio Router will close.", NULL, MB_ICONERROR); - return 0; - } - else if(GetLastError() == ERROR_ALREADY_EXISTS) - { - CloseHandle(audio_router_mutex); - MessageBox( - NULL, L"Another instance of Audio Router is already running. " \ - L"Audio Router will close.", NULL, MB_ICONERROR); - return 0; - } - - HRESULT hr = CoInitializeEx(NULL, COINIT_MULTITHREADED); - if(hr != S_OK) - { - CloseHandle(audio_router_mutex); - MessageBox( - NULL, L"COM could not be initialized. Audio Router will close.", NULL, MB_ICONERROR); - return 0; - } - - if(_Module.Init(NULL, hInstance) != S_OK) - { - CoUninitialize(); - CloseHandle(audio_router_mutex); - MessageBox( - NULL, L"ATL could not be initialized. Audio Router will close.", NULL, MB_ICONERROR); - return 0; - } - - ULONG_PTR gdiplusToken; - Gdiplus::GdiplusStartupInput gdiplusStartupInput; - if(Gdiplus::GdiplusStartup(&gdiplusToken, &gdiplusStartupInput, NULL) != Gdiplus::Ok) - { - _Module.Term(); - CoUninitialize(); - CloseHandle(audio_router_mutex); - MessageBox( - NULL, L"GDI+ could not be initialized. Audio Router will close.", NULL, MB_ICONERROR); - return 0; - } - - MSG msg = {0}; - //std::unique_ptr bootstrap; - //try - //{ - // // TODO: decide if create a dummy bootstapper in case if the initialization fails - // bootstrap.reset(new bootstrapper); - //} - //catch(std::wstring err) - //{ - // err += L"Audio Router will close."; - // MessageBox(NULL, err.c_str(), NULL, MB_ICONERROR); - // goto cleanup; - //} - { - window win/*(bootstrap.get())*/; - RECT r = {CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT + WIN_WIDTH, CW_USEDEFAULT + WIN_HEIGHT}; - if(win.CreateEx(NULL, &r) == NULL) - { - MessageBox(NULL, L"Could not create window. Audio Router will close.", NULL, MB_ICONERROR); - goto cleanup; - } - win.ShowWindow(nCmdShow); - win.UpdateWindow(); - - while(GetMessage(&msg, NULL, 0, 0) > 0) - { - if(win.dlg_main && IsDialogMessage(*win.dlg_main, &msg)) - continue; - TranslateMessage(&msg); - DispatchMessage(&msg); - } - } + /*srand(time(NULL));*/ + + /*global_routing_params* params = new global_routing_params; + params->version = 0; + params->local.module_name_ptr = (uint64_t)new wchar_t[wcslen(L"full\\path\\to\\module.dll") + 1]; + wcscpy((wchar_t*)params->local.module_name_ptr, L"full\\path\\to\\module.dll"); + params->local.device_id_ptr = (uint64_t)new wchar_t[wcslen(L"device id") + 1]; + wcscpy((wchar_t*)params->local.device_id_ptr, L"device id"); + + global_routing_params* params2 = new global_routing_params; + params2->version = 0; + params2->local.module_name_ptr = (uint64_t)new wchar_t[wcslen(L"full\\path\\to\\module.dll") + 1]; + wcscpy((wchar_t*)params2->local.module_name_ptr, L"full\\path\\to\\module.dll"); + params2->local.device_id_ptr = (uint64_t)new wchar_t[wcslen(L"device id") + 1]; + wcscpy((wchar_t*)params2->local.device_id_ptr, L"device id"); + params->next_global_ptr = (uint64_t)params2; + + global_routing_params* params3 = new global_routing_params; + params3->version = 0; + params3->local.module_name_ptr = (uint64_t)new wchar_t[wcslen(L"full\\path\\to\\module.dll") + 1]; + wcscpy((wchar_t*)params3->local.module_name_ptr, L"full\\path\\to\\module.dll"); + params3->local.device_id_ptr = NULL; + params2->next_global_ptr = (uint64_t)params3; + params3->next_global_ptr = NULL; + + unsigned char* serialized = serialize(params); + free(params); + global_routing_params* serialized_params = rebase(serialized); + + MessageBox(NULL, (wchar_t*)serialized_params->local.module_name_ptr, NULL, 0); + MessageBox(NULL, (wchar_t*)((global_routing_params*)serialized_params->next_global_ptr)->local.device_id_ptr, NULL, 0); + + delete [] serialized_params;*/ + + if (GetModuleHandle(L"Audio Router.exe") == NULL) + { + MessageBox( + NULL, L"Wrong application name. Audio Router will close.", NULL, MB_ICONERROR); + return 0; + } + + { + security_attributes sec(GENERIC_ALL, security_attributes::DEFAULT); + assert(sec.get() != NULL); + audio_router_mutex = CreateMutex(sec.get(), FALSE, L"Local\\audio-router-mutex"); + } + + if (audio_router_mutex == NULL) + { + MessageBox( + NULL, L"Mutex creation failed. Audio Router will close.", NULL, MB_ICONERROR); + return 0; + } + else if (GetLastError() == ERROR_ALREADY_EXISTS) + { + CloseHandle(audio_router_mutex); + MessageBox( + NULL, L"Another instance of Audio Router is already running. " \ + L"Audio Router will close.", NULL, MB_ICONERROR); + return 0; + } + + HRESULT hr = CoInitializeEx(NULL, COINIT_MULTITHREADED); + if (hr != S_OK) + { + CloseHandle(audio_router_mutex); + MessageBox(NULL, L"COM could not be initialized. Audio Router will close.", NULL, MB_ICONERROR); + return 0; + } + + if (_Module.Init(NULL, hInstance) != S_OK) + { + CoUninitialize(); + CloseHandle(audio_router_mutex); + MessageBox( + NULL, L"ATL could not be initialized. Audio Router will close.", NULL, MB_ICONERROR); + return 0; + } + + ULONG_PTR gdiplusToken; + Gdiplus::GdiplusStartupInput gdiplusStartupInput; + if (Gdiplus::GdiplusStartup(&gdiplusToken, &gdiplusStartupInput, NULL) != Gdiplus::Ok) + { + _Module.Term(); + CoUninitialize(); + CloseHandle(audio_router_mutex); + MessageBox( + NULL, L"GDI+ could not be initialized. Audio Router will close.", NULL, MB_ICONERROR); + return 0; + } + + MSG msg = { 0 }; + //std::unique_ptr bootstrap; + //try + //{ + // // TODO: decide if create a dummy bootstapper in case if the initialization fails + // bootstrap.reset(new bootstrapper); + //} + //catch(std::wstring err) + //{ + // err += L"Audio Router will close."; + // MessageBox(NULL, err.c_str(), NULL, MB_ICONERROR); + // goto cleanup; + //} + + { + window win/*(bootstrap.get())*/; + RECT r = { CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT + WIN_WIDTH, CW_USEDEFAULT + WIN_HEIGHT }; + + + if (win.CreateEx(NULL, &r) == NULL) + { + MessageBox(NULL, L"Could not create window. Audio Router will close.", NULL, MB_ICONERROR); + goto cleanup; + } + + win.ShowWindow(nCmdShow); + win.UpdateWindow(); + + while (GetMessage(&msg, NULL, 0, 0) > 0) + { + + if (win.dlg_main && IsDialogMessage(*win.dlg_main, &msg)) + continue; + TranslateMessage(&msg); + DispatchMessage(&msg); + } + } cleanup: - Gdiplus::GdiplusShutdown(gdiplusToken); - _Module.Term(); - CoUninitialize(); // this thread should be the last one to call uninitialize - CloseHandle(audio_router_mutex); + Gdiplus::GdiplusShutdown(gdiplusToken); + _Module.Term(); + CoUninitialize(); // this thread should be the last one to call uninitialize + CloseHandle(audio_router_mutex); + + return (int)msg.wParam; +} - return (int)msg.wParam; -} \ No newline at end of file diff --git a/audio-router-gui/resource.h b/audio-router-gui/resource.h index 252eace1445e0bce90161d6872ba55d844b68cd9..ac8c89a14efbae6523f588404a05910b62c99c4d 100644 GIT binary patch delta 228 zcmaDMu}*q}0GFgcLkNQ>g9}3>kaTA7XYd2E9f4wwlRq+v>MDTc;(`1iplBpRJdg|k z!g#o91qK*2oZQGJD~YMYl_3JCI%F~~l;3KVw*+N!{y4a9~Fnhd-QTnzd^sKDR`)ZquD{ebQTx!w)a^_%~5W-dlg_main_b) delete this->dlg_main; delete this->form_view; @@ -27,11 +28,16 @@ int window::OnCreate(LPCREATESTRUCT lpcs) this->m_hWndClient = this->dlg_main->Create(this->m_hWnd); this->dlg_main->ShowWindow(SW_SHOW); + bIsVisible = true; + STray.hWnd = this->m_hWnd; + STray.SetTipText("Audio Router"); + STray.AddIcon(); return 0; } LRESULT window::OnSysCommand(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled) { + if(wParam == SC_MINIMIZE) { for(dialog_main::dialog_arrays_t::iterator it = this->dlg_main->dialog_arrays.begin(); @@ -44,7 +50,9 @@ LRESULT window::OnSysCommand(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHan { (*jt)->set_display_name(false, true); } + } + } else if(wParam == SC_RESTORE) { @@ -65,6 +73,24 @@ LRESULT window::OnSysCommand(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHan return 0; } +LRESULT window::OnTrayNotify(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL & bHandled) +{ + switch (LOWORD(lParam) ) + { + case WM_LBUTTONDBLCLK: + if(bIsVisible){ + this->ShowWindow(SW_HIDE); + bIsVisible = false; + } + else { + this->ShowWindow(SW_SHOW); + bIsVisible = true; + } + return 0; + break; + } +} + LRESULT window::OnFileRefreshlist(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/) { if(!this->dlg_main_b) @@ -74,7 +100,6 @@ LRESULT window::OnFileRefreshlist(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWn return 0; } - LRESULT window::OnAbout(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/) { this->MessageBoxW( @@ -86,7 +111,6 @@ LRESULT window::OnAbout(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BO return 0; } - LRESULT window::OnFileSwitchview(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/) { RECT rc; @@ -119,4 +143,4 @@ LRESULT window::OnFileSwitchview(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWnd LRESULT window::OnNcHitTest(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled) { return HTCLOSE; -} \ No newline at end of file +} diff --git a/audio-router-gui/window.h b/audio-router-gui/window.h index 70d6b77..c0effd1 100644 --- a/audio-router-gui/window.h +++ b/audio-router-gui/window.h @@ -6,6 +6,8 @@ #include "licensing.h" #include +#include "clsSysTray.h" + #define WIN_WIDTH 970//400 #define WIN_HEIGHT 670//360 #define GET(type, item) reinterpret_cast(this->GetDlgItem(item)) @@ -14,6 +16,10 @@ class window : public CFrameWindowImpl { private: bool dlg_main_b; + + clsSysTray STray; + BOOL bIsVisible; + public: dialog_main* dlg_main; formview* form_view; @@ -25,8 +31,9 @@ class window : public CFrameWindowImpl DECLARE_FRAME_WND_CLASS(L"Audio Router", IDR_MAINFRAME); - BEGIN_MSG_MAP(window) - MESSAGE_HANDLER(WM_SYSCOMMAND, OnSysCommand) + BEGIN_MSG_MAP(window) + MESSAGE_HANDLER(WM_SYSCOMMAND, OnSysCommand) + MESSAGE_HANDLER(WM_TRAYNOTIFY, OnTrayNotify); MSG_WM_CREATE(OnCreate) /*MESSAGE_HANDLER(WM_NCHITTEST, OnNcHitTest)*/ CHAIN_MSG_MAP(CFrameWindowImpl) @@ -42,4 +49,5 @@ class window : public CFrameWindowImpl LRESULT OnFileSwitchview(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/); LRESULT OnNcHitTest(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled); LRESULT OnSysCommand(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled); + LRESULT OnTrayNotify(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled); }; \ No newline at end of file diff --git a/audio-router/audio-router.vcxproj b/audio-router/audio-router.vcxproj index 9089c8e..279f9e7 100644 --- a/audio-router/audio-router.vcxproj +++ b/audio-router/audio-router.vcxproj @@ -1,5 +1,5 @@  - + Debug @@ -26,26 +26,26 @@ DynamicLibrary true - v120 + v140 Unicode DynamicLibrary true - v120 + v140 Unicode DynamicLibrary false - v120 + v140 true Unicode DynamicLibrary false - v120 + v140 true Unicode diff --git a/audio-router/patcher.h b/audio-router/patcher.h index a1c017d..aa49fc3 100644 --- a/audio-router/patcher.h +++ b/audio-router/patcher.h @@ -11,61 +11,61 @@ template class patcher { public: - typedef T func_t; - typedef size_t address_t; + typedef T func_t; + typedef size_t address_t; #pragma pack(push, 1) - struct jmp_to - { - typedef typename std::conditional< - std::is_same::value, - std::integral_constant, - std::integral_constant>::type mov_ax_t; - typename mov_ax_t::value_type mov_ax = mov_ax_t::value; - address_t addr; - WORD jmp_ax = 0xe0ff; - }; + struct jmp_to + { + typedef typename std::conditional< + std::is_same::value, + std::integral_constant, + std::integral_constant>::type mov_ax_t; + typename mov_ax_t::value_type mov_ax = mov_ax_t::value; + address_t addr; + WORD jmp_ax = 0xe0ff; + }; #pragma pack(pop) private: - const func_t patched_func; - void* original_func; - jmp_to old_bytes; - DWORD old_protect; - CRITICAL_SECTION critical_section; + const func_t patched_func; + void* original_func; + jmp_to old_bytes; + DWORD old_protect; + CRITICAL_SECTION critical_section; public: - patcher(func_t patched_func) : patched_func(patched_func), original_func(NULL) - { - InitializeCriticalSectionAndSpinCount(&this->critical_section, 0x00000400); - } + patcher(func_t patched_func) : patched_func(patched_func), original_func(NULL) + { + InitializeCriticalSectionAndSpinCount(&this->critical_section, 0x00000400); + } - ~patcher() - { - this->destroy(); - } + ~patcher() + { + this->destroy(); + } - void destroy() - { - this->revert(); - DeleteCriticalSection(&this->critical_section); - } + void destroy() + { + this->revert(); + DeleteCriticalSection(&this->critical_section); + } - int is_patched() const - { - if(IsBadReadPtr(this->original_func, sizeof(jmp_to))) - return 2; + int is_patched() const + { + if (IsBadReadPtr(this->original_func, sizeof(jmp_to))) + return 2; - return (int)(memcmp(this->original_func, &this->old_bytes, sizeof(jmp_to)) != 0); - } + return (int)(memcmp(this->original_func, &this->old_bytes, sizeof(jmp_to)) != 0); + } - const void* get_function() const {return this->original_func;} + const void* get_function() const { return this->original_func; } - int patch(void* func_address) - { - if(!func_address) - return 1; + int patch(void* func_address) + { + if (!func_address) + return 1; - //// patchable function must be 16 byte aligned to ensure atomic patching - //if((address_t)func_address & 0xf) - // return 3; + //// patchable function must be 16 byte aligned to ensure atomic patching + //if((address_t)func_address & 0xf) + // return 3; //#ifdef _WIN64 // const size_t size = 16; @@ -74,46 +74,46 @@ class patcher //#endif // assert(size >= sizeof(jmp_to)); // - if(!VirtualProtect(func_address, sizeof(jmp_to), PAGE_EXECUTE_READWRITE, &this->old_protect)) - return 2; - - this->original_func = func_address; - memcpy(&this->old_bytes, this->original_func, sizeof(jmp_to)); - this->apply(); - - return 0; - } - - void lock() {EnterCriticalSection(&this->critical_section);} - void unlock() {LeaveCriticalSection(&this->critical_section);} - - void revert() - { - if(IsBadWritePtr(this->original_func, sizeof(jmp_to))) - return; - - //if(this->patched) - { - // bad write ptr might happen if the dll that is patched - // is unloaded before this dll is unloaded - /*if(IsBadWritePtr(this->original_func, sizeof(jmp_to))) - return;*/ - memcpy(this->original_func, &this->old_bytes, sizeof(jmp_to)); - //this->patched = false; - } - } - - void apply() - { - if(IsBadWritePtr(this->original_func, sizeof(jmp_to))) - return; - - //if(!this->patched) - { - jmp_to patch; - patch.addr = (address_t)this->patched_func; - memcpy(this->original_func, &patch, sizeof(jmp_to)); - //this->patched = true; - } - } + if (!VirtualProtect(func_address, sizeof(jmp_to), PAGE_EXECUTE_READWRITE, &this->old_protect)) + return 2; + + this->original_func = func_address; + memcpy(&this->old_bytes, this->original_func, sizeof(jmp_to)); + this->apply(); + + return 0; + } + + void lock() { EnterCriticalSection(&this->critical_section); } + void unlock() { LeaveCriticalSection(&this->critical_section); } + + void revert() + { + if (IsBadWritePtr(this->original_func, sizeof(jmp_to))) + return; + + //if(this->patched) + { + // bad write ptr might happen if the dll that is patched + // is unloaded before this dll is unloaded + /*if(IsBadWritePtr(this->original_func, sizeof(jmp_to))) + return;*/ + memcpy(this->original_func, &this->old_bytes, sizeof(jmp_to)); + //this->patched = false; + } + } + + void apply() + { + if (IsBadWritePtr(this->original_func, sizeof(jmp_to))) + return; + + //if(!this->patched) + { + jmp_to patch; + patch.addr = (address_t)this->patched_func; + memcpy(this->original_func, &patch, sizeof(jmp_to)); + //this->patched = true; + } + } }; \ No newline at end of file diff --git a/bootstrapper/bootstrapper.vcxproj b/bootstrapper/bootstrapper.vcxproj index eedcf5e..bbc4ac0 100644 --- a/bootstrapper/bootstrapper.vcxproj +++ b/bootstrapper/bootstrapper.vcxproj @@ -1,5 +1,5 @@  - + Debug @@ -32,26 +32,26 @@ DynamicLibrary true - v120 + v140 Unicode DynamicLibrary true - v120 + v140 Unicode DynamicLibrary false - v120 + v140 true Unicode DynamicLibrary false - v120 + v140 true Unicode diff --git a/do/do.vcxproj b/do/do.vcxproj index 2bece19..6efb070 100644 --- a/do/do.vcxproj +++ b/do/do.vcxproj @@ -1,5 +1,5 @@  - + Debug @@ -26,26 +26,26 @@ Application true - v120 + v140 Unicode Application true - v120 + v140 Unicode Application false - v120 + v140 true Unicode Application false - v120 + v140 true Unicode From 3cbee6c56a37ed04e2ac1155a94c2631b0788846 Mon Sep 17 00:00:00 2001 From: Ronny Fretel Date: Fri, 26 Aug 2016 12:46:28 -0500 Subject: [PATCH 2/8] minimiza y cierra a systray - se cierra desde el menu File --- .gitignore | 2 + .vscode/.gitignore | 1 + audio-router-gui/audio-router-gui.rc | Bin 11918 -> 12264 bytes audio-router-gui/clsSysTray.cpp | 2 - audio-router-gui/main.cpp | 34 ++--- audio-router-gui/resource.h | Bin 3502 -> 3524 bytes audio-router-gui/window.cpp | 212 +++++++++++++++------------ audio-router-gui/window.h | 53 +++---- 8 files changed, 165 insertions(+), 139 deletions(-) create mode 100644 .vscode/.gitignore diff --git a/.gitignore b/.gitignore index 4612351..9199674 100644 --- a/.gitignore +++ b/.gitignore @@ -188,3 +188,5 @@ GeneratedArtifacts/ _Pvt_Extensions/ ModelManifest.xml /do/err.txt +/audio-router.VC.VC.opendb +/audio-router.VC.db diff --git a/.vscode/.gitignore b/.vscode/.gitignore new file mode 100644 index 0000000..fd844a8 --- /dev/null +++ b/.vscode/.gitignore @@ -0,0 +1 @@ +/.browse.VC.db diff --git a/audio-router-gui/audio-router-gui.rc b/audio-router-gui/audio-router-gui.rc index 53b4014d8ab3bab3331dadb27af16b95c1651ed9..a1a4718efbd5502e0e09283bdd01a32bf9a114c4 100644 GIT binary patch delta 212 zcmeB+eG$K*LT<8^eAeVXagNCiiXxNCWRq|Xw z@dyS_hLFjElH!}!$-iO}^ki^h2x5q52w?CB;!uWw$@U7WjGU9R6{Hn?8C)6sfMQAv zybN3noD5DtzB^F6AC%8IIZ;mB9BLI%l@3r10)k9NG8f2(S`N`Y`JjyGH@RwBOn5k3In2(pcV?Vz9uROWOxsO diff --git a/audio-router-gui/clsSysTray.cpp b/audio-router-gui/clsSysTray.cpp index 16b91f1..883311d 100644 --- a/audio-router-gui/clsSysTray.cpp +++ b/audio-router-gui/clsSysTray.cpp @@ -12,8 +12,6 @@ clsSysTray::clsSysTray() NotifyIconData.hIcon = LoadIcon(GetModuleHandle(NULL), MAKEINTRESOURCE(IDR_MAINFRAME)); NotifyIconData.szTip[0] = '\0'; NotifyIconData.hWnd = NULL; - - } diff --git a/audio-router-gui/main.cpp b/audio-router-gui/main.cpp index d8cfff8..ac9692d 100644 --- a/audio-router-gui/main.cpp +++ b/audio-router-gui/main.cpp @@ -61,20 +61,20 @@ int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLi audio_router_mutex = CreateMutex(sec.get(), FALSE, L"Local\\audio-router-mutex"); } - if (audio_router_mutex == NULL) - { - MessageBox( - NULL, L"Mutex creation failed. Audio Router will close.", NULL, MB_ICONERROR); - return 0; - } - else if (GetLastError() == ERROR_ALREADY_EXISTS) - { - CloseHandle(audio_router_mutex); - MessageBox( - NULL, L"Another instance of Audio Router is already running. " \ - L"Audio Router will close.", NULL, MB_ICONERROR); - return 0; - } + //if (audio_router_mutex == NULL) + //{ + // MessageBox( + // NULL, L"Mutex creation failed. Audio Router will close.", NULL, MB_ICONERROR); + // return 0; + //} + //else if (GetLastError() == ERROR_ALREADY_EXISTS) + //{ + // CloseHandle(audio_router_mutex); + // MessageBox( + // NULL, L"Another instance of Audio Router is already running. " \ + // L"Audio Router will close.", NULL, MB_ICONERROR); + // return 0; + //} HRESULT hr = CoInitializeEx(NULL, COINIT_MULTITHREADED); if (hr != S_OK) @@ -122,8 +122,8 @@ int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLi { window win/*(bootstrap.get())*/; RECT r = { CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT + WIN_WIDTH, CW_USEDEFAULT + WIN_HEIGHT }; - - + + if (win.CreateEx(NULL, &r) == NULL) { MessageBox(NULL, L"Could not create window. Audio Router will close.", NULL, MB_ICONERROR); @@ -135,7 +135,7 @@ int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLi while (GetMessage(&msg, NULL, 0, 0) > 0) { - + if (win.dlg_main && IsDialogMessage(*win.dlg_main, &msg)) continue; TranslateMessage(&msg); diff --git a/audio-router-gui/resource.h b/audio-router-gui/resource.h index ac8c89a14efbae6523f588404a05910b62c99c4d..eac18204c47d72e81cbac34f9951bfefac1165a2 100644 GIT binary patch delta 141 zcmZ1{eMEYL8{1?zE|tkOOj48cxTGdKu(3^^0OSiWicMa?%r Zk4&PI4R}N*&*L$f%)}xFX8+;Y1OWP4Aiy-s?A8{6b64zA5S>|2;sc^SAE^np-;!H>b8A%ww`!G$3bNIC;~en7S(P|R`i zM<&t9c5FJ68`$I~&jHgMlb^APi7GIJGx##ZGXw+m1jBSqW@Hq1*MQ1|0>xb!f`I00 u1F<24CIiAoH=qtbB%9qZZQdNst;;yMfK_7h0v?aa65L`yT4J&o?>YdPS|+9d diff --git a/audio-router-gui/window.cpp b/audio-router-gui/window.cpp index cf40ed2..c491d3b 100644 --- a/audio-router-gui/window.cpp +++ b/audio-router-gui/window.cpp @@ -4,143 +4,165 @@ telemetry* telemetry_m = NULL; window::window(/*bootstrapper* bootstrap*/) : dlg_main_b(true)/*, license(NULL)*//*, bootstrap(bootstrap)*/ { - this->dlg_main = new dialog_main(*this); - this->form_view = new formview(*this); + this->dlg_main = new dialog_main(*this); + this->form_view = new formview(*this); } window::~window() { STray.RemoveIcon(); - if(this->dlg_main_b) - delete this->dlg_main; - delete this->form_view; + if (this->dlg_main_b) + delete this->dlg_main; + delete this->form_view; - delete telemetry_m; - telemetry_m = NULL; + delete telemetry_m; + telemetry_m = NULL; } int window::OnCreate(LPCREATESTRUCT lpcs) { - telemetry_m = new telemetry; + telemetry_m = new telemetry; - /*this->license = new dialog_licensing(*this);*/ + /*this->license = new dialog_licensing(*this);*/ - this->m_hWndClient = this->dlg_main->Create(this->m_hWnd); - this->dlg_main->ShowWindow(SW_SHOW); + this->m_hWndClient = this->dlg_main->Create(this->m_hWnd); + this->dlg_main->ShowWindow(SW_SHOW); bIsVisible = true; STray.hWnd = this->m_hWnd; STray.SetTipText("Audio Router"); STray.AddIcon(); - return 0; + return 0; } LRESULT window::OnSysCommand(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled) { - if(wParam == SC_MINIMIZE) - { - for(dialog_main::dialog_arrays_t::iterator it = this->dlg_main->dialog_arrays.begin(); - it != this->dlg_main->dialog_arrays.end(); - it++) - { - for(dialog_array::dialog_controls_t::iterator jt = (*it)->dialog_controls.begin(); - jt != (*it)->dialog_controls.end(); - jt++) - { - (*jt)->set_display_name(false, true); - } - - } - - } - else if(wParam == SC_RESTORE) - { - for(dialog_main::dialog_arrays_t::iterator it = this->dlg_main->dialog_arrays.begin(); - it != this->dlg_main->dialog_arrays.end(); - it++) - { - for(dialog_array::dialog_controls_t::iterator jt = (*it)->dialog_controls.begin(); - jt != (*it)->dialog_controls.end(); - jt++) - { - (*jt)->set_display_name(false, false); - } - } - } - - bHandled = FALSE; - return 0; + if (wParam == SC_MINIMIZE) { + for (dialog_main::dialog_arrays_t::iterator it = this->dlg_main->dialog_arrays.begin(); + it != this->dlg_main->dialog_arrays.end(); + it++) + { + for (dialog_array::dialog_controls_t::iterator jt = (*it)->dialog_controls.begin(); + jt != (*it)->dialog_controls.end(); + jt++) + { + (*jt)->set_display_name(false, true); + } + + } + + this->ShowWindow(SW_HIDE); + bIsVisible = false; + return 0; + + } else if (wParam == SC_RESTORE) { + for (dialog_main::dialog_arrays_t::iterator it = this->dlg_main->dialog_arrays.begin(); + it != this->dlg_main->dialog_arrays.end(); + it++) + { + for (dialog_array::dialog_controls_t::iterator jt = (*it)->dialog_controls.begin(); + jt != (*it)->dialog_controls.end(); + jt++) + { + (*jt)->set_display_name(false, false); + } + } + } else if (wParam == SC_CLOSE) { + this->ShowWindow(SW_HIDE); + bIsVisible = false; + return 0; + } + + + bHandled = FALSE; + return 0; } LRESULT window::OnTrayNotify(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL & bHandled) { - switch (LOWORD(lParam) ) + switch (LOWORD(lParam)) { - case WM_LBUTTONDBLCLK: - if(bIsVisible){ - this->ShowWindow(SW_HIDE); - bIsVisible = false; - } - else { - this->ShowWindow(SW_SHOW); - bIsVisible = true; - } - return 0; - break; + case WM_LBUTTONDBLCLK: + if (bIsVisible) { + this->ShowWindow(SW_HIDE); + bIsVisible = false; + } else { + this->ShowWindow(SW_SHOW); + this->BringWindowToTop(); + bIsVisible = true; + } + break; + case WM_RBUTTONUP: + + /*POINT lpClickPoint; + + UINT uFlag = MF_BYPOSITION | MF_STRING; + GetCursorPos(&lpClickPoint); + + HMENU hPopMenu = CreatePopupMenu(); + InsertMenu(hPopMenu, 0xFFFFFFFF, MF_BYPOSITION | MF_STRING, ID_POPUP_EXIT, _T("Exit"); +*/ + break; } + return 0; } LRESULT window::OnFileRefreshlist(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/) { - if(!this->dlg_main_b) - { - this->form_view->refresh_list(); - } - return 0; + if (!this->dlg_main_b) + { + this->form_view->refresh_list(); + } + return 0; } LRESULT window::OnAbout(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/) { - this->MessageBoxW( - L"Audio Router version 0.10.2.\n" \ - L"\nIf you come across any bugs(especially relating to routing or duplicating), " \ - L"or just have an idea for a new feature, " \ - L"please send a PM to the developer on reddit: reddit.com/user/audiorouterdev/", - L"About", MB_ICONINFORMATION); - return 0; + this->MessageBoxW( + L"Audio Router version 0.10.2.\n" \ + L"\nIf you come across any bugs(especially relating to routing or duplicating), " \ + L"or just have an idea for a new feature, " \ + L"please send a PM to the developer on reddit: reddit.com/user/audiorouterdev/", + L"About", MB_ICONINFORMATION); + return 0; } LRESULT window::OnFileSwitchview(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/) { - RECT rc; - this->GetClientRect(&rc); - - if(this->dlg_main_b) - { - this->dlg_main->DestroyWindow(); - delete this->dlg_main; - - this->m_hWndClient = this->form_view->Create(*this); - //this->form_view->ShowWindow(SW_SHOW); - this->form_view->SetWindowPos(NULL, &rc, SWP_NOZORDER | SWP_SHOWWINDOW); - } - else - { - this->form_view->DestroyWindow(); - - this->dlg_main = new dialog_main(*this); - this->m_hWndClient = this->dlg_main->Create(*this); - //this->dlg_main->ShowWindow(SW_SHOW); - this->dlg_main->SetWindowPos(NULL, &rc, SWP_NOZORDER | SWP_SHOWWINDOW); - } - - this->dlg_main_b = !this->dlg_main_b; - - return 0; + RECT rc; + this->GetClientRect(&rc); + + if (this->dlg_main_b) + { + this->dlg_main->DestroyWindow(); + delete this->dlg_main; + + this->m_hWndClient = this->form_view->Create(*this); + //this->form_view->ShowWindow(SW_SHOW); + this->form_view->SetWindowPos(NULL, &rc, SWP_NOZORDER | SWP_SHOWWINDOW); + } else + { + this->form_view->DestroyWindow(); + + this->dlg_main = new dialog_main(*this); + this->m_hWndClient = this->dlg_main->Create(*this); + //this->dlg_main->ShowWindow(SW_SHOW); + this->dlg_main->SetWindowPos(NULL, &rc, SWP_NOZORDER | SWP_SHOWWINDOW); + } + + this->dlg_main_b = !this->dlg_main_b; + + return 0; } LRESULT window::OnNcHitTest(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled) { - return HTCLOSE; + return HTCLOSE; +} + +LRESULT window::OnFileExit(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/) +{ + PostQuitMessage(0); + return 0; } diff --git a/audio-router-gui/window.h b/audio-router-gui/window.h index c0effd1..0d066bc 100644 --- a/audio-router-gui/window.h +++ b/audio-router-gui/window.h @@ -15,39 +15,42 @@ class window : public CFrameWindowImpl { private: - bool dlg_main_b; + bool dlg_main_b; clsSysTray STray; BOOL bIsVisible; - + public: - dialog_main* dlg_main; - formview* form_view; - /*dialog_licensing* license;*/ - /*bootstrapper* bootstrap;*/ + dialog_main* dlg_main; + formview* form_view; + /*dialog_licensing* license;*/ + /*bootstrapper* bootstrap;*/ - explicit window(/*bootstrapper**/); - ~window(); + explicit window(/*bootstrapper**/); + ~window(); - DECLARE_FRAME_WND_CLASS(L"Audio Router", IDR_MAINFRAME); + DECLARE_FRAME_WND_CLASS(L"Audio Router", IDR_MAINFRAME); BEGIN_MSG_MAP(window) MESSAGE_HANDLER(WM_SYSCOMMAND, OnSysCommand) - MESSAGE_HANDLER(WM_TRAYNOTIFY, OnTrayNotify); - MSG_WM_CREATE(OnCreate) - /*MESSAGE_HANDLER(WM_NCHITTEST, OnNcHitTest)*/ - CHAIN_MSG_MAP(CFrameWindowImpl) - COMMAND_ID_HANDLER(ID_FILE_REFRESHLIST, OnFileRefreshlist) - COMMAND_ID_HANDLER(ID_ABOUT, OnAbout) - COMMAND_ID_HANDLER(ID_FILE_SWITCHVIEW, OnFileSwitchview) - /*MSG_WM_NCHITTEST(OnNcHitTest)*/ - END_MSG_MAP() - - int OnCreate(LPCREATESTRUCT); - LRESULT OnFileRefreshlist(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/); - LRESULT OnAbout(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/); - LRESULT OnFileSwitchview(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/); - LRESULT OnNcHitTest(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled); - LRESULT OnSysCommand(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled); + MESSAGE_HANDLER(WM_TRAYNOTIFY, OnTrayNotify) + MSG_WM_CREATE(OnCreate) + /*MESSAGE_HANDLER(WM_NCHITTEST, OnNcHitTest)*/ + CHAIN_MSG_MAP(CFrameWindowImpl) + COMMAND_ID_HANDLER(ID_FILE_REFRESHLIST, OnFileRefreshlist) + COMMAND_ID_HANDLER(ID_ABOUT, OnAbout) + COMMAND_ID_HANDLER(ID_FILE_SWITCHVIEW, OnFileSwitchview) + COMMAND_ID_HANDLER(ID_FILE_EXIT, OnFileExit) + /*MSG_WM_NCHITTEST(OnNcHitTest)*/ + END_MSG_MAP() + + int OnCreate(LPCREATESTRUCT); + LRESULT OnFileRefreshlist(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/); + LRESULT OnAbout(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/); + LRESULT OnFileSwitchview(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/); + LRESULT OnFileExit(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/); LRESULT OnTrayNotify(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled); + LRESULT OnNcHitTest(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled); + LRESULT OnSysCommand(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled); + }; \ No newline at end of file From df43ab3d09a493e81add399da07486a7997b5d11 Mon Sep 17 00:00:00 2001 From: wolfreak99 Date: Sat, 1 Jul 2017 05:41:57 -0400 Subject: [PATCH 3/8] Tabs to spaces --- audio-router-gui/clsSysTray.cpp | 104 ++++++------- audio-router-gui/clsSysTray.h | 26 ++-- audio-router-gui/main.cpp | 266 ++++++++++++++++---------------- audio-router-gui/window.cpp | 238 ++++++++++++++-------------- audio-router-gui/window.h | 70 ++++----- audio-router/patcher.h | 172 ++++++++++----------- 6 files changed, 438 insertions(+), 438 deletions(-) diff --git a/audio-router-gui/clsSysTray.cpp b/audio-router-gui/clsSysTray.cpp index 883311d..4ea2771 100644 --- a/audio-router-gui/clsSysTray.cpp +++ b/audio-router-gui/clsSysTray.cpp @@ -4,14 +4,14 @@ clsSysTray::clsSysTray() { - bInTray = false; - NotifyIconData.cbSize = sizeof(NotifyIconData); - NotifyIconData.uID = uID = 2; - NotifyIconData.uFlags = NIF_ICON | NIF_TIP | NIF_MESSAGE; - NotifyIconData.uCallbackMessage = WM_TRAYNOTIFY; - NotifyIconData.hIcon = LoadIcon(GetModuleHandle(NULL), MAKEINTRESOURCE(IDR_MAINFRAME)); - NotifyIconData.szTip[0] = '\0'; - NotifyIconData.hWnd = NULL; + bInTray = false; + NotifyIconData.cbSize = sizeof(NotifyIconData); + NotifyIconData.uID = uID = 2; + NotifyIconData.uFlags = NIF_ICON | NIF_TIP | NIF_MESSAGE; + NotifyIconData.uCallbackMessage = WM_TRAYNOTIFY; + NotifyIconData.hIcon = LoadIcon(GetModuleHandle(NULL), MAKEINTRESOURCE(IDR_MAINFRAME)); + NotifyIconData.szTip[0] = '\0'; + NotifyIconData.hWnd = NULL; } @@ -21,69 +21,69 @@ clsSysTray::~clsSysTray() BOOL clsSysTray::SetIcon(HICON hNewIcon) { - NotifyIconData.hIcon = hNewIcon; - if (bInTray) - { - BOOL iRetVal; - iRetVal = Shell_NotifyIcon(NIM_MODIFY, &NotifyIconData); - if (iRetVal) - { - bInTray = true; - } - return iRetVal; - } - else - return (1); + NotifyIconData.hIcon = hNewIcon; + if (bInTray) + { + BOOL iRetVal; + iRetVal = Shell_NotifyIcon(NIM_MODIFY, &NotifyIconData); + if (iRetVal) + { + bInTray = true; + } + return iRetVal; + } + else + return (1); } HICON clsSysTray::GetIcon() { - return NotifyIconData.hIcon; + return NotifyIconData.hIcon; } BOOL clsSysTray::SetTipText(char *lpstrNewTipText) { - //strncpy(NotifyIconData.szTip, lpstrNewTipText); - if (bInTray) - { - BOOL iRetVal; - iRetVal = Shell_NotifyIcon(NIM_MODIFY, &NotifyIconData); - if (iRetVal) - { - bInTray = true; - } - return iRetVal; - } - else - return (1); + //strncpy(NotifyIconData.szTip, lpstrNewTipText); + if (bInTray) + { + BOOL iRetVal; + iRetVal = Shell_NotifyIcon(NIM_MODIFY, &NotifyIconData); + if (iRetVal) + { + bInTray = true; + } + return iRetVal; + } + else + return (1); } char *clsSysTray::GetTipText() { - return "test"; // NotifyIconData.szTip; + return "test"; // NotifyIconData.szTip; } BOOL clsSysTray::AddIcon() { - BOOL iRetVal; - NotifyIconData.hWnd = hWnd; - NotifyIconData.uID = uID; - iRetVal = Shell_NotifyIcon(NIM_ADD, &NotifyIconData); - if (iRetVal) - { - bInTray = true; + BOOL iRetVal; + NotifyIconData.hWnd = hWnd; + NotifyIconData.uID = uID; + iRetVal = Shell_NotifyIcon(NIM_ADD, &NotifyIconData); + if (iRetVal) + { + bInTray = true; - } - return iRetVal; + } + return iRetVal; } BOOL clsSysTray::RemoveIcon() { - BOOL iRetVal; - iRetVal = Shell_NotifyIcon(NIM_DELETE, &NotifyIconData); - if (iRetVal) - { - bInTray = false; - } - return iRetVal; + BOOL iRetVal; + iRetVal = Shell_NotifyIcon(NIM_DELETE, &NotifyIconData); + if (iRetVal) + { + bInTray = false; + } + return iRetVal; } diff --git a/audio-router-gui/clsSysTray.h b/audio-router-gui/clsSysTray.h index 8ea7ab2..32f430e 100644 --- a/audio-router-gui/clsSysTray.h +++ b/audio-router-gui/clsSysTray.h @@ -3,25 +3,25 @@ #include -#define WM_TRAYNOTIFY 0XA44C +#define WM_TRAYNOTIFY 0XA44C #include class clsSysTray { public: - clsSysTray(); - ~clsSysTray(); - BOOL SetIcon(HICON hNewIcon); - HICON GetIcon(); - BOOL SetTipText(char *lpstrNewTipText); - char *GetTipText(); - BOOL AddIcon(); - BOOL RemoveIcon(); - HWND hWnd; - UINT uID; + clsSysTray(); + ~clsSysTray(); + BOOL SetIcon(HICON hNewIcon); + HICON GetIcon(); + BOOL SetTipText(char *lpstrNewTipText); + char *GetTipText(); + BOOL AddIcon(); + BOOL RemoveIcon(); + HWND hWnd; + UINT uID; protected: - NOTIFYICONDATA NotifyIconData; - bool bInTray; + NOTIFYICONDATA NotifyIconData; + bool bInTray; }; diff --git a/audio-router-gui/main.cpp b/audio-router-gui/main.cpp index ac9692d..2b51827 100644 --- a/audio-router-gui/main.cpp +++ b/audio-router-gui/main.cpp @@ -14,141 +14,141 @@ HANDLE audio_router_mutex; int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) { - /*srand(time(NULL));*/ - - /*global_routing_params* params = new global_routing_params; - params->version = 0; - params->local.module_name_ptr = (uint64_t)new wchar_t[wcslen(L"full\\path\\to\\module.dll") + 1]; - wcscpy((wchar_t*)params->local.module_name_ptr, L"full\\path\\to\\module.dll"); - params->local.device_id_ptr = (uint64_t)new wchar_t[wcslen(L"device id") + 1]; - wcscpy((wchar_t*)params->local.device_id_ptr, L"device id"); - - global_routing_params* params2 = new global_routing_params; - params2->version = 0; - params2->local.module_name_ptr = (uint64_t)new wchar_t[wcslen(L"full\\path\\to\\module.dll") + 1]; - wcscpy((wchar_t*)params2->local.module_name_ptr, L"full\\path\\to\\module.dll"); - params2->local.device_id_ptr = (uint64_t)new wchar_t[wcslen(L"device id") + 1]; - wcscpy((wchar_t*)params2->local.device_id_ptr, L"device id"); - params->next_global_ptr = (uint64_t)params2; - - global_routing_params* params3 = new global_routing_params; - params3->version = 0; - params3->local.module_name_ptr = (uint64_t)new wchar_t[wcslen(L"full\\path\\to\\module.dll") + 1]; - wcscpy((wchar_t*)params3->local.module_name_ptr, L"full\\path\\to\\module.dll"); - params3->local.device_id_ptr = NULL; - params2->next_global_ptr = (uint64_t)params3; - params3->next_global_ptr = NULL; - - unsigned char* serialized = serialize(params); - free(params); - global_routing_params* serialized_params = rebase(serialized); - - MessageBox(NULL, (wchar_t*)serialized_params->local.module_name_ptr, NULL, 0); - MessageBox(NULL, (wchar_t*)((global_routing_params*)serialized_params->next_global_ptr)->local.device_id_ptr, NULL, 0); - - delete [] serialized_params;*/ - - if (GetModuleHandle(L"Audio Router.exe") == NULL) - { - MessageBox( - NULL, L"Wrong application name. Audio Router will close.", NULL, MB_ICONERROR); - return 0; - } - - { - security_attributes sec(GENERIC_ALL, security_attributes::DEFAULT); - assert(sec.get() != NULL); - audio_router_mutex = CreateMutex(sec.get(), FALSE, L"Local\\audio-router-mutex"); - } - - //if (audio_router_mutex == NULL) - //{ - // MessageBox( - // NULL, L"Mutex creation failed. Audio Router will close.", NULL, MB_ICONERROR); - // return 0; - //} - //else if (GetLastError() == ERROR_ALREADY_EXISTS) - //{ - // CloseHandle(audio_router_mutex); - // MessageBox( - // NULL, L"Another instance of Audio Router is already running. " \ - // L"Audio Router will close.", NULL, MB_ICONERROR); - // return 0; - //} - - HRESULT hr = CoInitializeEx(NULL, COINIT_MULTITHREADED); - if (hr != S_OK) - { - CloseHandle(audio_router_mutex); - MessageBox(NULL, L"COM could not be initialized. Audio Router will close.", NULL, MB_ICONERROR); - return 0; - } - - if (_Module.Init(NULL, hInstance) != S_OK) - { - CoUninitialize(); - CloseHandle(audio_router_mutex); - MessageBox( - NULL, L"ATL could not be initialized. Audio Router will close.", NULL, MB_ICONERROR); - return 0; - } - - ULONG_PTR gdiplusToken; - Gdiplus::GdiplusStartupInput gdiplusStartupInput; - if (Gdiplus::GdiplusStartup(&gdiplusToken, &gdiplusStartupInput, NULL) != Gdiplus::Ok) - { - _Module.Term(); - CoUninitialize(); - CloseHandle(audio_router_mutex); - MessageBox( - NULL, L"GDI+ could not be initialized. Audio Router will close.", NULL, MB_ICONERROR); - return 0; - } - - MSG msg = { 0 }; - //std::unique_ptr bootstrap; - //try - //{ - // // TODO: decide if create a dummy bootstapper in case if the initialization fails - // bootstrap.reset(new bootstrapper); - //} - //catch(std::wstring err) - //{ - // err += L"Audio Router will close."; - // MessageBox(NULL, err.c_str(), NULL, MB_ICONERROR); - // goto cleanup; - //} - - { - window win/*(bootstrap.get())*/; - RECT r = { CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT + WIN_WIDTH, CW_USEDEFAULT + WIN_HEIGHT }; - - - if (win.CreateEx(NULL, &r) == NULL) - { - MessageBox(NULL, L"Could not create window. Audio Router will close.", NULL, MB_ICONERROR); - goto cleanup; - } - - win.ShowWindow(nCmdShow); - win.UpdateWindow(); - - while (GetMessage(&msg, NULL, 0, 0) > 0) - { - - if (win.dlg_main && IsDialogMessage(*win.dlg_main, &msg)) - continue; - TranslateMessage(&msg); - DispatchMessage(&msg); - } - } + /*srand(time(NULL));*/ + + /*global_routing_params* params = new global_routing_params; + params->version = 0; + params->local.module_name_ptr = (uint64_t)new wchar_t[wcslen(L"full\\path\\to\\module.dll") + 1]; + wcscpy((wchar_t*)params->local.module_name_ptr, L"full\\path\\to\\module.dll"); + params->local.device_id_ptr = (uint64_t)new wchar_t[wcslen(L"device id") + 1]; + wcscpy((wchar_t*)params->local.device_id_ptr, L"device id"); + + global_routing_params* params2 = new global_routing_params; + params2->version = 0; + params2->local.module_name_ptr = (uint64_t)new wchar_t[wcslen(L"full\\path\\to\\module.dll") + 1]; + wcscpy((wchar_t*)params2->local.module_name_ptr, L"full\\path\\to\\module.dll"); + params2->local.device_id_ptr = (uint64_t)new wchar_t[wcslen(L"device id") + 1]; + wcscpy((wchar_t*)params2->local.device_id_ptr, L"device id"); + params->next_global_ptr = (uint64_t)params2; + + global_routing_params* params3 = new global_routing_params; + params3->version = 0; + params3->local.module_name_ptr = (uint64_t)new wchar_t[wcslen(L"full\\path\\to\\module.dll") + 1]; + wcscpy((wchar_t*)params3->local.module_name_ptr, L"full\\path\\to\\module.dll"); + params3->local.device_id_ptr = NULL; + params2->next_global_ptr = (uint64_t)params3; + params3->next_global_ptr = NULL; + + unsigned char* serialized = serialize(params); + free(params); + global_routing_params* serialized_params = rebase(serialized); + + MessageBox(NULL, (wchar_t*)serialized_params->local.module_name_ptr, NULL, 0); + MessageBox(NULL, (wchar_t*)((global_routing_params*)serialized_params->next_global_ptr)->local.device_id_ptr, NULL, 0); + + delete [] serialized_params;*/ + + if (GetModuleHandle(L"Audio Router.exe") == NULL) + { + MessageBox( + NULL, L"Wrong application name. Audio Router will close.", NULL, MB_ICONERROR); + return 0; + } + + { + security_attributes sec(GENERIC_ALL, security_attributes::DEFAULT); + assert(sec.get() != NULL); + audio_router_mutex = CreateMutex(sec.get(), FALSE, L"Local\\audio-router-mutex"); + } + + //if (audio_router_mutex == NULL) + //{ + // MessageBox( + // NULL, L"Mutex creation failed. Audio Router will close.", NULL, MB_ICONERROR); + // return 0; + //} + //else if (GetLastError() == ERROR_ALREADY_EXISTS) + //{ + // CloseHandle(audio_router_mutex); + // MessageBox( + // NULL, L"Another instance of Audio Router is already running. " \ + // L"Audio Router will close.", NULL, MB_ICONERROR); + // return 0; + //} + + HRESULT hr = CoInitializeEx(NULL, COINIT_MULTITHREADED); + if (hr != S_OK) + { + CloseHandle(audio_router_mutex); + MessageBox(NULL, L"COM could not be initialized. Audio Router will close.", NULL, MB_ICONERROR); + return 0; + } + + if (_Module.Init(NULL, hInstance) != S_OK) + { + CoUninitialize(); + CloseHandle(audio_router_mutex); + MessageBox( + NULL, L"ATL could not be initialized. Audio Router will close.", NULL, MB_ICONERROR); + return 0; + } + + ULONG_PTR gdiplusToken; + Gdiplus::GdiplusStartupInput gdiplusStartupInput; + if (Gdiplus::GdiplusStartup(&gdiplusToken, &gdiplusStartupInput, NULL) != Gdiplus::Ok) + { + _Module.Term(); + CoUninitialize(); + CloseHandle(audio_router_mutex); + MessageBox( + NULL, L"GDI+ could not be initialized. Audio Router will close.", NULL, MB_ICONERROR); + return 0; + } + + MSG msg = { 0 }; + //std::unique_ptr bootstrap; + //try + //{ + // // TODO: decide if create a dummy bootstapper in case if the initialization fails + // bootstrap.reset(new bootstrapper); + //} + //catch(std::wstring err) + //{ + // err += L"Audio Router will close."; + // MessageBox(NULL, err.c_str(), NULL, MB_ICONERROR); + // goto cleanup; + //} + + { + window win/*(bootstrap.get())*/; + RECT r = { CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT + WIN_WIDTH, CW_USEDEFAULT + WIN_HEIGHT }; + + + if (win.CreateEx(NULL, &r) == NULL) + { + MessageBox(NULL, L"Could not create window. Audio Router will close.", NULL, MB_ICONERROR); + goto cleanup; + } + + win.ShowWindow(nCmdShow); + win.UpdateWindow(); + + while (GetMessage(&msg, NULL, 0, 0) > 0) + { + + if (win.dlg_main && IsDialogMessage(*win.dlg_main, &msg)) + continue; + TranslateMessage(&msg); + DispatchMessage(&msg); + } + } cleanup: - Gdiplus::GdiplusShutdown(gdiplusToken); - _Module.Term(); - CoUninitialize(); // this thread should be the last one to call uninitialize - CloseHandle(audio_router_mutex); + Gdiplus::GdiplusShutdown(gdiplusToken); + _Module.Term(); + CoUninitialize(); // this thread should be the last one to call uninitialize + CloseHandle(audio_router_mutex); - return (int)msg.wParam; + return (int)msg.wParam; } diff --git a/audio-router-gui/window.cpp b/audio-router-gui/window.cpp index c491d3b..a044703 100644 --- a/audio-router-gui/window.cpp +++ b/audio-router-gui/window.cpp @@ -4,165 +4,165 @@ telemetry* telemetry_m = NULL; window::window(/*bootstrapper* bootstrap*/) : dlg_main_b(true)/*, license(NULL)*//*, bootstrap(bootstrap)*/ { - this->dlg_main = new dialog_main(*this); - this->form_view = new formview(*this); + this->dlg_main = new dialog_main(*this); + this->form_view = new formview(*this); } window::~window() { - STray.RemoveIcon(); - if (this->dlg_main_b) - delete this->dlg_main; - delete this->form_view; + STray.RemoveIcon(); + if (this->dlg_main_b) + delete this->dlg_main; + delete this->form_view; - delete telemetry_m; - telemetry_m = NULL; + delete telemetry_m; + telemetry_m = NULL; } int window::OnCreate(LPCREATESTRUCT lpcs) { - telemetry_m = new telemetry; + telemetry_m = new telemetry; - /*this->license = new dialog_licensing(*this);*/ + /*this->license = new dialog_licensing(*this);*/ - this->m_hWndClient = this->dlg_main->Create(this->m_hWnd); - this->dlg_main->ShowWindow(SW_SHOW); + this->m_hWndClient = this->dlg_main->Create(this->m_hWnd); + this->dlg_main->ShowWindow(SW_SHOW); - bIsVisible = true; - STray.hWnd = this->m_hWnd; - STray.SetTipText("Audio Router"); - STray.AddIcon(); - return 0; + bIsVisible = true; + STray.hWnd = this->m_hWnd; + STray.SetTipText("Audio Router"); + STray.AddIcon(); + return 0; } LRESULT window::OnSysCommand(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled) { - if (wParam == SC_MINIMIZE) { - for (dialog_main::dialog_arrays_t::iterator it = this->dlg_main->dialog_arrays.begin(); - it != this->dlg_main->dialog_arrays.end(); - it++) - { - for (dialog_array::dialog_controls_t::iterator jt = (*it)->dialog_controls.begin(); - jt != (*it)->dialog_controls.end(); - jt++) - { - (*jt)->set_display_name(false, true); - } - - } - - this->ShowWindow(SW_HIDE); - bIsVisible = false; - return 0; - - } else if (wParam == SC_RESTORE) { - for (dialog_main::dialog_arrays_t::iterator it = this->dlg_main->dialog_arrays.begin(); - it != this->dlg_main->dialog_arrays.end(); - it++) - { - for (dialog_array::dialog_controls_t::iterator jt = (*it)->dialog_controls.begin(); - jt != (*it)->dialog_controls.end(); - jt++) - { - (*jt)->set_display_name(false, false); - } - } - } else if (wParam == SC_CLOSE) { - this->ShowWindow(SW_HIDE); - bIsVisible = false; - return 0; - } - - - bHandled = FALSE; - return 0; + if (wParam == SC_MINIMIZE) { + for (dialog_main::dialog_arrays_t::iterator it = this->dlg_main->dialog_arrays.begin(); + it != this->dlg_main->dialog_arrays.end(); + it++) + { + for (dialog_array::dialog_controls_t::iterator jt = (*it)->dialog_controls.begin(); + jt != (*it)->dialog_controls.end(); + jt++) + { + (*jt)->set_display_name(false, true); + } + + } + + this->ShowWindow(SW_HIDE); + bIsVisible = false; + return 0; + + } else if (wParam == SC_RESTORE) { + for (dialog_main::dialog_arrays_t::iterator it = this->dlg_main->dialog_arrays.begin(); + it != this->dlg_main->dialog_arrays.end(); + it++) + { + for (dialog_array::dialog_controls_t::iterator jt = (*it)->dialog_controls.begin(); + jt != (*it)->dialog_controls.end(); + jt++) + { + (*jt)->set_display_name(false, false); + } + } + } else if (wParam == SC_CLOSE) { + this->ShowWindow(SW_HIDE); + bIsVisible = false; + return 0; + } + + + bHandled = FALSE; + return 0; } LRESULT window::OnTrayNotify(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL & bHandled) { - switch (LOWORD(lParam)) - { - case WM_LBUTTONDBLCLK: - if (bIsVisible) { - this->ShowWindow(SW_HIDE); - bIsVisible = false; - } else { - this->ShowWindow(SW_SHOW); - this->BringWindowToTop(); - bIsVisible = true; - } - break; - case WM_RBUTTONUP: - - /*POINT lpClickPoint; - - UINT uFlag = MF_BYPOSITION | MF_STRING; - GetCursorPos(&lpClickPoint); - - HMENU hPopMenu = CreatePopupMenu(); - InsertMenu(hPopMenu, 0xFFFFFFFF, MF_BYPOSITION | MF_STRING, ID_POPUP_EXIT, _T("Exit"); + switch (LOWORD(lParam)) + { + case WM_LBUTTONDBLCLK: + if (bIsVisible) { + this->ShowWindow(SW_HIDE); + bIsVisible = false; + } else { + this->ShowWindow(SW_SHOW); + this->BringWindowToTop(); + bIsVisible = true; + } + break; + case WM_RBUTTONUP: + + /*POINT lpClickPoint; + + UINT uFlag = MF_BYPOSITION | MF_STRING; + GetCursorPos(&lpClickPoint); + + HMENU hPopMenu = CreatePopupMenu(); + InsertMenu(hPopMenu, 0xFFFFFFFF, MF_BYPOSITION | MF_STRING, ID_POPUP_EXIT, _T("Exit"); */ - break; - } - return 0; + break; + } + return 0; } LRESULT window::OnFileRefreshlist(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/) { - if (!this->dlg_main_b) - { - this->form_view->refresh_list(); - } - return 0; + if (!this->dlg_main_b) + { + this->form_view->refresh_list(); + } + return 0; } LRESULT window::OnAbout(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/) { - this->MessageBoxW( - L"Audio Router version 0.10.2.\n" \ - L"\nIf you come across any bugs(especially relating to routing or duplicating), " \ - L"or just have an idea for a new feature, " \ - L"please send a PM to the developer on reddit: reddit.com/user/audiorouterdev/", - L"About", MB_ICONINFORMATION); - return 0; + this->MessageBoxW( + L"Audio Router version 0.10.2.\n" \ + L"\nIf you come across any bugs(especially relating to routing or duplicating), " \ + L"or just have an idea for a new feature, " \ + L"please send a PM to the developer on reddit: reddit.com/user/audiorouterdev/", + L"About", MB_ICONINFORMATION); + return 0; } LRESULT window::OnFileSwitchview(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/) { - RECT rc; - this->GetClientRect(&rc); - - if (this->dlg_main_b) - { - this->dlg_main->DestroyWindow(); - delete this->dlg_main; - - this->m_hWndClient = this->form_view->Create(*this); - //this->form_view->ShowWindow(SW_SHOW); - this->form_view->SetWindowPos(NULL, &rc, SWP_NOZORDER | SWP_SHOWWINDOW); - } else - { - this->form_view->DestroyWindow(); - - this->dlg_main = new dialog_main(*this); - this->m_hWndClient = this->dlg_main->Create(*this); - //this->dlg_main->ShowWindow(SW_SHOW); - this->dlg_main->SetWindowPos(NULL, &rc, SWP_NOZORDER | SWP_SHOWWINDOW); - } - - this->dlg_main_b = !this->dlg_main_b; - - return 0; + RECT rc; + this->GetClientRect(&rc); + + if (this->dlg_main_b) + { + this->dlg_main->DestroyWindow(); + delete this->dlg_main; + + this->m_hWndClient = this->form_view->Create(*this); + //this->form_view->ShowWindow(SW_SHOW); + this->form_view->SetWindowPos(NULL, &rc, SWP_NOZORDER | SWP_SHOWWINDOW); + } else + { + this->form_view->DestroyWindow(); + + this->dlg_main = new dialog_main(*this); + this->m_hWndClient = this->dlg_main->Create(*this); + //this->dlg_main->ShowWindow(SW_SHOW); + this->dlg_main->SetWindowPos(NULL, &rc, SWP_NOZORDER | SWP_SHOWWINDOW); + } + + this->dlg_main_b = !this->dlg_main_b; + + return 0; } LRESULT window::OnNcHitTest(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled) { - return HTCLOSE; + return HTCLOSE; } LRESULT window::OnFileExit(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/) { - PostQuitMessage(0); - return 0; + PostQuitMessage(0); + return 0; } diff --git a/audio-router-gui/window.h b/audio-router-gui/window.h index 0d066bc..8f4f9b1 100644 --- a/audio-router-gui/window.h +++ b/audio-router-gui/window.h @@ -15,42 +15,42 @@ class window : public CFrameWindowImpl { private: - bool dlg_main_b; + bool dlg_main_b; - clsSysTray STray; - BOOL bIsVisible; + clsSysTray STray; + BOOL bIsVisible; public: - dialog_main* dlg_main; - formview* form_view; - /*dialog_licensing* license;*/ - /*bootstrapper* bootstrap;*/ - - explicit window(/*bootstrapper**/); - ~window(); - - DECLARE_FRAME_WND_CLASS(L"Audio Router", IDR_MAINFRAME); - - BEGIN_MSG_MAP(window) - MESSAGE_HANDLER(WM_SYSCOMMAND, OnSysCommand) - MESSAGE_HANDLER(WM_TRAYNOTIFY, OnTrayNotify) - MSG_WM_CREATE(OnCreate) - /*MESSAGE_HANDLER(WM_NCHITTEST, OnNcHitTest)*/ - CHAIN_MSG_MAP(CFrameWindowImpl) - COMMAND_ID_HANDLER(ID_FILE_REFRESHLIST, OnFileRefreshlist) - COMMAND_ID_HANDLER(ID_ABOUT, OnAbout) - COMMAND_ID_HANDLER(ID_FILE_SWITCHVIEW, OnFileSwitchview) - COMMAND_ID_HANDLER(ID_FILE_EXIT, OnFileExit) - /*MSG_WM_NCHITTEST(OnNcHitTest)*/ - END_MSG_MAP() - - int OnCreate(LPCREATESTRUCT); - LRESULT OnFileRefreshlist(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/); - LRESULT OnAbout(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/); - LRESULT OnFileSwitchview(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/); - LRESULT OnFileExit(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/); - LRESULT OnTrayNotify(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled); - LRESULT OnNcHitTest(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled); - LRESULT OnSysCommand(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled); - + dialog_main* dlg_main; + formview* form_view; + /*dialog_licensing* license;*/ + /*bootstrapper* bootstrap;*/ + + explicit window(/*bootstrapper**/); + ~window(); + + DECLARE_FRAME_WND_CLASS(L"Audio Router", IDR_MAINFRAME); + + BEGIN_MSG_MAP(window) + MESSAGE_HANDLER(WM_SYSCOMMAND, OnSysCommand) + MESSAGE_HANDLER(WM_TRAYNOTIFY, OnTrayNotify) + MSG_WM_CREATE(OnCreate) + /*MESSAGE_HANDLER(WM_NCHITTEST, OnNcHitTest)*/ + CHAIN_MSG_MAP(CFrameWindowImpl) + COMMAND_ID_HANDLER(ID_FILE_REFRESHLIST, OnFileRefreshlist) + COMMAND_ID_HANDLER(ID_ABOUT, OnAbout) + COMMAND_ID_HANDLER(ID_FILE_SWITCHVIEW, OnFileSwitchview) + COMMAND_ID_HANDLER(ID_FILE_EXIT, OnFileExit) + /*MSG_WM_NCHITTEST(OnNcHitTest)*/ + END_MSG_MAP() + + int OnCreate(LPCREATESTRUCT); + LRESULT OnFileRefreshlist(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/); + LRESULT OnAbout(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/); + LRESULT OnFileSwitchview(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/); + LRESULT OnFileExit(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/); + LRESULT OnTrayNotify(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled); + LRESULT OnNcHitTest(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled); + LRESULT OnSysCommand(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled); + }; \ No newline at end of file diff --git a/audio-router/patcher.h b/audio-router/patcher.h index aa49fc3..78dd123 100644 --- a/audio-router/patcher.h +++ b/audio-router/patcher.h @@ -11,61 +11,61 @@ template class patcher { public: - typedef T func_t; - typedef size_t address_t; + typedef T func_t; + typedef size_t address_t; #pragma pack(push, 1) - struct jmp_to - { - typedef typename std::conditional< - std::is_same::value, - std::integral_constant, - std::integral_constant>::type mov_ax_t; - typename mov_ax_t::value_type mov_ax = mov_ax_t::value; - address_t addr; - WORD jmp_ax = 0xe0ff; - }; + struct jmp_to + { + typedef typename std::conditional< + std::is_same::value, + std::integral_constant, + std::integral_constant>::type mov_ax_t; + typename mov_ax_t::value_type mov_ax = mov_ax_t::value; + address_t addr; + WORD jmp_ax = 0xe0ff; + }; #pragma pack(pop) private: - const func_t patched_func; - void* original_func; - jmp_to old_bytes; - DWORD old_protect; - CRITICAL_SECTION critical_section; + const func_t patched_func; + void* original_func; + jmp_to old_bytes; + DWORD old_protect; + CRITICAL_SECTION critical_section; public: - patcher(func_t patched_func) : patched_func(patched_func), original_func(NULL) - { - InitializeCriticalSectionAndSpinCount(&this->critical_section, 0x00000400); - } + patcher(func_t patched_func) : patched_func(patched_func), original_func(NULL) + { + InitializeCriticalSectionAndSpinCount(&this->critical_section, 0x00000400); + } - ~patcher() - { - this->destroy(); - } + ~patcher() + { + this->destroy(); + } - void destroy() - { - this->revert(); - DeleteCriticalSection(&this->critical_section); - } + void destroy() + { + this->revert(); + DeleteCriticalSection(&this->critical_section); + } - int is_patched() const - { - if (IsBadReadPtr(this->original_func, sizeof(jmp_to))) - return 2; + int is_patched() const + { + if (IsBadReadPtr(this->original_func, sizeof(jmp_to))) + return 2; - return (int)(memcmp(this->original_func, &this->old_bytes, sizeof(jmp_to)) != 0); - } + return (int)(memcmp(this->original_func, &this->old_bytes, sizeof(jmp_to)) != 0); + } - const void* get_function() const { return this->original_func; } + const void* get_function() const { return this->original_func; } - int patch(void* func_address) - { - if (!func_address) - return 1; + int patch(void* func_address) + { + if (!func_address) + return 1; - //// patchable function must be 16 byte aligned to ensure atomic patching - //if((address_t)func_address & 0xf) - // return 3; + //// patchable function must be 16 byte aligned to ensure atomic patching + //if((address_t)func_address & 0xf) + // return 3; //#ifdef _WIN64 // const size_t size = 16; @@ -74,46 +74,46 @@ class patcher //#endif // assert(size >= sizeof(jmp_to)); // - if (!VirtualProtect(func_address, sizeof(jmp_to), PAGE_EXECUTE_READWRITE, &this->old_protect)) - return 2; - - this->original_func = func_address; - memcpy(&this->old_bytes, this->original_func, sizeof(jmp_to)); - this->apply(); - - return 0; - } - - void lock() { EnterCriticalSection(&this->critical_section); } - void unlock() { LeaveCriticalSection(&this->critical_section); } - - void revert() - { - if (IsBadWritePtr(this->original_func, sizeof(jmp_to))) - return; - - //if(this->patched) - { - // bad write ptr might happen if the dll that is patched - // is unloaded before this dll is unloaded - /*if(IsBadWritePtr(this->original_func, sizeof(jmp_to))) - return;*/ - memcpy(this->original_func, &this->old_bytes, sizeof(jmp_to)); - //this->patched = false; - } - } - - void apply() - { - if (IsBadWritePtr(this->original_func, sizeof(jmp_to))) - return; - - //if(!this->patched) - { - jmp_to patch; - patch.addr = (address_t)this->patched_func; - memcpy(this->original_func, &patch, sizeof(jmp_to)); - //this->patched = true; - } - } + if (!VirtualProtect(func_address, sizeof(jmp_to), PAGE_EXECUTE_READWRITE, &this->old_protect)) + return 2; + + this->original_func = func_address; + memcpy(&this->old_bytes, this->original_func, sizeof(jmp_to)); + this->apply(); + + return 0; + } + + void lock() { EnterCriticalSection(&this->critical_section); } + void unlock() { LeaveCriticalSection(&this->critical_section); } + + void revert() + { + if (IsBadWritePtr(this->original_func, sizeof(jmp_to))) + return; + + //if(this->patched) + { + // bad write ptr might happen if the dll that is patched + // is unloaded before this dll is unloaded + /*if(IsBadWritePtr(this->original_func, sizeof(jmp_to))) + return;*/ + memcpy(this->original_func, &this->old_bytes, sizeof(jmp_to)); + //this->patched = false; + } + } + + void apply() + { + if (IsBadWritePtr(this->original_func, sizeof(jmp_to))) + return; + + //if(!this->patched) + { + jmp_to patch; + patch.addr = (address_t)this->patched_func; + memcpy(this->original_func, &patch, sizeof(jmp_to)); + //this->patched = true; + } + } }; \ No newline at end of file From 63746f4c9cbac2ff5c29e341d310bad673edafdb Mon Sep 17 00:00:00 2001 From: wolfreak99 Date: Fri, 30 Jun 2017 22:35:26 -0400 Subject: [PATCH 4/8] Update .gitignore --- .gitignore | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/.gitignore b/.gitignore index 9199674..a756370 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,6 @@ ## Ignore Visual Studio temporary files, build results, and ## files generated by popular Visual Studio add-ons. +/.vs/ # User-specific files *.suo @@ -187,6 +188,19 @@ FakesAssemblies/ GeneratedArtifacts/ _Pvt_Extensions/ ModelManifest.xml + +# Visual Studio cache/options directory +.vs/ + +# Visual C++ cache files +ipch/ +*.aps +*.ncb +*.opendb +*.opensdf +*.sdf +*.cachefile +*.VC.db +*.VC.VC.opendb + /do/err.txt -/audio-router.VC.VC.opendb -/audio-router.VC.db From f246cc69929bdd909deb2758f47d36ef3b7ac93a Mon Sep 17 00:00:00 2001 From: wolfreak99 Date: Wed, 14 Jun 2017 13:23:49 -0400 Subject: [PATCH 5/8] Upgrade solution --- audio-router-gui/audio-router-gui.vcxproj | 10 +++++----- audio-router/audio-router.vcxproj | 10 +++++----- bootstrapper/bootstrapper.vcxproj | 10 +++++----- do/do.vcxproj | 10 +++++----- 4 files changed, 20 insertions(+), 20 deletions(-) diff --git a/audio-router-gui/audio-router-gui.vcxproj b/audio-router-gui/audio-router-gui.vcxproj index b738164..a8ead2c 100644 --- a/audio-router-gui/audio-router-gui.vcxproj +++ b/audio-router-gui/audio-router-gui.vcxproj @@ -1,5 +1,5 @@  - + Debug @@ -26,26 +26,26 @@ Application true - v140 + v141 Unicode Application true - v140 + v141 Unicode Application false - v140 + v141 true Unicode Application false - v140 + v141 true Unicode diff --git a/audio-router/audio-router.vcxproj b/audio-router/audio-router.vcxproj index 279f9e7..aabfa08 100644 --- a/audio-router/audio-router.vcxproj +++ b/audio-router/audio-router.vcxproj @@ -1,5 +1,5 @@  - + Debug @@ -26,26 +26,26 @@ DynamicLibrary true - v140 + v141 Unicode DynamicLibrary true - v140 + v141 Unicode DynamicLibrary false - v140 + v141 true Unicode DynamicLibrary false - v140 + v141 true Unicode diff --git a/bootstrapper/bootstrapper.vcxproj b/bootstrapper/bootstrapper.vcxproj index bbc4ac0..5ab541d 100644 --- a/bootstrapper/bootstrapper.vcxproj +++ b/bootstrapper/bootstrapper.vcxproj @@ -1,5 +1,5 @@  - + Debug @@ -32,26 +32,26 @@ DynamicLibrary true - v140 + v141 Unicode DynamicLibrary true - v140 + v141 Unicode DynamicLibrary false - v140 + v141 true Unicode DynamicLibrary false - v140 + v141 true Unicode diff --git a/do/do.vcxproj b/do/do.vcxproj index 6efb070..dba3be8 100644 --- a/do/do.vcxproj +++ b/do/do.vcxproj @@ -1,5 +1,5 @@  - + Debug @@ -26,26 +26,26 @@ Application true - v140 + v141 Unicode Application true - v140 + v141 Unicode Application false - v140 + v141 true Unicode Application false - v140 + v141 true Unicode From bcd442429f7bf7f30072f00d25556eeaf67ac0b1 Mon Sep 17 00:00:00 2001 From: wolfreak99 Date: Thu, 15 Jun 2017 05:38:11 -0400 Subject: [PATCH 6/8] Compiling fixes --- audio-router-gui/app_list.cpp | 4 ++-- bootstrapper/main.cpp | 2 +- third-party/WTL90_4140_Final/Include/atlframe.h | 2 +- third-party/WTL90_4140_Final/Include/atlgdi.h | 12 ++++++------ 4 files changed, 10 insertions(+), 10 deletions(-) diff --git a/audio-router-gui/app_list.cpp b/audio-router-gui/app_list.cpp index fe03bd1..2245fe8 100644 --- a/audio-router-gui/app_list.cpp +++ b/audio-router-gui/app_list.cpp @@ -26,10 +26,10 @@ bool app_list::populate_list() { bool app_list::populate_list(const filters_t & filters) { this->apps.clear(); - if ( ! this-> populate_list(true, filters)) + if (!this->populate_list(true, filters)) return false; #ifdef _WIN64 - return this - > populate_list(false, filters); + return this->populate_list(false, filters); #else return true; #endif diff --git a/bootstrapper/main.cpp b/bootstrapper/main.cpp index 98fb316..4bf89c6 100644 --- a/bootstrapper/main.cpp +++ b/bootstrapper/main.cpp @@ -241,7 +241,7 @@ NTSTATUS NTAPI ntcreateuserprocess_patch( DWORD mode = PIPE_READMODE_MESSAGE; SetNamedPipeHandleState(hpipe, &mode, NULL, NULL); // flag 2 indicates that bootstrapping is only injected - DWORD pid_tid_both[3] = {pid, tid, in_list ? 1 : 2}; + DWORD pid_tid_both[3] = {pid, tid, (DWORD)(in_list ? 1 : 2) }; DWORD exitcode, bytes_read; BOOL success = TransactNamedPipe( hpipe, pid_tid_both, sizeof(pid_tid_both), &exitcode, sizeof(exitcode), diff --git a/third-party/WTL90_4140_Final/Include/atlframe.h b/third-party/WTL90_4140_Final/Include/atlframe.h index 7d7acd5..18df933 100644 --- a/third-party/WTL90_4140_Final/Include/atlframe.h +++ b/third-party/WTL90_4140_Final/Include/atlframe.h @@ -987,7 +987,7 @@ class ATL_NO_VTABLE CFrameWindowImplBase : public ATL::CWindowImplBaseT< TBase, bool PrepareChevronMenu(_ChevronMenuInfo& cmi) { // get rebar and toolbar - REBARBANDINFO rbbi = { RunTimeHelper::SizeOf_REBARBANDINFO() }; + REBARBANDINFO rbbi = { (UINT)RunTimeHelper::SizeOf_REBARBANDINFO() }; rbbi.fMask = RBBIM_CHILD; BOOL bRet = (BOOL)::SendMessage(cmi.lpnm->hdr.hwndFrom, RB_GETBANDINFO, cmi.lpnm->uBand, (LPARAM)&rbbi); ATLASSERT(bRet); diff --git a/third-party/WTL90_4140_Final/Include/atlgdi.h b/third-party/WTL90_4140_Final/Include/atlgdi.h index 03aa076..eb7c9ed 100644 --- a/third-party/WTL90_4140_Final/Include/atlgdi.h +++ b/third-party/WTL90_4140_Final/Include/atlgdi.h @@ -467,28 +467,28 @@ class CLogFont : public LOGFONT #ifndef _WIN32_WCE void SetCaptionFont() { - NONCLIENTMETRICS ncm = { RunTimeHelper::SizeOf_NONCLIENTMETRICS() }; + NONCLIENTMETRICS ncm = { (UINT)RunTimeHelper::SizeOf_NONCLIENTMETRICS() }; ATLVERIFY(::SystemParametersInfo(SPI_GETNONCLIENTMETRICS, sizeof(ncm), &ncm, 0)); Copy(&ncm.lfCaptionFont); } void SetMenuFont() { - NONCLIENTMETRICS ncm = { RunTimeHelper::SizeOf_NONCLIENTMETRICS() }; + NONCLIENTMETRICS ncm = { (UINT)RunTimeHelper::SizeOf_NONCLIENTMETRICS() }; ATLVERIFY(::SystemParametersInfo(SPI_GETNONCLIENTMETRICS, sizeof(ncm), &ncm, 0)); Copy(&ncm.lfMenuFont); } void SetStatusFont() { - NONCLIENTMETRICS ncm = { RunTimeHelper::SizeOf_NONCLIENTMETRICS() }; + NONCLIENTMETRICS ncm = { (UINT)RunTimeHelper::SizeOf_NONCLIENTMETRICS() }; ATLVERIFY(::SystemParametersInfo(SPI_GETNONCLIENTMETRICS, sizeof(ncm), &ncm, 0)); Copy(&ncm.lfStatusFont); } void SetMessageBoxFont() { - NONCLIENTMETRICS ncm = { RunTimeHelper::SizeOf_NONCLIENTMETRICS() }; + NONCLIENTMETRICS ncm = { (UINT)RunTimeHelper::SizeOf_NONCLIENTMETRICS() }; ATLVERIFY(::SystemParametersInfo(SPI_GETNONCLIENTMETRICS, sizeof(ncm), &ncm, 0)); Copy(&ncm.lfMessageFont); } @@ -3680,8 +3680,8 @@ struct DIBINFO16 // a BITMAPINFO with 2 additional color bitfields DIBINFO16(SIZE size) { BITMAPINFOHEADER bmih = { sizeof(BITMAPINFOHEADER), size.cx, size.cy, - 1, 16, BI_BITFIELDS, 2 * size.cx * size.cy , 0, 0, 3 }; - DWORD dw[3] = DIBINFO16_BITFIELDS ; + 1, 16, (DWORD)BI_BITFIELDS, (DWORD)2 * size.cx * size.cy, 0, 0, 3 }; + DWORD dw[3] = DIBINFO16_BITFIELDS; bmiHeader = bmih; SecureHelper::memcpy_x(bmiColors, sizeof(bmiColors), dw, 3 * sizeof(DWORD)); From e795d6ab6fe2d9821c9bc238e0ce23467e3dce4f Mon Sep 17 00:00:00 2001 From: wolfreak99 Date: Sat, 1 Jul 2017 03:12:19 -0400 Subject: [PATCH 7/8] Implement Tray Icon right click menu --- audio-router-gui/audio-router-gui.rc | Bin 12264 -> 12432 bytes audio-router-gui/resource.h | Bin 3524 -> 3610 bytes audio-router-gui/window.cpp | 62 +++++++++++++++++++++++---- audio-router-gui/window.h | 6 ++- 4 files changed, 58 insertions(+), 10 deletions(-) diff --git a/audio-router-gui/audio-router-gui.rc b/audio-router-gui/audio-router-gui.rc index a1a4718efbd5502e0e09283bdd01a32bf9a114c4..81c35b9f289c84b2c31b3d0f50c3bffc76f54a74 100644 GIT binary patch delta 148 zcmaD6KOu30j52!&LlA=_L*(S$3aXR6lm+;qdiJxgYT3AcI(LlA=_LnMPQgDZm{LnuQ$LokB}gFiz!ko0750g7^h;N<%}@{=9d g_%spfTp1#ODncOg3<^+a!e9V|h787=qq#Gg0Jwq>hyVZp delta 44 rcmbOwb3}TB3HRiE>^#!03=s^T3?U4haA?9{0EC7NMw>TsXEFf**1QNj diff --git a/audio-router-gui/window.cpp b/audio-router-gui/window.cpp index a044703..05610c9 100644 --- a/audio-router-gui/window.cpp +++ b/audio-router-gui/window.cpp @@ -1,6 +1,7 @@ #include "window.h" telemetry* telemetry_m = NULL; +HMENU trayIconMenu; window::window(/*bootstrapper* bootstrap*/) : dlg_main_b(true)/*, license(NULL)*//*, bootstrap(bootstrap)*/ { @@ -81,28 +82,41 @@ LRESULT window::OnSysCommand(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHan LRESULT window::OnTrayNotify(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL & bHandled) { + if (trayIconMenu != NULL) { + DestroyMenu(trayIconMenu); + trayIconMenu = NULL; + } + switch (LOWORD(lParam)) { - case WM_LBUTTONDBLCLK: + case WM_LBUTTONUP: if (bIsVisible) { this->ShowWindow(SW_HIDE); bIsVisible = false; - } else { + } + else { this->ShowWindow(SW_SHOW); this->BringWindowToTop(); bIsVisible = true; } break; case WM_RBUTTONUP: - - /*POINT lpClickPoint; + trayIconMenu = CreatePopupMenu(); + + UINT menuFlags = MF_BYPOSITION | MF_STRING; + InsertMenuW(trayIconMenu, -1, menuFlags, ID_TRAYMENU_SHOWHIDE, _T("Show/hide")); + InsertMenuW(trayIconMenu, -1, menuFlags, ID_FILE_EXIT, _T("Exit")); - UINT uFlag = MF_BYPOSITION | MF_STRING; + POINT lpClickPoint; GetCursorPos(&lpClickPoint); - - HMENU hPopMenu = CreatePopupMenu(); - InsertMenu(hPopMenu, 0xFFFFFFFF, MF_BYPOSITION | MF_STRING, ID_POPUP_EXIT, _T("Exit"); -*/ + + int nReserved = 0; + + TrackPopupMenu(trayIconMenu, + TPM_RIGHTALIGN | TPM_BOTTOMALIGN | TPM_LEFTBUTTON, + lpClickPoint.x, lpClickPoint.y, + nReserved, this->m_hWnd, NULL + ); break; } return 0; @@ -166,3 +180,33 @@ LRESULT window::OnFileExit(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, PostQuitMessage(0); return 0; } + +LRESULT window::OnTrayMenuExit(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/) +{ + if (trayIconMenu != NULL) { + DestroyMenu(trayIconMenu); + trayIconMenu = NULL; + } + + PostQuitMessage(0); + return 0; +} + +LRESULT window::OnTrayMenuShowHide(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/) +{ + if (trayIconMenu != NULL) { + DestroyMenu(trayIconMenu); + trayIconMenu = NULL; + } + + if (bIsVisible) { + this->ShowWindow(SW_HIDE); + bIsVisible = false; + } + else { + this->ShowWindow(SW_SHOW); + this->BringWindowToTop(); + bIsVisible = true; + } + return 0; +} diff --git a/audio-router-gui/window.h b/audio-router-gui/window.h index 8f4f9b1..4b88719 100644 --- a/audio-router-gui/window.h +++ b/audio-router-gui/window.h @@ -41,6 +41,8 @@ class window : public CFrameWindowImpl COMMAND_ID_HANDLER(ID_ABOUT, OnAbout) COMMAND_ID_HANDLER(ID_FILE_SWITCHVIEW, OnFileSwitchview) COMMAND_ID_HANDLER(ID_FILE_EXIT, OnFileExit) + COMMAND_ID_HANDLER(ID_TRAYMENU_SHOWHIDE, OnTrayMenuShowHide) + COMMAND_ID_HANDLER(ID_TRAYMENU_EXIT, OnTrayMenuExit) /*MSG_WM_NCHITTEST(OnNcHitTest)*/ END_MSG_MAP() @@ -49,8 +51,10 @@ class window : public CFrameWindowImpl LRESULT OnAbout(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/); LRESULT OnFileSwitchview(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/); LRESULT OnFileExit(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/); + LRESULT OnTrayMenuShowHide(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/); + LRESULT OnTrayMenuExit(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/); LRESULT OnTrayNotify(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled); LRESULT OnNcHitTest(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled); LRESULT OnSysCommand(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled); - + }; \ No newline at end of file From 5f642c3fe7f7a5a5e275c38b987ab01f9fdae442 Mon Sep 17 00:00:00 2001 From: wolfreak99 Date: Thu, 6 Jul 2017 02:37:03 -0400 Subject: [PATCH 8/8] app_list.cpp > extract divisons from iteration loops --- audio-router-gui/app_list.cpp | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/audio-router-gui/app_list.cpp b/audio-router-gui/app_list.cpp index 2245fe8..2322e3f 100644 --- a/audio-router-gui/app_list.cpp +++ b/audio-router-gui/app_list.cpp @@ -7,7 +7,8 @@ bool app_list::populate_list(bool x86, const filters_t & filters) { if ( ! EnumProcesses(processes, sizeof(processes), & needed)) return false; - for (DWORD i = 0; i < (needed / sizeof(DWORD)); i++) { + size_t count = needed / sizeof(DWORD); + for (DWORD i = 0; i < count; i++) { app_info info; info.id = processes[i]; if (this->get_app_info(info, filters, x86, true)) @@ -58,8 +59,9 @@ bool app_list::get_app_info(app_info & info, const filters_t & filters, bool x86 if (query_name && EnumProcessModulesEx( hprocess, hmodules, sizeof(hmodules), & needed, x86?LIST_MODULES_32BIT:LIST_MODULES_64BIT)) { WCHAR name[MAX_PATH] = {0}; - std::wstring exename; - if (GetModuleBaseName(hprocess, hmodules[0], name, sizeof(name)/sizeof(WCHAR))) { + std::wstring exename; + auto name_size = sizeof(name) / sizeof(WCHAR); + if (GetModuleBaseName(hprocess, hmodules[0], name, name_size)) { _wcslwr(name); exename = name; @@ -70,9 +72,10 @@ bool app_list::get_app_info(app_info & info, const filters_t & filters, bool x86 return true; } - for (DWORD j = 0; j < (needed / sizeof(HMODULE)); j++) { + size_t needed_count = needed / sizeof(HMODULE); + for (DWORD j = 0; j < needed_count; j++) { WCHAR name[MAX_PATH] = {0}; - if (GetModuleBaseName(hprocess, hmodules[j], name, sizeof(name)/sizeof(WCHAR))) { + if (GetModuleBaseName(hprocess, hmodules[j], name, name_size)) { _wcslwr(name); for (filters_t::const_iterator it = filters.begin(); it != filters.end(); it++) if ( * it == name) {