Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Windows 10 Taskbar Reorder WIP (uses RaMMichael's Taskbar Tweaking Library)
#include "stdafx.h"
#include "include/TTLib.h"
BOOL ShiftActiveWindow(int nToShift) {
if (!TTLib_ManipulationStart())
{
wprintf(L"TTLib_ManipulationStart() failed\n");
return FALSE;
}
HANDLE hTaskbar = TTLib_GetMainTaskbar();
HANDLE hActiveButtonGroup = TTLib_GetActiveButtonGroup(hTaskbar);
HANDLE hTrackedButtonGroup = TTLib_GetTrackedButtonGroup(hTaskbar);
int nCount;
if (TTLib_GetButtonGroupCount(hTaskbar, &nCount))
{
wprintf(L"Button group count: %d\n", nCount);
for (int i = 0; i < nCount; i++)
{
HANDLE hButtonGroup = TTLib_GetButtonGroup(hTaskbar, i);
wprintf(L"%d: %p\n", i, hButtonGroup);
if (hButtonGroup == hActiveButtonGroup) {
wprintf(L"\t* This is the active button group\n");
// assume move index spaces only
int newIndex;
if (i + nToShift < 0 && abs(nToShift) < nCount) {
newIndex = nCount - 1 - (nToShift - i);
}
else {
newIndex = abs(i + nToShift) % nCount;
}
BOOL result = TTLib_ButtonGroupMove(hTaskbar, i, newIndex);
wprintf(L"move result: %d\n", result);
TTLib_ManipulationEnd();
return result;
}
}
}
TTLib_ManipulationEnd();
return FALSE;
}
void registerKeys() {
HANDLE hWnd = GetActiveWindow();
if (RegisterHotKey(
hWnd,
10000,
//MOD_ALT | MOD_NOREPEAT,
MOD_SHIFT | MOD_WIN | MOD_NOREPEAT,
0x48)) //0x48 is 'h'
{
wprintf("Hotkey 'SHIFT+WIN+h' registered, using MOD_NOREPEAT flag\n");
}
if (RegisterHotKey(
hWnd,
10001,
MOD_SHIFT | MOD_WIN | MOD_NOREPEAT,
//MOD_ALT | MOD_NOREPEAT,
0x4C)) //0x4C is 'l'
{
wprintf("Hotkey 'SHIFT+WIN+l' registered, using MOD_NOREPEAT flag\n");
}
MSG msg = { 0 };
while (GetMessage(&msg, NULL, 0, 0) != 0)
{
if (msg.message == WM_HOTKEY)
{
//if (msg.wParam == 10000) wprintf("WM_HOTKEY received\n");
if (msg.wParam == 10000) ShiftActiveWindow(-1);
if (msg.wParam == 10001) ShiftActiveWindow(1);
}
}
}
int wmain(int argc, WCHAR* argv[])
//int WinMain(HINSTANCE hInstance,
// HINSTANCE hPrevInstance,
// LPTSTR lpCmdLine,
// int cmdShow)
{
BOOL bSuccess = FALSE;
DWORD dwError;
wprintf(L"Initializing 7+ Taskbar Tweaking library...\n");
dwError = TTLib_Init();
if (dwError == TTLIB_OK)
{
wprintf(L"Loading 7+ Taskbar Tweaking library into explorer...\n");
dwError = TTLib_LoadIntoExplorer();
if (dwError == TTLIB_OK)
{
/* bSuccess = PrintAllTaskbarsContents(); */
registerKeys();
//ShiftActiveWindow(-1);
TTLib_UnloadFromExplorer();
}
else
wprintf(L"TTLib_LoadIntoExplorer() failed with error %u\n", dwError);
TTLib_Uninit();
}
else
wprintf(L"TTLib_Init() failed with error %u\n", dwError);
return bSuccess ? 0 : 1;
}
@AlexN34

This comment has been minimized.

Copy link
Owner Author

@AlexN34 AlexN34 commented Nov 9, 2019

  • ln47 should be true, fix on clean up
  • remove commented artifacts from print taskbar example
  • specify windows linker flags instead of console to hide con window
  • support reorder on secondary taskbar too
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment