Skip to content

Instantly share code, notes, and snippets.

@m417z

m417z/TTLib.c Secret

Created September 22, 2020 12:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save m417z/d523a5a1c8d71d74152aa4c5837a163f to your computer and use it in GitHub Desktop.
Save m417z/d523a5a1c8d71d74152aa4c5837a163f to your computer and use it in GitHub Desktop.
7+ Taskbar Tweaking Library v5.9, selected source code files
#include "stdafx.h"
#include "TTLib.h"
#include "functions.h"
#include "version.h"
#include "wnd_proc.h"
#include "inject_init_struct_def.h"
// superglobals
extern HINSTANCE hDllInst;
extern int nWinVersion;
extern WORD nExplorerBuild, nExplorerQFE;
extern HANDLE hTweakerProcess;
extern HANDLE hCleanEvent;
extern HANDLE g_hRequestMapping;
extern void *g_pRequestMappingView;
extern HANDLE g_hResponseMapping;
extern void *g_pResponseMappingView;
extern UINT g_uCustomMsg;
BOOL APIENTRY DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved)
{
switch(fdwReason)
{
case DLL_PROCESS_ATTACH:
hDllInst = hinstDLL;
break;
case DLL_THREAD_ATTACH:
case DLL_THREAD_DETACH:
break;
case DLL_PROCESS_DETACH:
break;
}
return TRUE;
}
DWORD WINAPI WaitThread(LPVOID lpParameter)
{
HANDLE hHandles[] = { hTweakerProcess, hCleanEvent };
WaitForMultipleObjects(_countof(hHandles), hHandles, FALSE, INFINITE);
WndProcExit();
WndProcWaitTillDone();
CloseHandle(hTweakerProcess);
CloseHandle(hCleanEvent);
if(g_pResponseMappingView)
{
UnmapViewOfFile(g_pResponseMappingView);
g_pResponseMappingView = NULL;
}
if(g_hResponseMapping)
{
CloseHandle(g_hResponseMapping);
g_hResponseMapping = NULL;
}
if(g_pRequestMappingView)
{
UnmapViewOfFile(g_pRequestMappingView);
g_pRequestMappingView = NULL;
}
if(g_hRequestMapping)
{
CloseHandle(g_hRequestMapping);
g_hRequestMapping = NULL;
}
FreeLibraryAndExitThread(hDllInst, 0);
}
// Exported
DWORD __stdcall Init(INJECT_INIT_STRUCT *p_inject_init_struct)
{
static volatile LONG nInitCalled = 0;
BOOL bWndProcInitDone = FALSE;
DWORD dwError;
// Make sure this function is called only once
if(InterlockedExchange(&nInitCalled, 1))
return TTLIB_ERR_LIB_INIT_ALREADY_CALLED;
// Check tweaker version
if(p_inject_init_struct->dwVersion != VER_FILE_VERSION_LONG)
return TTLIB_ERR_LIB_LIB_VER_MISMATCH;
// Check explorer version
nWinVersion = WIN_VERSION_UNSUPPORTED;
VS_FIXEDFILEINFO *pFixedFileInfo = GetModuleVersionInfo(NULL, NULL);
if(!pFixedFileInfo)
return TTLIB_ERR_LIB_WIN_VER_MISMATCH;
WORD nMajor = HIWORD(pFixedFileInfo->dwFileVersionMS);
WORD nMinor = LOWORD(pFixedFileInfo->dwFileVersionMS);
WORD nBuild = HIWORD(pFixedFileInfo->dwFileVersionLS);
WORD nQFE = LOWORD(pFixedFileInfo->dwFileVersionLS);
switch(nMajor)
{
case 6:
switch(nMinor)
{
case 1:
nWinVersion = WIN_VERSION_7;
break;
case 2:
nWinVersion = WIN_VERSION_8;
break;
case 3:
if(nQFE < 17000)
nWinVersion = WIN_VERSION_81;
else
nWinVersion = WIN_VERSION_811;
break;
case 4:
nWinVersion = WIN_VERSION_10_T1;
break;
}
break;
case 10:
if(nBuild <= 10240)
nWinVersion = WIN_VERSION_10_T1;
else if(nBuild <= 10586)
nWinVersion = WIN_VERSION_10_T2;
else if(nBuild <= 14393)
nWinVersion = WIN_VERSION_10_R1;
else if(nBuild <= 15063)
nWinVersion = WIN_VERSION_10_R2;
else if(nBuild <= 16299)
nWinVersion = WIN_VERSION_10_R3;
else if(nBuild <= 17134)
nWinVersion = WIN_VERSION_10_R4;
else if(nBuild <= 17763)
nWinVersion = WIN_VERSION_10_R5;
else if(nBuild <= 18362)
nWinVersion = WIN_VERSION_10_19H1;
else if(nBuild <= 19041)
nWinVersion = WIN_VERSION_10_20H1;
else
nWinVersion = WIN_VERSION_10_20H2;
break;
}
if(nWinVersion == WIN_VERSION_UNSUPPORTED)
return TTLIB_ERR_LIB_WIN_VER_MISMATCH;
nExplorerBuild = nBuild;
nExplorerQFE = nQFE;
// Set some globals
hTweakerProcess = p_inject_init_struct->hTweakerProcess;
hCleanEvent = p_inject_init_struct->hCleanEvent;
g_hRequestMapping = p_inject_init_struct->hRequestMapping;
g_hResponseMapping = p_inject_init_struct->hResponseMapping;
g_uCustomMsg = p_inject_init_struct->uCustomMsg;
g_pRequestMappingView = MapViewOfFile(g_hRequestMapping, FILE_MAP_READ, 0, 0, 0);
if(!g_pRequestMappingView)
{
dwError = TTLIB_ERR_LIB_VIEW_MAPPING;
goto fail;
}
g_pResponseMappingView = MapViewOfFile(g_hResponseMapping, FILE_MAP_WRITE, 0, 0, 0);
if(!g_pRequestMappingView)
{
dwError = TTLIB_ERR_LIB_VIEW_MAPPING;
goto fail;
}
// Init
dwError = WndProcInit();
if(dwError)
{
goto fail;
}
bWndProcInitDone = TRUE;
// Create our thread that will clean stuff up
HANDLE hWaitThread = CreateThread(NULL, 0, WaitThread, NULL, 0, NULL);
if(!hWaitThread)
{
dwError = TTLIB_ERR_LIB_WAITTHREAD;
goto fail;
}
DuplicateHandle(GetCurrentProcess(), hWaitThread, p_inject_init_struct->hTweakerProcess, &p_inject_init_struct->hWaitThread, SYNCHRONIZE, FALSE, DUPLICATE_CLOSE_SOURCE);
return TTLIB_OK;
fail:
if(bWndProcInitDone)
{
WndProcExit();
WndProcWaitTillDone();
}
if(g_pResponseMappingView)
{
UnmapViewOfFile(g_pResponseMappingView);
g_pResponseMappingView = NULL;
}
if(g_pRequestMappingView)
{
UnmapViewOfFile(g_pRequestMappingView);
g_pRequestMappingView = NULL;
}
return dwError;
}
#ifndef _TTLIB_H_
#define _TTLIB_H_
#pragma once
#include <windows.h>
#ifdef __cplusplus
extern "C" {
#endif
#define TTLIBCALL __stdcall
//////////////////////////////////////////////////////////////////////////
// Initialization
#define TTLIB_OK 0
// Errors returned by TTLib_Init
enum
{
TTLIB_ERR_INIT_ALREADY_INITIALIZED = 1,
TTLIB_ERR_INIT_REGISTER_MESSAGE,
TTLIB_ERR_INIT_FILE_MAPPING,
TTLIB_ERR_INIT_VIEW_MAPPING,
};
// Errors returned by TTLib_LoadIntoExplorer
enum
{
TTLIB_ERR_EXE_NOT_INITIALIZED = 1,
TTLIB_ERR_EXE_ALREADY_LOADED,
TTLIB_ERR_EXE_FIND_TASKBAR,
TTLIB_ERR_EXE_OPEN_PROCESS,
TTLIB_ERR_EXE_VIRTUAL_ALLOC,
TTLIB_ERR_EXE_WRITE_PROC_MEM,
TTLIB_ERR_EXE_CREATE_REMOTE_THREAD,
TTLIB_ERR_EXE_READ_PROC_MEM,
TTLIB_ERR_INJ_BEFORE_RUN = 101,
TTLIB_ERR_INJ_BEFORE_GETMODULEHANDLE,
TTLIB_ERR_INJ_BEFORE_LOADLIBRARY,
TTLIB_ERR_INJ_BEFORE_GETPROCADDR,
TTLIB_ERR_INJ_BEFORE_LIBINIT,
TTLIB_ERR_INJ_GETMODULEHANDLE,
TTLIB_ERR_INJ_LOADLIBRARY,
TTLIB_ERR_INJ_GETPROCADDR,
TTLIB_ERR_LIB_INIT_ALREADY_CALLED = 201,
TTLIB_ERR_LIB_LIB_VER_MISMATCH,
TTLIB_ERR_LIB_WIN_VER_MISMATCH,
TTLIB_ERR_LIB_VIEW_MAPPING,
TTLIB_ERR_LIB_FIND_IMPORT,
TTLIB_ERR_LIB_WND_TASKBAR,
TTLIB_ERR_LIB_WND_TASKSW,
TTLIB_ERR_LIB_WND_TASKLIST,
TTLIB_ERR_LIB_WND_THUMB,
TTLIB_ERR_LIB_MSG_DLL_INIT,
TTLIB_ERR_LIB_WAITTHREAD,
TTLIB_ERR_LIB_EXTHREAD_MINHOOK = 301,
TTLIB_ERR_LIB_EXTHREAD_MINHOOK_PRELOADED,
TTLIB_ERR_LIB_EXTHREAD_COMFUNCHOOK,
TTLIB_ERR_LIB_EXTHREAD_REFRESHTASKBAR,
TTLIB_ERR_LIB_EXTHREAD_MINHOOK_APPLY,
};
DWORD TTLIBCALL TTLib_Init();
BOOL TTLIBCALL TTLib_Uninit();
DWORD TTLIBCALL TTLib_LoadIntoExplorer();
BOOL TTLIBCALL TTLib_IsLoadedIntoExplorer();
BOOL TTLIBCALL TTLib_UnloadFromExplorer();
//////////////////////////////////////////////////////////////////////////
// Manipulation
typedef enum
{
TTLIB_GROUPTYPE_UNKNOWN = 0,
TTLIB_GROUPTYPE_NORMAL,
TTLIB_GROUPTYPE_PINNED,
TTLIB_GROUPTYPE_COMBINED,
TTLIB_GROUPTYPE_TEMPORARY,
} TTLIB_GROUPTYPE;
BOOL TTLIBCALL TTLib_ManipulationStart();
BOOL TTLIBCALL TTLib_ManipulationEnd();
HANDLE TTLIBCALL TTLib_GetMainTaskbar();
BOOL TTLIBCALL TTLib_GetSecondaryTaskbarCount(int *pnCount);
HANDLE TTLIBCALL TTLib_GetSecondaryTaskbar(int nIndex);
HWND TTLIBCALL TTLib_GetTaskListWindow(HANDLE hTaskbar);
HWND TTLIBCALL TTLib_GetTaskbarWindow(HANDLE hTaskbar);
HMONITOR TTLIBCALL TTLib_GetTaskbarMonitor(HANDLE hTaskbar);
BOOL TTLIBCALL TTLib_GetButtonGroupCount(HANDLE hTaskbar, int *pnCount);
HANDLE TTLIBCALL TTLib_GetButtonGroup(HANDLE hTaskbar, int nIndex);
HANDLE TTLIBCALL TTLib_GetActiveButtonGroup(HANDLE hTaskbar);
HANDLE TTLIBCALL TTLib_GetTrackedButtonGroup(HANDLE hTaskbar);
BOOL TTLIBCALL TTLib_ButtonGroupMove(HANDLE hTaskbar, int nIndexFrom, int nIndexTo);
BOOL TTLIBCALL TTLib_GetButtonGroupTaskbar(HANDLE hButtonGroup, HANDLE *phTaskbar);
BOOL TTLIBCALL TTLib_GetButtonGroupRect(HANDLE hButtonGroup, RECT *pRect);
BOOL TTLIBCALL TTLib_GetButtonGroupType(HANDLE hButtonGroup, TTLIB_GROUPTYPE *pnType);
SIZE_T TTLIBCALL TTLib_GetButtonGroupAppId(HANDLE hButtonGroup, WCHAR *pszAppId, SIZE_T nMaxSize);
BOOL TTLIBCALL TTLib_GetButtonCount(HANDLE hButtonGroup, int *pnCount);
HANDLE TTLIBCALL TTLib_GetButton(HANDLE hButtonGroup, int nIndex);
HANDLE TTLIBCALL TTLib_GetActiveButton(HANDLE hTaskbar);
HANDLE TTLIBCALL TTLib_GetTrackedButton(HANDLE hTaskbar);
BOOL TTLIBCALL TTLib_ButtonMoveInButtonGroup(HANDLE hButtonGroup, int nIndexFrom, int nIndexTo);
HWND TTLIBCALL TTLib_GetButtonWindow(HANDLE hButton);
//////////////////////////////////////////////////////////////////////////
// Lists
typedef enum
{
TTLIB_LIST_LABEL = 0,
TTLIB_LIST_GROUP,
TTLIB_LIST_GROUPPINNED,
TTLIB_LIST_COMBINE,
} TTLIB_LIST;
typedef enum
{
TTLIB_LIST_LABEL_NEVER = 0,
TTLIB_LIST_LABEL_ALWAYS,
TTLIB_LIST_GROUP_NEVER = 0,
TTLIB_LIST_GROUP_ALWAYS,
TTLIB_LIST_GROUPPINNED_NEVER = 0,
TTLIB_LIST_GROUPPINNED_ALWAYS,
TTLIB_LIST_COMBINE_NEVER = 0,
TTLIB_LIST_COMBINE_ALWAYS,
} TTLIB_LIST_VALUE;
BOOL TTLIBCALL TTLib_AddAppIdToList(TTLIB_LIST nList, const WCHAR *pszAppId, TTLIB_LIST_VALUE nListValue);
BOOL TTLIBCALL TTLib_RemoveAppIdFromList(TTLIB_LIST nList, const WCHAR *pszAppId);
BOOL TTLIBCALL TTLib_GetAppIdListValue(TTLIB_LIST nList, const WCHAR *pszAppId, TTLIB_LIST_VALUE *pnListValue);
//////////////////////////////////////////////////////////////////////////
// Other
#define MAX_APPID_LENGTH MAX_PATH
#ifdef __cplusplus
}
#endif
#endif // _TTLIB_H_
#include "stdafx.h"
#include "TTLibAPI.h"
#include "explorer_inject.h"
#include "custom_messages.h"
static BOOL g_bInitialized = FALSE;
static UINT g_uCustomMsg = WM_NULL;
static HANDLE g_hRequestMapping;
static void *g_pRequestMappingView;
static HANDLE g_hResponseMapping;
static void *g_pResponseMappingView;
static HANDLE g_hManipulationRequestEvent = NULL, g_hManipulationResponseEvent = NULL, g_hManipulationDoneEvent = NULL;
static BOOL ManipulationExecAPIMessage(int nApiId);
static BOOL SendExecAPIMessage(int nApiId);
DWORD TTLIBCALL TTLib_Init()
{
if(g_bInitialized)
return TTLIB_ERR_INIT_ALREADY_INITIALIZED;
UINT uCustomMsg = WM_NULL;
HANDLE hRequestMapping = NULL, hResponseMapping = NULL;
void *pRequestMappingView = NULL, *pResponseMappingView = NULL;
DWORD dwError;
WCHAR szCustomMsgName[sizeof("7+ Taskbar Tweaking Library 12345678")];
wsprintf(szCustomMsgName, L"7+ Taskbar Tweaking Library %08X", GetCurrentProcessId());
uCustomMsg = RegisterWindowMessage(szCustomMsgName);
if(!uCustomMsg)
{
dwError = TTLIB_ERR_INIT_REGISTER_MESSAGE;
goto fail;
}
hRequestMapping = CreateFileMapping(INVALID_HANDLE_VALUE, NULL, PAGE_READWRITE, 0, REQUEST_MAPPING_SIZE, NULL);
if(!hRequestMapping)
{
dwError = TTLIB_ERR_INIT_FILE_MAPPING;
goto fail;
}
hResponseMapping = CreateFileMapping(INVALID_HANDLE_VALUE, NULL, PAGE_READWRITE, 0, RESPONSE_MAPPING_SIZE, NULL);
if(!hResponseMapping)
{
dwError = TTLIB_ERR_INIT_FILE_MAPPING;
goto fail;
}
pRequestMappingView = MapViewOfFile(hRequestMapping, FILE_MAP_WRITE, 0, 0, 0);
if(!pRequestMappingView)
{
dwError = TTLIB_ERR_INIT_VIEW_MAPPING;
goto fail;
}
pResponseMappingView = MapViewOfFile(hResponseMapping, FILE_MAP_READ, 0, 0, 0);
if(!pResponseMappingView)
{
dwError = TTLIB_ERR_INIT_VIEW_MAPPING;
goto fail;
}
g_uCustomMsg = uCustomMsg;
g_hRequestMapping = hRequestMapping;
g_hResponseMapping = hResponseMapping;
g_pRequestMappingView = pRequestMappingView;
g_pResponseMappingView = pResponseMappingView;
g_bInitialized = TRUE;
return TTLIB_OK;
fail:
if(pResponseMappingView)
UnmapViewOfFile(pResponseMappingView);
if(pRequestMappingView)
UnmapViewOfFile(pRequestMappingView);
if(hResponseMapping)
CloseHandle(hResponseMapping);
if(hRequestMapping)
CloseHandle(hRequestMapping);
return dwError;
}
BOOL TTLIBCALL TTLib_Uninit()
{
if(!g_bInitialized)
return FALSE;
if(ExplorerIsInjected())
TTLib_UnloadFromExplorer();
if(g_pResponseMappingView)
{
UnmapViewOfFile(g_pResponseMappingView);
g_pResponseMappingView = NULL;
}
if(g_pRequestMappingView)
{
UnmapViewOfFile(g_pRequestMappingView);
g_pRequestMappingView = NULL;
}
if(g_hResponseMapping)
{
CloseHandle(g_hResponseMapping);
g_hResponseMapping = NULL;
}
if(g_hRequestMapping)
{
CloseHandle(g_hRequestMapping);
g_hRequestMapping = NULL;
}
g_uCustomMsg = WM_NULL;
g_bInitialized = FALSE;
return TRUE;
}
//////////////////////////////////////////////////////////////////////////
DWORD TTLIBCALL TTLib_LoadIntoExplorer()
{
if(!g_bInitialized)
return TTLIB_ERR_EXE_NOT_INITIALIZED;
if(ExplorerIsInjected())
return TTLIB_ERR_EXE_ALREADY_LOADED;
return ExplorerInject(g_hRequestMapping, g_hResponseMapping, g_uCustomMsg);
}
BOOL TTLIBCALL TTLib_IsLoadedIntoExplorer()
{
return g_bInitialized && ExplorerIsInjected();
}
BOOL TTLIBCALL TTLib_UnloadFromExplorer()
{
if(!ExplorerIsInjected())
return FALSE;
if(g_hManipulationDoneEvent)
TTLib_ManipulationEnd();
return ExplorerCleanup();
}
//////////////////////////////////////////////////////////////////////////
BOOL TTLIBCALL TTLib_ManipulationStart()
{
if(!ExplorerIsInjected() || g_hManipulationDoneEvent)
return FALSE;
HWND hTaskbarWnd = ExplorerGetTaskbarWnd();
if(!hTaskbarWnd)
return FALSE;
DWORD dwExplorerProcessId;
GetWindowThreadProcessId(hTaskbarWnd, &dwExplorerProcessId);
HANDLE hExplorerProcess = OpenProcess(PROCESS_DUP_HANDLE, FALSE, dwExplorerProcessId);
if(!hExplorerProcess)
return FALSE;
g_hManipulationRequestEvent = CreateEvent(NULL, FALSE, FALSE, NULL);
g_hManipulationResponseEvent = CreateEvent(NULL, FALSE, FALSE, NULL);
g_hManipulationDoneEvent = CreateEvent(NULL, FALSE, FALSE, NULL);
HANDLE hRemoteManipulationRequestEvent, hRemoteManipulationResponseEvent, hRemoteManipulationDoneEvent;
DuplicateHandle(GetCurrentProcess(), g_hManipulationRequestEvent, hExplorerProcess, &hRemoteManipulationRequestEvent, SYNCHRONIZE, FALSE, 0);
DuplicateHandle(GetCurrentProcess(), g_hManipulationResponseEvent, hExplorerProcess, &hRemoteManipulationResponseEvent, EVENT_MODIFY_STATE, FALSE, 0);
DuplicateHandle(GetCurrentProcess(), g_hManipulationDoneEvent, hExplorerProcess, &hRemoteManipulationDoneEvent, SYNCHRONIZE, FALSE, 0);
REQUEST_MANIPULATION_START *pRequest = g_pRequestMappingView;
pRequest->hManipulationRequestEvent = hRemoteManipulationRequestEvent;
pRequest->hManipulationResponseEvent = hRemoteManipulationResponseEvent;
pRequest->hManipulationDoneEvent = hRemoteManipulationDoneEvent;
BOOL bSucceeded = (BOOL)SendMessage(hTaskbarWnd, g_uCustomMsg, 0, MSG_DLL_MANIPULATION_START);
if(!bSucceeded)
{
DuplicateHandle(hExplorerProcess, hRemoteManipulationRequestEvent, NULL, NULL, 0, FALSE, DUPLICATE_CLOSE_SOURCE);
DuplicateHandle(hExplorerProcess, hRemoteManipulationResponseEvent, NULL, NULL, 0, FALSE, DUPLICATE_CLOSE_SOURCE);
DuplicateHandle(hExplorerProcess, hRemoteManipulationDoneEvent, NULL, NULL, 0, FALSE, DUPLICATE_CLOSE_SOURCE);
}
CloseHandle(hExplorerProcess);
return bSucceeded;
}
BOOL TTLIBCALL TTLib_ManipulationEnd()
{
if(!ExplorerIsInjected() || !g_hManipulationDoneEvent)
return FALSE;
SetEvent(g_hManipulationDoneEvent);
CloseHandle(g_hManipulationRequestEvent);
g_hManipulationRequestEvent = NULL;
CloseHandle(g_hManipulationResponseEvent);
g_hManipulationResponseEvent = NULL;
CloseHandle(g_hManipulationDoneEvent);
g_hManipulationDoneEvent = NULL;
return TRUE;
}
//////////////////////////////////////////////////////////////////////////
HANDLE TTLIBCALL TTLib_GetMainTaskbar()
{
if(!g_bInitialized || !ExplorerIsInjected() || !g_hManipulationDoneEvent)
return NULL;
if(!ManipulationExecAPIMessage(API_GET_MAIN_TASKBAR))
return NULL;
RESPONSE_GET_MAIN_TASKBAR *pResponse = g_pResponseMappingView;
return pResponse->hTaskbar;
}
BOOL TTLIBCALL TTLib_GetSecondaryTaskbarCount(int *pnCount)
{
if(!g_bInitialized || !ExplorerIsInjected() || !g_hManipulationDoneEvent)
return FALSE;
if(!ManipulationExecAPIMessage(API_GET_SECONDARY_TASKBAR_COUNT))
return FALSE;
RESPONSE_GET_SECONDARY_TASKBAR_COUNT *pResponse = g_pResponseMappingView;
*pnCount = pResponse->nCount;
return TRUE;
}
HANDLE TTLIBCALL TTLib_GetSecondaryTaskbar(int nIndex)
{
if(!g_bInitialized || !ExplorerIsInjected() || !g_hManipulationDoneEvent)
return NULL;
REQUEST_GET_SECONDARY_TASKBAR *pRequest = g_pRequestMappingView;
pRequest->nIndex = nIndex;
if(!ManipulationExecAPIMessage(API_GET_SECONDARY_TASKBAR))
return NULL;
RESPONSE_GET_SECONDARY_TASKBAR *pResponse = g_pResponseMappingView;
return pResponse->hTaskbar;
}
HWND TTLIBCALL TTLib_GetTaskListWindow(HANDLE hTaskbar)
{
if(!g_bInitialized || !ExplorerIsInjected() || !g_hManipulationDoneEvent)
return NULL;
REQUEST_GET_TASK_LIST_WINDOW *pRequest = g_pRequestMappingView;
pRequest->hTaskbar = hTaskbar;
if(!ManipulationExecAPIMessage(API_GET_TASK_LIST_WINDOW))
return NULL;
RESPONSE_GET_TASK_LIST_WINDOW *pResponse = g_pResponseMappingView;
return pResponse->hWnd;
}
HWND TTLIBCALL TTLib_GetTaskbarWindow(HANDLE hTaskbar)
{
if(!g_bInitialized || !ExplorerIsInjected() || !g_hManipulationDoneEvent)
return NULL;
REQUEST_GET_TASKBAR_WINDOW *pRequest = g_pRequestMappingView;
pRequest->hTaskbar = hTaskbar;
if(!ManipulationExecAPIMessage(API_GET_TASKBAR_WINDOW))
return NULL;
RESPONSE_GET_TASKBAR_WINDOW *pResponse = g_pResponseMappingView;
return pResponse->hWnd;
}
HMONITOR TTLIBCALL TTLib_GetTaskbarMonitor(HANDLE hTaskbar)
{
if(!g_bInitialized || !ExplorerIsInjected() || !g_hManipulationDoneEvent)
return NULL;
REQUEST_GET_TASKBAR_MONITOR *pRequest = g_pRequestMappingView;
pRequest->hTaskbar = hTaskbar;
if(!ManipulationExecAPIMessage(API_GET_TASKBAR_MONITOR))
return NULL;
RESPONSE_GET_TASKBAR_MONITOR *pResponse = g_pResponseMappingView;
return pResponse->hMonitor;
}
//////////////////////////////////////////////////////////////////////////
BOOL TTLIBCALL TTLib_GetButtonGroupCount(HANDLE hTaskbar, int *pnCount)
{
if(!g_bInitialized || !ExplorerIsInjected() || !g_hManipulationDoneEvent)
return FALSE;
REQUEST_GET_BUTTON_GROUP_COUNT *pRequest = g_pRequestMappingView;
pRequest->hTaskbar = hTaskbar;
if(!ManipulationExecAPIMessage(API_GET_BUTTON_GROUP_COUNT))
return FALSE;
RESPONSE_GET_BUTTON_GROUP_COUNT *pResponse = g_pResponseMappingView;
*pnCount = pResponse->nCount;
return TRUE;
}
HANDLE TTLIBCALL TTLib_GetButtonGroup(HANDLE hTaskbar, int nIndex)
{
if(!g_bInitialized || !ExplorerIsInjected() || !g_hManipulationDoneEvent)
return NULL;
REQUEST_GET_BUTTON_GROUP *pRequest = g_pRequestMappingView;
pRequest->hTaskbar = hTaskbar;
pRequest->nIndex = nIndex;
if(!ManipulationExecAPIMessage(API_GET_BUTTON_GROUP))
return NULL;
RESPONSE_GET_BUTTON_GROUP *pResponse = g_pResponseMappingView;
return pResponse->hButtonGroup;
}
HANDLE TTLIBCALL TTLib_GetActiveButtonGroup(HANDLE hTaskbar)
{
if(!g_bInitialized || !ExplorerIsInjected() || !g_hManipulationDoneEvent)
return NULL;
REQUEST_GET_ACTIVE_BUTTON_GROUP *pRequest = g_pRequestMappingView;
pRequest->hTaskbar = hTaskbar;
if(!ManipulationExecAPIMessage(API_GET_ACTIVE_BUTTON_GROUP))
return NULL;
RESPONSE_GET_ACTIVE_BUTTON_GROUP *pResponse = g_pResponseMappingView;
return pResponse->hButtonGroup;
}
HANDLE TTLIBCALL TTLib_GetTrackedButtonGroup(HANDLE hTaskbar)
{
if(!g_bInitialized || !ExplorerIsInjected() || !g_hManipulationDoneEvent)
return NULL;
REQUEST_GET_TRACKED_BUTTON_GROUP *pRequest = g_pRequestMappingView;
pRequest->hTaskbar = hTaskbar;
if(!ManipulationExecAPIMessage(API_GET_TRACKED_BUTTON_GROUP))
return NULL;
RESPONSE_GET_TRACKED_BUTTON_GROUP *pResponse = g_pResponseMappingView;
return pResponse->hButtonGroup;
}
BOOL TTLIBCALL TTLib_ButtonGroupMove(HANDLE hTaskbar, int nIndexFrom, int nIndexTo)
{
if(!g_bInitialized || !ExplorerIsInjected() || !g_hManipulationDoneEvent)
return FALSE;
REQUEST_BUTTON_GROUP_MOVE *pRequest = g_pRequestMappingView;
pRequest->hTaskbar = hTaskbar;
pRequest->nIndexFrom = nIndexFrom;
pRequest->nIndexTo = nIndexTo;
if(!ManipulationExecAPIMessage(API_BUTTON_GROUP_MOVE))
return FALSE;
return TRUE;
}
BOOL TTLIBCALL TTLib_GetButtonGroupTaskbar(HANDLE hButtonGroup, HANDLE *phTaskbar)
{
if(!g_bInitialized || !ExplorerIsInjected() || !g_hManipulationDoneEvent)
return FALSE;
REQUEST_GET_BUTTON_GROUP_TASKBAR *pRequest = g_pRequestMappingView;
pRequest->hButtonGroup = hButtonGroup;
if(!ManipulationExecAPIMessage(API_GET_BUTTON_GROUP_TASKBAR))
return FALSE;
RESPONSE_GET_BUTTON_GROUP_TASKBAR *pResponse = g_pResponseMappingView;
*phTaskbar = pResponse->hTaskbar;
return TRUE;
}
BOOL TTLIBCALL TTLib_GetButtonGroupRect(HANDLE hButtonGroup, RECT *pRect)
{
if(!g_bInitialized || !ExplorerIsInjected() || !g_hManipulationDoneEvent)
return FALSE;
REQUEST_GET_BUTTON_GROUP_RECT *pRequest = g_pRequestMappingView;
pRequest->hButtonGroup = hButtonGroup;
if(!ManipulationExecAPIMessage(API_GET_BUTTON_GROUP_RECT))
return FALSE;
RESPONSE_GET_BUTTON_GROUP_RECT *pResponse = g_pResponseMappingView;
*pRect = pResponse->rc;
return TRUE;
}
BOOL TTLIBCALL TTLib_GetButtonGroupType(HANDLE hButtonGroup, TTLIB_GROUPTYPE *pnType)
{
if(!g_bInitialized || !ExplorerIsInjected() || !g_hManipulationDoneEvent)
return FALSE;
REQUEST_GET_BUTTON_GROUP_TYPE *pRequest = g_pRequestMappingView;
pRequest->hButtonGroup = hButtonGroup;
if(!ManipulationExecAPIMessage(API_GET_BUTTON_GROUP_TYPE))
return FALSE;
RESPONSE_GET_BUTTON_GROUP_TYPE *pResponse = g_pResponseMappingView;
*pnType = pResponse->nType;
return TRUE;
}
SIZE_T TTLIBCALL TTLib_GetButtonGroupAppId(HANDLE hButtonGroup, WCHAR *pszAppId, SIZE_T nMaxSize)
{
if(!g_bInitialized || !ExplorerIsInjected() || !g_hManipulationDoneEvent)
return 0;
REQUEST_GET_BUTTON_GROUP_APP_ID *pRequest = g_pRequestMappingView;
pRequest->hButtonGroup = hButtonGroup;
pRequest->nMaxSize = nMaxSize;
if(!ManipulationExecAPIMessage(API_GET_BUTTON_GROUP_APP_ID))
return 0;
RESPONSE_GET_BUTTON_GROUP_APP_ID *pResponse = g_pResponseMappingView;
CopyMemory(pszAppId, pResponse->szAppId, pResponse->nResultSize*sizeof(WCHAR));
return pResponse->nResultSize;
}
//////////////////////////////////////////////////////////////////////////
BOOL TTLIBCALL TTLib_GetButtonCount(HANDLE hButtonGroup, int *pnCount)
{
if(!g_bInitialized || !ExplorerIsInjected() || !g_hManipulationDoneEvent)
return FALSE;
REQUEST_GET_BUTTON_COUNT *pRequest = g_pRequestMappingView;
pRequest->hButtonGroup = hButtonGroup;
if(!ManipulationExecAPIMessage(API_GET_BUTTON_COUNT))
return FALSE;
RESPONSE_GET_BUTTON_COUNT *pResponse = g_pResponseMappingView;
*pnCount = pResponse->nCount;
return TRUE;
}
HANDLE TTLIBCALL TTLib_GetButton(HANDLE hButtonGroup, int nIndex)
{
if(!g_bInitialized || !ExplorerIsInjected() || !g_hManipulationDoneEvent)
return FALSE;
REQUEST_GET_BUTTON *pRequest = g_pRequestMappingView;
pRequest->hButtonGroup = hButtonGroup;
pRequest->nIndex = nIndex;
if(!ManipulationExecAPIMessage(API_GET_BUTTON))
return FALSE;
RESPONSE_GET_BUTTON *pResponse = g_pResponseMappingView;
return pResponse->hButton;
}
HANDLE TTLIBCALL TTLib_GetActiveButton(HANDLE hTaskbar)
{
if(!g_bInitialized || !ExplorerIsInjected() || !g_hManipulationDoneEvent)
return FALSE;
REQUEST_GET_ACTIVE_BUTTON *pRequest = g_pRequestMappingView;
pRequest->hTaskbar = hTaskbar;
if(!ManipulationExecAPIMessage(API_GET_ACTIVE_BUTTON))
return FALSE;
RESPONSE_GET_ACTIVE_BUTTON *pResponse = g_pResponseMappingView;
return pResponse->hButton;
}
HANDLE TTLIBCALL TTLib_GetTrackedButton(HANDLE hTaskbar)
{
if(!g_bInitialized || !ExplorerIsInjected() || !g_hManipulationDoneEvent)
return FALSE;
REQUEST_GET_TRACKED_BUTTON *pRequest = g_pRequestMappingView;
pRequest->hTaskbar = hTaskbar;
if(!ManipulationExecAPIMessage(API_GET_TRACKED_BUTTON))
return FALSE;
RESPONSE_GET_TRACKED_BUTTON *pResponse = g_pResponseMappingView;
return pResponse->hButton;
}
BOOL TTLIBCALL TTLib_ButtonMoveInButtonGroup(HANDLE hButtonGroup, int nIndexFrom, int nIndexTo)
{
if(!g_bInitialized || !ExplorerIsInjected() || !g_hManipulationDoneEvent)
return FALSE;
REQUEST_BUTTON_MOVE_IN_BUTTON_GROUP *pRequest = g_pRequestMappingView;
pRequest->hButtonGroup = hButtonGroup;
pRequest->nIndexFrom = nIndexFrom;
pRequest->nIndexTo = nIndexTo;
if(!ManipulationExecAPIMessage(API_BUTTON_MOVE_IN_BUTTON_GROUP))
return FALSE;
return TRUE;
}
HWND TTLIBCALL TTLib_GetButtonWindow(HANDLE hButton)
{
if(!g_bInitialized || !ExplorerIsInjected() || !g_hManipulationDoneEvent)
return NULL;
REQUEST_GET_BUTTON_WINDOW *pRequest = g_pRequestMappingView;
pRequest->hButton = hButton;
if(!ManipulationExecAPIMessage(API_GET_BUTTON_WINDOW))
return NULL;
RESPONSE_GET_BUTTON_WINDOW *pResponse = g_pResponseMappingView;
return pResponse->hWnd;
}
//////////////////////////////////////////////////////////////////////////
BOOL TTLIBCALL TTLib_AddAppIdToList(TTLIB_LIST nList, const WCHAR *pszAppId, TTLIB_LIST_VALUE nListValue)
{
if(!g_bInitialized || !ExplorerIsInjected())
return FALSE;
SIZE_T nAppIdLength = lstrlen(pszAppId);
if(nAppIdLength + 1 > MAX_APPID_LENGTH)
return FALSE;
REQUEST_ADD_APP_ID_TO_LIST *pRequest = g_pRequestMappingView;
pRequest->nList = nList;
CopyMemory(pRequest->szAppId, pszAppId, (nAppIdLength + 1) * sizeof(WCHAR));
pRequest->nListValue = nListValue;
if(!SendExecAPIMessage(API_ADD_APP_ID_TO_LIST))
return FALSE;
return TRUE;
}
BOOL TTLIBCALL TTLib_RemoveAppIdFromList(TTLIB_LIST nList, const WCHAR *pszAppId)
{
if(!g_bInitialized || !ExplorerIsInjected())
return FALSE;
SIZE_T nAppIdLength = lstrlen(pszAppId);
if(nAppIdLength + 1 > MAX_APPID_LENGTH)
return FALSE;
REQUEST_REMOVE_APP_ID_FROM_LIST *pRequest = g_pRequestMappingView;
pRequest->nList = nList;
CopyMemory(pRequest->szAppId, pszAppId, (nAppIdLength + 1) * sizeof(WCHAR));
if(!SendExecAPIMessage(API_REMOVE_APP_ID_FROM_LIST))
return FALSE;
return TRUE;
}
BOOL TTLIBCALL TTLib_GetAppIdListValue(TTLIB_LIST nList, const WCHAR *pszAppId, TTLIB_LIST_VALUE *pnListValue)
{
if(!g_bInitialized || !ExplorerIsInjected())
return FALSE;
SIZE_T nAppIdLength = lstrlen(pszAppId);
if(nAppIdLength + 1 > MAX_APPID_LENGTH)
return FALSE;
REQUEST_GET_APP_ID_LIST_VALUE *pRequest = g_pRequestMappingView;
pRequest->nList = nList;
CopyMemory(pRequest->szAppId, pszAppId, (nAppIdLength + 1) * sizeof(WCHAR));
if(!SendExecAPIMessage(API_GET_APP_ID_LIST_VALUE))
return FALSE;
RESPONSE_GET_APP_ID_LIST_VALUE *pResponse = g_pResponseMappingView;
*pnListValue = pResponse->nListValue;
return TRUE;
}
//////////////////////////////////////////////////////////////////////////
static BOOL ManipulationExecAPIMessage(int nApiId)
{
REQUEST_API_HEADER *pRequest = g_pRequestMappingView;
pRequest->nApiId = nApiId;
if(!SetEvent(g_hManipulationRequestEvent))
return FALSE;
if(WaitForSingleObject(g_hManipulationResponseEvent, INFINITE) != WAIT_OBJECT_0)
return FALSE;
RESPONSE_API_HEADER *pResponse = g_pResponseMappingView;
return pResponse->bSucceeded;
}
static BOOL SendExecAPIMessage(int nApiId)
{
HWND hTaskbarWnd = ExplorerGetTaskbarWnd();
if(!hTaskbarWnd)
return FALSE;
if(!SendMessage(hTaskbarWnd, g_uCustomMsg, nApiId, MSG_DLL_EXEC_API))
return FALSE;
return TRUE;
}
#pragma once
#include "TTLib.h"
#define REQUEST_MAPPING_SIZE 1024
#define RESPONSE_MAPPING_SIZE 1024
enum
{
API_GET_MAIN_TASKBAR,
API_GET_SECONDARY_TASKBAR_COUNT,
API_GET_SECONDARY_TASKBAR,
API_GET_TASK_LIST_WINDOW,
API_GET_TASKBAR_WINDOW,
API_GET_TASKBAR_MONITOR,
API_GET_BUTTON_GROUP_COUNT,
API_GET_BUTTON_GROUP,
API_GET_ACTIVE_BUTTON_GROUP,
API_GET_TRACKED_BUTTON_GROUP,
API_BUTTON_GROUP_MOVE,
API_GET_BUTTON_GROUP_TASKBAR,
API_GET_BUTTON_GROUP_RECT,
API_GET_BUTTON_GROUP_TYPE,
API_GET_BUTTON_GROUP_APP_ID,
API_GET_BUTTON_COUNT,
API_GET_BUTTON,
API_GET_ACTIVE_BUTTON,
API_GET_TRACKED_BUTTON,
API_BUTTON_MOVE_IN_BUTTON_GROUP,
API_GET_BUTTON_WINDOW,
API_ADD_APP_ID_TO_LIST,
API_REMOVE_APP_ID_FROM_LIST,
API_GET_APP_ID_LIST_VALUE,
};
//////////////////////////////////////////////////////////////////////////
typedef struct {
HANDLE hManipulationRequestEvent;
HANDLE hManipulationResponseEvent;
HANDLE hManipulationDoneEvent;
} REQUEST_MANIPULATION_START;
typedef struct {
int nApiId;
} REQUEST_API_HEADER;
typedef struct {
BOOL bSucceeded;
} RESPONSE_API_HEADER;
// API_GET_MAIN_TASKBAR
//typedef struct {
// REQUEST_API_HEADER header;
//} REQUEST_GET_MAIN_TASKBAR;
typedef struct {
RESPONSE_API_HEADER header;
HANDLE hTaskbar;
} RESPONSE_GET_MAIN_TASKBAR;
// API_GET_SECONDARY_TASKBAR_COUNT
//typedef struct {
// REQUEST_API_HEADER header;
//} REQUEST_GET_SECONDARY_TASKBAR_COUNT;
typedef struct {
RESPONSE_API_HEADER header;
int nCount;
} RESPONSE_GET_SECONDARY_TASKBAR_COUNT;
// API_GET_SECONDARY_TASKBAR
typedef struct {
REQUEST_API_HEADER header;
int nIndex;
} REQUEST_GET_SECONDARY_TASKBAR;
typedef struct {
RESPONSE_API_HEADER header;
HANDLE hTaskbar;
} RESPONSE_GET_SECONDARY_TASKBAR;
// API_GET_TASK_LIST_WINDOW
typedef struct {
REQUEST_API_HEADER header;
HANDLE hTaskbar;
} REQUEST_GET_TASK_LIST_WINDOW;
typedef struct {
RESPONSE_API_HEADER header;
HWND hWnd;
} RESPONSE_GET_TASK_LIST_WINDOW;
// API_GET_TASKBAR_WINDOW
typedef struct {
REQUEST_API_HEADER header;
HANDLE hTaskbar;
} REQUEST_GET_TASKBAR_WINDOW;
typedef struct {
RESPONSE_API_HEADER header;
HWND hWnd;
} RESPONSE_GET_TASKBAR_WINDOW;
// API_GET_TASKBAR_MONITOR
typedef struct {
REQUEST_API_HEADER header;
HANDLE hTaskbar;
} REQUEST_GET_TASKBAR_MONITOR;
typedef struct {
RESPONSE_API_HEADER header;
HMONITOR hMonitor;
} RESPONSE_GET_TASKBAR_MONITOR;
//////////////////////////////////////////////////////////////////////////
// API_GET_BUTTON_GROUP_COUNT
typedef struct {
REQUEST_API_HEADER header;
HANDLE hTaskbar;
} REQUEST_GET_BUTTON_GROUP_COUNT;
typedef struct {
RESPONSE_API_HEADER header;
int nCount;
} RESPONSE_GET_BUTTON_GROUP_COUNT;
// API_GET_BUTTON_GROUP
typedef struct {
REQUEST_API_HEADER header;
HANDLE hTaskbar;
int nIndex;
} REQUEST_GET_BUTTON_GROUP;
typedef struct {
RESPONSE_API_HEADER header;
HANDLE hButtonGroup;
} RESPONSE_GET_BUTTON_GROUP;
// API_GET_ACTIVE_BUTTON_GROUP
typedef struct {
REQUEST_API_HEADER header;
HANDLE hTaskbar;
} REQUEST_GET_ACTIVE_BUTTON_GROUP;
typedef struct {
RESPONSE_API_HEADER header;
HANDLE hButtonGroup;
} RESPONSE_GET_ACTIVE_BUTTON_GROUP;
// API_GET_TRACKED_BUTTON_GROUP
typedef struct {
REQUEST_API_HEADER header;
HANDLE hTaskbar;
} REQUEST_GET_TRACKED_BUTTON_GROUP;
typedef struct {
RESPONSE_API_HEADER header;
HANDLE hButtonGroup;
} RESPONSE_GET_TRACKED_BUTTON_GROUP;
// API_BUTTON_GROUP_MOVE
typedef struct {
REQUEST_API_HEADER header;
HANDLE hTaskbar;
int nIndexFrom;
int nIndexTo;
} REQUEST_BUTTON_GROUP_MOVE;
//typedef struct {
// RESPONSE_API_HEADER header;
//} RESPONSE_BUTTON_GROUP_MOVE;
// API_GET_BUTTON_GROUP_TASKBAR
typedef struct {
REQUEST_API_HEADER header;
HANDLE hButtonGroup;
} REQUEST_GET_BUTTON_GROUP_TASKBAR;
typedef struct {
RESPONSE_API_HEADER header;
HANDLE hTaskbar;
} RESPONSE_GET_BUTTON_GROUP_TASKBAR;
// API_GET_BUTTON_GROUP_RECT
typedef struct {
REQUEST_API_HEADER header;
HANDLE hButtonGroup;
} REQUEST_GET_BUTTON_GROUP_RECT;
typedef struct {
RESPONSE_API_HEADER header;
RECT rc;
} RESPONSE_GET_BUTTON_GROUP_RECT;
// API_GET_BUTTON_GROUP_TYPE
typedef struct {
REQUEST_API_HEADER header;
HANDLE hButtonGroup;
} REQUEST_GET_BUTTON_GROUP_TYPE;
typedef struct {
RESPONSE_API_HEADER header;
TTLIB_GROUPTYPE nType;
} RESPONSE_GET_BUTTON_GROUP_TYPE;
// API_GET_BUTTON_GROUP_APP_ID
typedef struct {
REQUEST_API_HEADER header;
HANDLE hButtonGroup;
SIZE_T nMaxSize;
} REQUEST_GET_BUTTON_GROUP_APP_ID;
typedef struct {
RESPONSE_API_HEADER header;
SIZE_T nResultSize;
WCHAR szAppId[MAX_APPID_LENGTH];
} RESPONSE_GET_BUTTON_GROUP_APP_ID;
//////////////////////////////////////////////////////////////////////////
// API_GET_BUTTON_COUNT
typedef struct {
REQUEST_API_HEADER header;
HANDLE hButtonGroup;
} REQUEST_GET_BUTTON_COUNT;
typedef struct {
RESPONSE_API_HEADER header;
int nCount;
} RESPONSE_GET_BUTTON_COUNT;
// API_GET_BUTTON
typedef struct {
REQUEST_API_HEADER header;
HANDLE hButtonGroup;
int nIndex;
} REQUEST_GET_BUTTON;
typedef struct {
RESPONSE_API_HEADER header;
HANDLE hButton;
} RESPONSE_GET_BUTTON;
// API_GET_ACTIVE_BUTTON
typedef struct {
REQUEST_API_HEADER header;
HANDLE hTaskbar;
} REQUEST_GET_ACTIVE_BUTTON;
typedef struct {
RESPONSE_API_HEADER header;
HANDLE hButton;
} RESPONSE_GET_ACTIVE_BUTTON;
// API_GET_TRACKED_BUTTON
typedef struct {
REQUEST_API_HEADER header;
HANDLE hTaskbar;
} REQUEST_GET_TRACKED_BUTTON;
typedef struct {
RESPONSE_API_HEADER header;
HANDLE hButton;
} RESPONSE_GET_TRACKED_BUTTON;
// API_BUTTON_MOVE_IN_BUTTON_GROUP
typedef struct {
REQUEST_API_HEADER header;
HANDLE hButtonGroup;
int nIndexFrom;
int nIndexTo;
} REQUEST_BUTTON_MOVE_IN_BUTTON_GROUP;
//typedef struct {
// RESPONSE_API_HEADER header;
//} RESPONSE_BUTTON_MOVE_IN_BUTTON_GROUP;
// API_GET_BUTTON_WINDOW
typedef struct {
REQUEST_API_HEADER header;
HANDLE hButton;
} REQUEST_GET_BUTTON_WINDOW;
typedef struct {
RESPONSE_API_HEADER header;
HWND hWnd;
} RESPONSE_GET_BUTTON_WINDOW;
//////////////////////////////////////////////////////////////////////////
// API_ADD_APP_ID_TO_LIST
typedef struct {
TTLIB_LIST nList;
WCHAR szAppId[MAX_APPID_LENGTH];
TTLIB_LIST_VALUE nListValue;
} REQUEST_ADD_APP_ID_TO_LIST;
// API_REMOVE_APP_ID_FROM_LIST
typedef struct {
TTLIB_LIST nList;
WCHAR szAppId[MAX_APPID_LENGTH];
} REQUEST_REMOVE_APP_ID_FROM_LIST;
// API_GET_APP_ID_LIST_VALUE
typedef struct {
TTLIB_LIST nList;
WCHAR szAppId[MAX_APPID_LENGTH];
} REQUEST_GET_APP_ID_LIST_VALUE;
typedef struct {
TTLIB_LIST_VALUE nListValue;
} RESPONSE_GET_APP_ID_LIST_VALUE;
#include "stdafx.h"
#include "TTLibAPIHandler.h"
#include "functions.h"
#include "appid_lists.h"
#include "taskbar_refresh.h"
#include "explorer_vars.h"
// superglobals
extern HANDLE hTweakerProcess;
extern HANDLE hCleanEvent;
extern HWND hTaskbarWnd, hTaskSwWnd, hTaskListWnd, hThumbnailWnd;
extern LONG_PTR lpTaskbarLongPtr, lpTaskSwLongPtr, lpTaskListLongPtr, lpThumbnailLongPtr;
extern HANDLE g_hRequestMapping;
extern void *g_pRequestMappingView;
extern HANDLE g_hResponseMapping;
extern void *g_pResponseMappingView;
extern UINT g_uCustomMsg;
static BOOL GetMainTaskbar();
static BOOL GetSecondaryTaskbarCount();
static BOOL GetSecondaryTaskbar();
static BOOL GetTaskListWindow();
static BOOL GetTaskbarWindow();
static BOOL GetTaskbarMonitor();
static BOOL GetButtonGroupCount();
static BOOL GetButtonGroup();
static BOOL GetActiveButtonGroup();
static BOOL GetTrackedButtonGroup();
static BOOL ButtonGroupMove();
static BOOL GetButtonGroupTaskbar();
static BOOL GetButtonGroupRect();
static BOOL GetButtonGroupType();
static BOOL GetButtonGroupAppId();
static BOOL GetButtonCount();
static BOOL GetButton();
static BOOL GetActiveButton();
static BOOL GetTrackedButton();
static BOOL ButtonMoveInButtonGroup();
static BOOL GetButtonWindow();
static BOOL AddAppIdToList();
static BOOL RemoveAppIdFromList();
static BOOL GetAppIdListValue();
static void OnAppIdListUpdated(TTLIB_LIST nList);
void GetManipulationStartRequest(REQUEST_MANIPULATION_START *pOutRequest)
{
REQUEST_MANIPULATION_START *pRequest = g_pRequestMappingView;
*pOutRequest = *pRequest;
}
void DoManipulation(const REQUEST_MANIPULATION_START *pManipulationRequest)
{
HANDLE hHandles[4];
hHandles[0] = pManipulationRequest->hManipulationRequestEvent;
hHandles[1] = pManipulationRequest->hManipulationDoneEvent;
hHandles[2] = hTweakerProcess;
hHandles[3] = hCleanEvent;
for(;;)
{
DWORD dwWaitResult = WaitForMultipleObjects(_countof(hHandles), hHandles, FALSE, INFINITE);
if(dwWaitResult == WAIT_FAILED)
break;
if(dwWaitResult == WAIT_OBJECT_0)
{
REQUEST_API_HEADER *pRequest = g_pRequestMappingView;
RESPONSE_API_HEADER *pResponse = g_pResponseMappingView;
pResponse->bSucceeded = ExecAPI(pRequest->nApiId);
SetEvent(pManipulationRequest->hManipulationResponseEvent);
}
else if(dwWaitResult >= WAIT_OBJECT_0 + 1 && dwWaitResult < WAIT_OBJECT_0 + _countof(hHandles))
break;
}
CloseHandle(pManipulationRequest->hManipulationRequestEvent);
CloseHandle(pManipulationRequest->hManipulationResponseEvent);
CloseHandle(pManipulationRequest->hManipulationDoneEvent);
}
BOOL ExecAPI(int nApiId)
{
switch(nApiId)
{
case API_GET_MAIN_TASKBAR: return GetMainTaskbar();
case API_GET_SECONDARY_TASKBAR_COUNT: return GetSecondaryTaskbarCount();
case API_GET_SECONDARY_TASKBAR: return GetSecondaryTaskbar();
case API_GET_TASK_LIST_WINDOW: return GetTaskListWindow();
case API_GET_TASKBAR_WINDOW: return GetTaskbarWindow();
case API_GET_TASKBAR_MONITOR: return GetTaskbarMonitor();
case API_GET_BUTTON_GROUP_COUNT: return GetButtonGroupCount();
case API_GET_BUTTON_GROUP: return GetButtonGroup();
case API_GET_ACTIVE_BUTTON_GROUP: return GetActiveButtonGroup();
case API_GET_TRACKED_BUTTON_GROUP: return GetTrackedButtonGroup();
case API_BUTTON_GROUP_MOVE: return ButtonGroupMove();
case API_GET_BUTTON_GROUP_TASKBAR: return GetButtonGroupTaskbar();
case API_GET_BUTTON_GROUP_RECT: return GetButtonGroupRect();
case API_GET_BUTTON_GROUP_TYPE: return GetButtonGroupType();
case API_GET_BUTTON_GROUP_APP_ID: return GetButtonGroupAppId();
case API_GET_BUTTON_COUNT: return GetButtonCount();
case API_GET_BUTTON: return GetButton();
case API_GET_ACTIVE_BUTTON: return GetActiveButton();
case API_GET_TRACKED_BUTTON: return GetTrackedButton();
case API_BUTTON_MOVE_IN_BUTTON_GROUP: return ButtonMoveInButtonGroup();
case API_GET_BUTTON_WINDOW: return GetButtonWindow();
case API_ADD_APP_ID_TO_LIST: return AddAppIdToList();
case API_REMOVE_APP_ID_FROM_LIST: return RemoveAppIdFromList();
case API_GET_APP_ID_LIST_VALUE: return GetAppIdListValue();
}
return FALSE;
}
//////////////////////////////////////////////////////////////////////////
static BOOL GetMainTaskbar()
{
HANDLE hTaskbar = (HANDLE)lpTaskListLongPtr;
RESPONSE_GET_MAIN_TASKBAR *pResponse = g_pResponseMappingView;
pResponse->hTaskbar = hTaskbar;
return TRUE;
}
static BOOL GetSecondaryTaskbarCount()
{
RESPONSE_GET_SECONDARY_TASKBAR_COUNT *pResponse = g_pResponseMappingView;
pResponse->nCount = GetSecondaryTaskListCount();
return TRUE;
}
static BOOL GetSecondaryTaskbar()
{
REQUEST_GET_SECONDARY_TASKBAR *pRequest = g_pRequestMappingView;
int nIndex = pRequest->nIndex;
SECONDARY_TASK_LIST_GET secondary_task_list_get;
LONG_PTR lpSecondaryTaskListLongPtr = SecondaryTaskListGetFirstLongPtr(&secondary_task_list_get);
for(int i = 0; lpSecondaryTaskListLongPtr && i < nIndex; i++)
{
lpSecondaryTaskListLongPtr = SecondaryTaskListGetNextLongPtr(&secondary_task_list_get);
}
HANDLE hTaskbar = (HANDLE)lpSecondaryTaskListLongPtr;
RESPONSE_GET_SECONDARY_TASKBAR *pResponse = g_pResponseMappingView;
pResponse->hTaskbar = hTaskbar;
return TRUE;
}
static BOOL GetTaskListWindow()
{
REQUEST_GET_TASK_LIST_WINDOW *pRequest = g_pRequestMappingView;
HANDLE hTaskbar = pRequest->hTaskbar;
HWND hMMTaskListWnd;
LONG_PTR lpMMTaskListLongPtr = (LONG_PTR)hTaskbar;
hMMTaskListWnd = *EV_MM_TASKLIST_HWND(lpMMTaskListLongPtr);
RESPONSE_GET_TASK_LIST_WINDOW *pResponse = g_pResponseMappingView;
pResponse->hWnd = hMMTaskListWnd;
return TRUE;
}
static BOOL GetTaskbarWindow()
{
REQUEST_GET_TASKBAR_WINDOW *pRequest = g_pRequestMappingView;
HANDLE hTaskbar = pRequest->hTaskbar;
HWND hMMTaskbarWnd;
LONG_PTR lpMMTaskListLongPtr = (LONG_PTR)hTaskbar;
if(lpMMTaskListLongPtr != lpTaskListLongPtr)
{
LONG_PTR lpSecondaryTaskBandLongPtr = EV_MM_TASKLIST_SECONDARY_TASK_BAND_LONG_PTR_VALUE(lpMMTaskListLongPtr);
LONG_PTR lpSecondaryTaskbarLongPtr = EV_SECONDARY_TASK_BAND_SECONDARY_TASKBAR_LONG_PTR_VALUE(lpSecondaryTaskBandLongPtr);
hMMTaskbarWnd = *EV_SECONDARY_TASKBAR_HWND(lpSecondaryTaskbarLongPtr);
}
else
hMMTaskbarWnd = hTaskbarWnd;
RESPONSE_GET_TASKBAR_WINDOW *pResponse = g_pResponseMappingView;
pResponse->hWnd = hMMTaskbarWnd;
return TRUE;
}
static BOOL GetTaskbarMonitor()
{
REQUEST_GET_TASKBAR_MONITOR *pRequest = g_pRequestMappingView;
HANDLE hTaskbar = pRequest->hTaskbar;
HMONITOR hMonitor;
LONG_PTR lpMMTaskListLongPtr = (LONG_PTR)hTaskbar;
if(lpMMTaskListLongPtr != lpTaskListLongPtr)
{
LONG_PTR lpSecondaryTaskBandLongPtr = EV_MM_TASKLIST_SECONDARY_TASK_BAND_LONG_PTR_VALUE(lpMMTaskListLongPtr);
LONG_PTR lpSecondaryTaskbarLongPtr = EV_SECONDARY_TASK_BAND_SECONDARY_TASKBAR_LONG_PTR_VALUE(lpSecondaryTaskBandLongPtr);
hMonitor = *EV_SECONDARY_TASKBAR_MONITOR(lpSecondaryTaskbarLongPtr);
}
else
{
POINT pt;
pt.x = 0;
pt.y = 0;
hMonitor = MonitorFromPoint(pt, MONITOR_DEFAULTTOPRIMARY);
}
RESPONSE_GET_TASKBAR_MONITOR *pResponse = g_pResponseMappingView;
pResponse->hMonitor = hMonitor;
return TRUE;
}
//////////////////////////////////////////////////////////////////////////
static BOOL GetButtonGroupCount()
{
REQUEST_GET_BUTTON_GROUP_COUNT *pRequest = g_pRequestMappingView;
HANDLE hTaskbar = pRequest->hTaskbar;
LONG_PTR lpMMTaskListLongPtr = (LONG_PTR)hTaskbar;
int nCount = 0;
LONG_PTR *plp = (LONG_PTR *)*EV_MM_TASKLIST_BUTTON_GROUPS_HDPA(lpMMTaskListLongPtr);
if(plp)
{
nCount = (int)plp[0];
}
RESPONSE_GET_BUTTON_GROUP_COUNT *pResponse = g_pResponseMappingView;
pResponse->nCount = nCount;
return TRUE;
}
static BOOL GetButtonGroup()
{
REQUEST_GET_BUTTON_GROUP *pRequest = g_pRequestMappingView;
HANDLE hTaskbar = pRequest->hTaskbar;
int nIndex = pRequest->nIndex;
LONG_PTR lpMMTaskListLongPtr = (LONG_PTR)hTaskbar;
LONG_PTR *plp = (LONG_PTR *)*EV_MM_TASKLIST_BUTTON_GROUPS_HDPA(lpMMTaskListLongPtr);
if(!plp)
return FALSE;
int button_groups_count = (int)plp[0];
if(nIndex >= button_groups_count)
return FALSE;
LONG_PTR **button_groups = (LONG_PTR **)plp[1];
HANDLE hButtonGroup = (HANDLE)button_groups[nIndex];
RESPONSE_GET_BUTTON_GROUP *pResponse = g_pResponseMappingView;
pResponse->hButtonGroup = hButtonGroup;
return TRUE;
}
static BOOL GetActiveButtonGroup()
{
REQUEST_GET_ACTIVE_BUTTON_GROUP *pRequest = g_pRequestMappingView;
HANDLE hTaskbar = pRequest->hTaskbar;
LONG_PTR lpMMTaskListLongPtr = (LONG_PTR)hTaskbar;
LONG_PTR *button_group = TaskbarGetActiveButtonGroup(lpMMTaskListLongPtr);
HANDLE hButtonGroup = (HANDLE)button_group;
RESPONSE_GET_ACTIVE_BUTTON_GROUP *pResponse = g_pResponseMappingView;
pResponse->hButtonGroup = hButtonGroup;
return TRUE;
}
static BOOL GetTrackedButtonGroup()
{
REQUEST_GET_TRACKED_BUTTON_GROUP *pRequest = g_pRequestMappingView;
HANDLE hTaskbar = pRequest->hTaskbar;
LONG_PTR lpMMTaskListLongPtr = (LONG_PTR)hTaskbar;
LONG_PTR *button_group = TaskbarGetTrackedButtonGroup(lpMMTaskListLongPtr);
HANDLE hButtonGroup = (HANDLE)button_group;
RESPONSE_GET_TRACKED_BUTTON_GROUP *pResponse = g_pResponseMappingView;
pResponse->hButtonGroup = hButtonGroup;
return TRUE;
}
static BOOL ButtonGroupMove()
{
REQUEST_BUTTON_GROUP_MOVE *pRequest = g_pRequestMappingView;
HANDLE hTaskbar = pRequest->hTaskbar;
int nIndexFrom = pRequest->nIndexFrom;
int nIndexTo = pRequest->nIndexTo;
LONG_PTR lpMMTaskListLongPtr = (LONG_PTR)hTaskbar;
return TaskbarMoveGroup(lpMMTaskListLongPtr, nIndexFrom, nIndexTo);
}
static BOOL GetButtonGroupTaskbar()
{
REQUEST_GET_BUTTON_GROUP_TASKBAR *pRequest = g_pRequestMappingView;
HANDLE hButtonGroup = pRequest->hButtonGroup;
LONG_PTR *button_group = (LONG_PTR *)hButtonGroup;
LONG_PTR lpMMTaskListLongPtr;
// multimonitor environment
if(nWinVersion >= WIN_VERSION_8)
lpMMTaskListLongPtr = button_group[3];
else
lpMMTaskListLongPtr = lpTaskListLongPtr;
HANDLE hTaskbar = (HANDLE)lpMMTaskListLongPtr;
RESPONSE_GET_BUTTON_GROUP_TASKBAR *pResponse = g_pResponseMappingView;
pResponse->hTaskbar = hTaskbar;
return TRUE;
}
static BOOL GetButtonGroupRect()
{
REQUEST_GET_BUTTON_GROUP_RECT *pRequest = g_pRequestMappingView;
HANDLE hButtonGroup = pRequest->hButtonGroup;
LONG_PTR *button_group = (LONG_PTR *)hButtonGroup;
RECT rc = **(RECT **)(button_group[DO2(4, 6)] + sizeof(LONG_PTR));
RESPONSE_GET_BUTTON_GROUP_RECT *pResponse = g_pResponseMappingView;
pResponse->rc = rc;
return TRUE;
}
static BOOL GetButtonGroupType()
{
REQUEST_GET_BUTTON_GROUP_TYPE *pRequest = g_pRequestMappingView;
HANDLE hButtonGroup = pRequest->hButtonGroup;
LONG_PTR *button_group = (LONG_PTR *)hButtonGroup;
int button_group_type = (int)button_group[DO2(6, 8)];
TTLIB_GROUPTYPE nType = button_group_type;
RESPONSE_GET_BUTTON_GROUP_TYPE *pResponse = g_pResponseMappingView;
pResponse->nType = nType;
return TRUE;
}
static BOOL GetButtonGroupAppId()
{
REQUEST_GET_BUTTON_GROUP_APP_ID *pRequest = g_pRequestMappingView;
HANDLE hButtonGroup = pRequest->hButtonGroup;
SIZE_T nMaxSize = pRequest->nMaxSize;
LONG_PTR *button_group = (LONG_PTR *)hButtonGroup;
WCHAR *pAppId = *EV_TASKGROUP_APPID(button_group[DO2(3, 4)]);
SIZE_T nResultSize = lstrlen(pAppId) + 1;
if(nResultSize > nMaxSize)
return FALSE;
RESPONSE_GET_BUTTON_GROUP_APP_ID *pResponse = g_pResponseMappingView;
if(nResultSize * sizeof(WCHAR) > sizeof(pResponse->szAppId))
return FALSE;
pResponse->nResultSize = nResultSize;
CopyMemory(pResponse->szAppId, pAppId, nResultSize * sizeof(WCHAR));
return TRUE;
}
//////////////////////////////////////////////////////////////////////////
static BOOL GetButtonCount()
{
REQUEST_GET_BUTTON_COUNT *pRequest = g_pRequestMappingView;
HANDLE hButtonGroup = pRequest->hButtonGroup;
int nCount = 0;
LONG_PTR *button_group = (LONG_PTR *)hButtonGroup;
int button_group_type = (int)button_group[DO2(6, 8)];
if(button_group_type == 1 || button_group_type == 3)
{
LONG_PTR *plp = (LONG_PTR *)button_group[DO2(5, 7)];
if(plp)
{
nCount = (int)plp[0];
}
}
RESPONSE_GET_BUTTON_COUNT *pResponse = g_pResponseMappingView;
pResponse->nCount = nCount;
return TRUE;
}
static BOOL GetButton()
{
REQUEST_GET_BUTTON *pRequest = g_pRequestMappingView;
HANDLE hButtonGroup = pRequest->hButtonGroup;
int nIndex = pRequest->nIndex;
LONG_PTR *button_group = (LONG_PTR *)hButtonGroup;
int button_group_type = (int)button_group[DO2(6, 8)];
if(button_group_type != 1 && button_group_type != 3)
return FALSE;
LONG_PTR *plp = (LONG_PTR *)button_group[DO2(5, 7)];
if(!plp)
return FALSE;
int buttons_count = (int)plp[0];
if(nIndex >= buttons_count)
return FALSE;
LONG_PTR **buttons = (LONG_PTR **)plp[1];
HANDLE hButton = (HANDLE)buttons[nIndex];
RESPONSE_GET_BUTTON *pResponse = g_pResponseMappingView;
pResponse->hButton = hButton;
return TRUE;
}
static BOOL GetActiveButton()
{
REQUEST_GET_ACTIVE_BUTTON *pRequest = g_pRequestMappingView;
HANDLE hTaskbar = pRequest->hTaskbar;
LONG_PTR lpMMTaskListLongPtr = (LONG_PTR)hTaskbar;
LONG_PTR *button = TaskbarGetActiveButton(lpMMTaskListLongPtr);
HANDLE hButton= (HANDLE)button;
RESPONSE_GET_ACTIVE_BUTTON *pResponse = g_pResponseMappingView;
pResponse->hButton = hButton;
return TRUE;
}
static BOOL GetTrackedButton()
{
REQUEST_GET_TRACKED_BUTTON *pRequest = g_pRequestMappingView;
HANDLE hTaskbar = pRequest->hTaskbar;
LONG_PTR lpMMTaskListLongPtr = (LONG_PTR)hTaskbar;
LONG_PTR *button = TaskbarGetTrackedButton(lpMMTaskListLongPtr);
HANDLE hButton = (HANDLE)button;
RESPONSE_GET_TRACKED_BUTTON *pResponse = g_pResponseMappingView;
pResponse->hButton = hButton;
return TRUE;
}
static BOOL ButtonMoveInButtonGroup()
{
REQUEST_BUTTON_MOVE_IN_BUTTON_GROUP *pRequest = g_pRequestMappingView;
HANDLE hButtonGroup = pRequest->hButtonGroup;
int nIndexFrom = pRequest->nIndexFrom;
int nIndexTo = pRequest->nIndexTo;
LONG_PTR *button_group = (LONG_PTR *)hButtonGroup;
MOVE_BUTTON_IN_GROUP move_button;
move_button.button_group = button_group;
move_button.index_from = nIndexFrom;
move_button.index_to = nIndexTo;
return TaskbarMoveButtonInGroup(&move_button);
}
static BOOL GetButtonWindow()
{
REQUEST_GET_BUTTON_WINDOW *pRequest = g_pRequestMappingView;
HANDLE hButton = pRequest->hButton;
LONG_PTR *button = (LONG_PTR *)hButton;
LONG_PTR *task_item = (LONG_PTR *)button[DO2(3, 4)];
HWND hWnd = GetTaskItemWnd(task_item);
RESPONSE_GET_BUTTON_WINDOW *pResponse = g_pResponseMappingView;
pResponse->hWnd = hWnd;
return TRUE;
}
//////////////////////////////////////////////////////////////////////////
static BOOL AddAppIdToList()
{
REQUEST_ADD_APP_ID_TO_LIST *pRequest = g_pRequestMappingView;
TTLIB_LIST nList = pRequest->nList;
TTLIB_LIST_VALUE nListValue = pRequest->nListValue;
WCHAR szAppId[MAX_APPID_LENGTH];
lstrcpy(szAppId, pRequest->szAppId);
if(!AddAppidToList(nList, szAppId, nListValue))
return FALSE;
OnAppIdListUpdated(nList);
return TRUE;
}
static BOOL RemoveAppIdFromList()
{
REQUEST_REMOVE_APP_ID_FROM_LIST *pRequest = g_pRequestMappingView;
TTLIB_LIST nList = pRequest->nList;
WCHAR szAppId[MAX_APPID_LENGTH];
lstrcpy(szAppId, pRequest->szAppId);
if(!RemoveAppidFromList(nList, szAppId))
return FALSE;
OnAppIdListUpdated(nList);
return TRUE;
}
static BOOL GetAppIdListValue()
{
REQUEST_GET_APP_ID_LIST_VALUE *pRequest = g_pRequestMappingView;
TTLIB_LIST nList = pRequest->nList;
WCHAR szAppId[MAX_APPID_LENGTH];
lstrcpy(szAppId, pRequest->szAppId);
int nListValue;
if(!GetAppidListValue(nList, szAppId, &nListValue))
return FALSE;
RESPONSE_GET_APP_ID_LIST_VALUE *pResponse = g_pResponseMappingView;
pResponse->nListValue = nListValue;
return TRUE;
}
static void OnAppIdListUpdated(TTLIB_LIST nList)
{
switch(nList)
{
case TTLIB_LIST_LABEL:
MMTaskListRecomputeLayout();
break;
case TTLIB_LIST_GROUP:
case TTLIB_LIST_GROUPPINNED:
case TTLIB_LIST_COMBINE:
RefreshTaskbarHardcore();
break;
}
}
#pragma once
#include "TTLibAPI.h"
void GetManipulationStartRequest(REQUEST_MANIPULATION_START *pOutRequest);
void DoManipulation(const REQUEST_MANIPULATION_START *pManipulationRequest);
BOOL ExecAPI(int nApiId);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment