Skip to content

Commit

Permalink
+ Fixed A apis to W Apis
Browse files Browse the repository at this point in the history
+ added force focus option
  • Loading branch information
McYoloSwagHam committed Mar 5, 2021
1 parent 8710e72 commit e50cf7f
Show file tree
Hide file tree
Showing 7 changed files with 243 additions and 215 deletions.
1 change: 1 addition & 0 deletions Build/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@
"true_fullscreen" : "n",
"remove_titlebars_experimental" : "n",
"enable_logs" : "n",
"force_focus" : "y",

"gaps_enabled" : "y",
"outer_gaps_vertical" : 10,
Expand Down
8 changes: 4 additions & 4 deletions ForceResize/ForceResize/ForceResize.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@
<WarningLevel>Level3</WarningLevel>
<Optimization>Disabled</Optimization>
<SDLCheck>true</SDLCheck>
<PreprocessorDefinitions>WIN32;_DEBUG;FORCERESIZE_EXPORTS;_WINDOWS;_USRDLL;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<PreprocessorDefinitions>WIN32;_DEBUG;FORCERESIZE_EXPORTS;_WINDOWS;_USRDLL;%(PreprocessorDefinitions);_CRT_SECURE_NO_WARNINGS</PreprocessorDefinitions>
<ConformanceMode>true</ConformanceMode>
<PrecompiledHeaderFile>pch.h</PrecompiledHeaderFile>
</ClCompile>
Expand All @@ -113,7 +113,7 @@
<WarningLevel>Level3</WarningLevel>
<Optimization>Disabled</Optimization>
<SDLCheck>true</SDLCheck>
<PreprocessorDefinitions>_DEBUG;FORCERESIZE_EXPORTS;_WINDOWS;_USRDLL;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<PreprocessorDefinitions>_DEBUG;FORCERESIZE_EXPORTS;_WINDOWS;_USRDLL;%(PreprocessorDefinitions);_CRT_SECURE_NO_WARNINGS;_CRT_SECURE_NO_WARNINGS</PreprocessorDefinitions>
<ConformanceMode>true</ConformanceMode>
<PrecompiledHeaderFile>pch.h</PrecompiledHeaderFile>
</ClCompile>
Expand All @@ -132,7 +132,7 @@
<FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions>
<SDLCheck>true</SDLCheck>
<PreprocessorDefinitions>WIN32;NDEBUG;FORCERESIZE_EXPORTS;_WINDOWS;_USRDLL;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<PreprocessorDefinitions>WIN32;NDEBUG;FORCERESIZE_EXPORTS;_WINDOWS;_USRDLL;%(PreprocessorDefinitions);_CRT_SECURE_NO_WARNINGS</PreprocessorDefinitions>
<ConformanceMode>true</ConformanceMode>
<PrecompiledHeaderFile>pch.h</PrecompiledHeaderFile>
</ClCompile>
Expand All @@ -153,7 +153,7 @@
<FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions>
<SDLCheck>true</SDLCheck>
<PreprocessorDefinitions>NDEBUG;FORCERESIZE_EXPORTS;_WINDOWS;_USRDLL;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<PreprocessorDefinitions>NDEBUG;FORCERESIZE_EXPORTS;_WINDOWS;_USRDLL;%(PreprocessorDefinitions);_CRT_SECURE_NO_WARNINGS;_CRT_SECURE_NO_WARNINGS</PreprocessorDefinitions>
<ConformanceMode>true</ConformanceMode>
<PrecompiledHeaderFile>pch.h</PrecompiledHeaderFile>
</ClCompile>
Expand Down
10 changes: 5 additions & 5 deletions ForceResize/ForceResize/dllmain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ extern "C" __declspec(dllexport) LRESULT HookProc(int nCode, WPARAM WParam, LPAR
if (pMessage->message == CustomMessage)
{

CHAR FormatString[1024] = { 0 };
WCHAR FormatString[1024] = { 0 };

HWND WindowToAdd = (HWND)pMessage->lParam;

Expand All @@ -98,8 +98,8 @@ extern "C" __declspec(dllexport) LRESULT HookProc(int nCode, WPARAM WParam, LPAR
TargetWindowList.push_back(WindowToAdd);
if (!SetWindowSubclass(WindowToAdd, SubclassHookProc, TargetWindowList.size(), NULL))
{
snprintf(FormatString, 1024, "SetWindowSubclass Failed %u : LPARAM : %p : WPARAM %p", GetLastError(), LParam, WParam);
MessageBoxA(GetForegroundWindow(), FormatString, NULL, MB_OK);
_snwprintf(FormatString, 1024, L"SetWindowSubclass Failed %u : LPARAM : %p : WPARAM %p", GetLastError(), LParam, WParam);
MessageBoxW(GetForegroundWindow(), FormatString, NULL, MB_OK);
}
}

Expand Down Expand Up @@ -132,11 +132,11 @@ BOOL APIENTRY DllMain( HMODULE hModule,
switch (ul_reason_for_call)
{
case DLL_PROCESS_ATTACH:
MainWin3WMWindow = FindWindowA("Win3wmWindow", "Win3wm");
MainWin3WMWindow = FindWindowW(L"Win3wmWindow", L"Win3wm");

if (!MainWin3WMWindow)
{
MessageBoxA(GetForegroundWindow(), "Couldn't Find Main Window ForceResize", NULL, MB_OK);
MessageBoxW(GetForegroundWindow(), L"Couldn't Find Main Window ForceResize", NULL, MB_OK);
TerminateProcess(GetCurrentProcess(), 8069);
}

Expand Down
54 changes: 27 additions & 27 deletions guitest/ComInterface.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ UINT16 GetWinBuildNumber()
UINT16 buildNumbers[] = { 10130, 10240, 14393, 9200, 18362, 18363, 19041, 19042, 20241, 21313, 21318, 21322};
OSVERSIONINFOEXW osvi = { sizeof(osvi), 0, 0, 0, 0,{ 0 }, 0, 0 };
NTSTATUS(WINAPI *RtlVerifyVersionInfo)(LPOSVERSIONINFOEXW, ULONG, ULONGLONG);
*(FARPROC*)&RtlVerifyVersionInfo = GetProcAddress(GetModuleHandleA("ntdll.dll"), "RtlVerifyVersionInfo");
*(FARPROC*)&RtlVerifyVersionInfo = GetProcAddress(GetModuleHandleW(L"ntdll.dll"), "RtlVerifyVersionInfo");
ULONGLONG mask = ::VerSetConditionMask(0, VER_BUILDNUMBER, VER_EQUAL);

for (size_t i = 0; i < sizeof(buildNumbers) / sizeof(buildNumbers[0]); i++)
Expand All @@ -37,27 +37,27 @@ UINT16 GetWinBuildNumber()
return 0;
}

const char* InitCom()
const wchar_t* InitCom()
{
HRESULT hr = CoInitialize(NULL);

if (FAILED(hr))
return "CoInitialize";
return L"CoInitialize";

hr = CoCreateInstance(CLSID_ImmersiveShell, NULL, CLSCTX_LOCAL_SERVER, __uuidof(IServiceProvider), (PVOID*)&ServiceProvider);

if (FAILED(hr))
return "CoCreateInstance";
return L"CoCreateInstance";

ServiceProvider->QueryService(__uuidof(IVirtualDesktopManager), &VDesktopManager);
ServiceProvider->QueryService(__uuidof(IApplicationViewCollection), &ViewCollection);


if (!VDesktopManager)
return "VDesktopManager";
return L"VDesktopManager";

if (!ViewCollection)
return "ViewCollection";
return L"ViewCollection";

UINT16 buildNumber = GetWinBuildNumber();

Expand Down Expand Up @@ -104,12 +104,12 @@ const char* InitCom()
}

if (FAILED(hr))
return "QueryService VDM";
return L"QueryService VDM";

if (!VDesktopWrapper.VDesktopManagerInternal &&
!VDesktopWrapper.VDesktopManagerInternal_20241 &&
!VDesktopWrapper.VDesktopManagerInternal_21313)
return "PinnedApps";
return L"PinnedApps";

VDesktopWrapper.CurrentIID = CurrentIID;
VDesktopWrapper.VersionNumber = buildNumber;
Expand Down Expand Up @@ -160,7 +160,7 @@ HRESULT EnumVirtualDesktops(HMONITOR Handle, VirtualDesktopWrapper* pDesktopMana
return hr;
}

const char* RemoveOtherVDesktops()
const wchar_t* RemoveOtherVDesktops()
{

IObjectArray* DesktopObjectArray;
Expand All @@ -169,22 +169,22 @@ const char* RemoveOtherVDesktops()
hr = VDesktopWrapper.GetDesktops(&DesktopObjectArray);

if (FAILED(hr))
return "DesktopObjectArray";
return L"DesktopObjectArray";

UINT NumDesktops;

if (FAILED(DesktopObjectArray->GetCount(&NumDesktops)))
return "NumDesktops";
return L"NumDesktops";

if (FAILED(DesktopObjectArray->GetAt(0, VDesktopWrapper.CurrentIID, (PVOID*)&FirstDesktop)))
return "No FirstDesktop.";
return L"No FirstDesktop.";

IVirtualDesktop* CurrentDesktop = NULL;
for (unsigned int i = 1; i < NumDesktops && i < 255; i++)
{

if (FAILED(DesktopObjectArray->GetAt(i, VDesktopWrapper.CurrentIID, (PVOID*)&CurrentDesktop)))
return "DesktopObjectArray->GetAt";
return L"DesktopObjectArray->GetAt";

VDesktopWrapper.RemoveDesktop(CurrentDesktop, FirstDesktop);

Expand All @@ -194,7 +194,7 @@ const char* RemoveOtherVDesktops()

}

const char* SetupVDesktops(std::vector<WORKSPACE_INFO>& WorkspaceList)
const wchar_t* SetupVDesktops(std::vector<WORKSPACE_INFO>& WorkspaceList)
{

WorkspaceList[1].VDesktop = FirstDesktop;
Expand All @@ -204,39 +204,39 @@ const char* SetupVDesktops(std::vector<WORKSPACE_INFO>& WorkspaceList)
HRESULT Hr;
Hr = VDesktopWrapper.CreateDesktopW(&WorkspaceList[i].VDesktop);
if (FAILED(Hr) || !WorkspaceList[i].VDesktop)
return "CreateDesktopW";
return L"CreateDesktopW";
}

return NULL;

}

const char* MoveWindowToVDesktop(HWND WindowHandle, IVirtualDesktop* VDesktop)
const wchar_t* MoveWindowToVDesktop(HWND WindowHandle, IVirtualDesktop* VDesktop)
{

IApplicationView* ApplicationView;

HRESULT Result = ViewCollection->GetViewForHwnd(WindowHandle, &ApplicationView);

if (FAILED(Result))
return "GetViewForHwnd";
return L"GetViewForHwnd";

Result = VDesktopWrapper.MoveViewToDesktop(ApplicationView, VDesktop);

ApplicationView->Release();

if (FAILED(Result))
return "MoveViewToDesktop";
return L"MoveViewToDesktop";

return NULL;
}

const char* CheckViewPinned(HWND WindowHandle, BOOL* IsPinned)
const wchar_t* CheckViewPinned(HWND WindowHandle, BOOL* IsPinned)
{
IApplicationView* ApplicationView;

if (FAILED(ViewCollection->GetViewForHwnd(WindowHandle, &ApplicationView)))
return "GetViewForHwnd";
return L"GetViewForHwnd";

WCHAR ApplicationIdBuffer[1024];
PWSTR ApplicationId = ApplicationIdBuffer;
Expand All @@ -246,18 +246,18 @@ const char* CheckViewPinned(HWND WindowHandle, BOOL* IsPinned)
ApplicationView->Release();

if (FAILED(Result))
return "IsAppIdPinned";
return L"IsAppIdPinned";

return NULL;
}


const char* CheckAppPinned(HWND WindowHandle, BOOL* IsPinned)
const wchar_t* CheckAppPinned(HWND WindowHandle, BOOL* IsPinned)
{
IApplicationView* ApplicationView;

if (FAILED(ViewCollection->GetViewForHwnd(WindowHandle, &ApplicationView)))
return "GetViewForHwnd";
return L"GetViewForHwnd";

WCHAR ApplicationIdBuffer[1024];
PWSTR ApplicationId = ApplicationIdBuffer;
Expand All @@ -267,23 +267,23 @@ const char* CheckAppPinned(HWND WindowHandle, BOOL* IsPinned)
ApplicationView->Release();

if (FAILED(Result))
return "GetAppUserModelId";
return L"GetAppUserModelId";

Result = PinnedApps->IsAppIdPinned(ApplicationId, IsPinned);

if (FAILED(Result))
return "IsAppIdPinned";
return L"IsAppIdPinned";

return NULL;
}

const char* SwitchToWorkspace(WORKSPACE_INFO* Workspace)
const wchar_t* SwitchToWorkspace(WORKSPACE_INFO* Workspace)
{

HRESULT Result = VDesktopWrapper.SwitchDesktop(Workspace->VDesktop);

if (FAILED(Result))
return "SwitchToWorkspace";
return L"SwitchToWorkspace";

return NULL;
}
Loading

0 comments on commit e50cf7f

Please sign in to comment.