Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Systray v0.10.3 #16

Open
wants to merge 2 commits into
base: open
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -188,3 +188,5 @@ GeneratedArtifacts/
_Pvt_Extensions/
ModelManifest.xml
/do/err.txt
/audio-router.VC.VC.opendb
/audio-router.VC.db
1 change: 1 addition & 0 deletions .vscode/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/.browse.VC.db
140 changes: 63 additions & 77 deletions audio-router-gui/app_list.cpp
Original file line number Diff line number Diff line change
@@ -1,114 +1,100 @@
#include "app_list.h"
#include <Psapi.h>
#include <algorithm>
#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
}
Binary file modified audio-router-gui/audio-router-gui.rc
Binary file not shown.
12 changes: 7 additions & 5 deletions audio-router-gui/audio-router-gui.vcxproj
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="12.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Project DefaultTargets="Build" ToolsVersion="14.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup Label="ProjectConfigurations">
<ProjectConfiguration Include="Debug|Win32">
<Configuration>Debug</Configuration>
Expand All @@ -26,26 +26,26 @@
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<PlatformToolset>v120</PlatformToolset>
<PlatformToolset>v140</PlatformToolset>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<PlatformToolset>v120</PlatformToolset>
<PlatformToolset>v140</PlatformToolset>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>v120</PlatformToolset>
<PlatformToolset>v140</PlatformToolset>
<WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>v120</PlatformToolset>
<PlatformToolset>v140</PlatformToolset>
<WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
Expand Down Expand Up @@ -159,6 +159,7 @@
<ClInclude Include="app_inject.h" />
<ClInclude Include="app_list.h" />
<ClInclude Include="bootstrapper.h" />
<ClInclude Include="clsSysTray.h" />
<ClInclude Include="DialogMessageHook.h" />
<ClInclude Include="dialog_array.h" />
<ClInclude Include="dialog_control.h" />
Expand All @@ -182,6 +183,7 @@
<ClCompile Include="app_inject.cpp" />
<ClCompile Include="app_list.cpp" />
<ClCompile Include="bootstrapper.cpp" />
<ClCompile Include="clsSysTray.cpp" />
<ClCompile Include="DialogMessageHook.cpp" />
<ClCompile Include="dialog_array.cpp" />
<ClCompile Include="dialog_control.cpp" />
Expand Down
6 changes: 6 additions & 0 deletions audio-router-gui/audio-router-gui.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,9 @@
<ClInclude Include="licensing.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="clsSysTray.h">
<Filter>Header Files</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<ResourceCompile Include="audio-router-gui.rc">
Expand Down Expand Up @@ -127,6 +130,9 @@
<ClCompile Include="licensing.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="clsSysTray.cpp">
<Filter>Source Files</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<Image Include="icon1.ico">
Expand Down
89 changes: 89 additions & 0 deletions audio-router-gui/clsSysTray.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
#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;
}
27 changes: 27 additions & 0 deletions audio-router-gui/clsSysTray.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#pragma once
#pragma warning(disable: 4996)

#include <windows.h>

#define WM_TRAYNOTIFY 0XA44C
#include <shellapi.h>

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;
};


4 changes: 1 addition & 3 deletions audio-router-gui/dialog_main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
Loading