From 1e0d9fee413c415ceccc3ad84865e771f4c0e0a9 Mon Sep 17 00:00:00 2001 From: wolfreak99 Date: Sat, 1 Jul 2017 05:41:57 -0400 Subject: [PATCH] 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 | 222 +++++++++++++------------- audio-router-gui/window.h | 66 ++++---- audio-router/patcher.h | 172 ++++++++++----------- 6 files changed, 428 insertions(+), 428 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 e3320a7..05610c9 100644 --- a/audio-router-gui/window.cpp +++ b/audio-router-gui/window.cpp @@ -5,79 +5,79 @@ HMENU trayIconMenu; 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) @@ -87,20 +87,20 @@ LRESULT window::OnTrayNotify(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL & bHa trayIconMenu = NULL; } - switch (LOWORD(lParam)) - { - case WM_LBUTTONUP: - if (bIsVisible) { - this->ShowWindow(SW_HIDE); - bIsVisible = false; - } + switch (LOWORD(lParam)) + { + case WM_LBUTTONUP: + if (bIsVisible) { + this->ShowWindow(SW_HIDE); + bIsVisible = false; + } else { - this->ShowWindow(SW_SHOW); - this->BringWindowToTop(); - bIsVisible = true; - } - break; - case WM_RBUTTONUP: + this->ShowWindow(SW_SHOW); + this->BringWindowToTop(); + bIsVisible = true; + } + break; + case WM_RBUTTONUP: trayIconMenu = CreatePopupMenu(); UINT menuFlags = MF_BYPOSITION | MF_STRING; @@ -117,68 +117,68 @@ LRESULT window::OnTrayNotify(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL & bHa lpClickPoint.x, lpClickPoint.y, nReserved, this->m_hWnd, NULL ); - 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; } LRESULT window::OnTrayMenuExit(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/) diff --git a/audio-router-gui/window.h b/audio-router-gui/window.h index 61984d2..53b4c99 100644 --- a/audio-router-gui/window.h +++ b/audio-router-gui/window.h @@ -15,46 +15,46 @@ 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) + 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) COMMAND_ID_HANDLER(ID_TRAYMENU_SHOWHIDE, OnTrayMenuShowHide) COMMAND_ID_HANDLER(ID_TRAYMENU_EXIT, OnTrayMenuExit) - /*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*/); + /*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 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); + 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