Что делать, если окно игры Lineage 2 открывается без фокуса. И установить фокус на окно можно лишь переключением на другое приложение и обратно. Напиши DLL, которая будет принудительно устанавливать фокус. Можешь добавить функционал в мою DLL:
#include <windows.h>
#include "Hook.h"

// Forward declarations of hook functions
void HookInitUGameEngine();
void HookInitUGameEngineImpl(DWORD hInit_UGameEngine);
void HookOnUserInfo();
void HookOnUserInfoImpl(DWORD hUI_this, DWORD hUI_user);

// Global variables
static Hook* pHookInitGameEngine = nullptr;
static wchar_t* playerName = nullptr;
static HWND pHwnd = nullptr;
static LPVOID wndProcOriginalHandler = nullptr;
static DWORD InitUGameEngine;
static DWORD OnUserInfo;
static DWORD GetName;

// Define a postfix for the player's name (empty by default)
#define NAMEPOSTFIX L""

// Empty export to ensure the DLL has at least one export
__declspec(dllexport) void EmptyExport() {
}

// Helper function to convert a string to lowercase
void ToLowerCase(char* str) {
    for (size_t i = 0; i < strlen(str); i++) {
        if (isupper(str[i])) {
            str[i] = tolower(str[i]);
        }
    }
}

// Helper function to read a boolean value from a configuration file
bool GetCfgBool(const char* section, const char* param, bool defaultValue) {
    char strValue[255];
    GetPrivateProfileStringA(section, param, defaultValue ? "true" : "false", strValue, 255, "./option.ini");
    ToLowerCase(strValue);
    return strcmp("true", strValue) == 0;
}

// Custom window procedure to intercept window messages
LRESULT CALLBACK WndProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam) {
    if (uMsg == WM_SETTEXT && playerName && lstrcmpW(reinterpret_cast<LPCWSTR>(lParam), playerName) != 0) {
        return TRUE;
    }
    return reinterpret_cast<WNDPROC>(wndProcOriginalHandler)(hwnd, uMsg, wParam, lParam);
}

// Callback function to enumerate windows
BOOL CALLBACK WndCallback(HWND hwnd, LPARAM lparam) {
    DWORD pid;
    GetWindowThreadProcessId(hwnd, &pid);
    if (pid == static_cast<DWORD>(lparam)) {
        if (!wndProcOriginalHandler) {
            wndProcOriginalHandler = reinterpret_cast<LPVOID>(GetWindowLong(hwnd, GWL_WNDPROC));
            if (!SetWindowLong(hwnd, GWL_WNDPROC, reinterpret_cast<LONG>(&WndProc))) {
                OutputDebugStringA("Failed to change window proc handler");
                ::ExitProcess(0);
            }
        }
        pHwnd = hwnd;
        if (SetWindowTextW(hwnd, playerName) == FALSE) {
            OutputDebugStringA("Failed to change window text");
        }
        return FALSE;
    }
    return TRUE;
}

// Thread to load and apply hooks
DWORD WINAPI LoadHook(LPVOID) {
    if (!GetCfgBool("Game", "ChangeWndPlayerName", true)) {
        return 0;
    }

    HMODULE engine = nullptr;
    while ((engine = GetModuleHandleA("engine.dll")) == nullptr) {
        Sleep(10);
    }

    BYTE* jmp = (BYTE*)GetProcAddress(engine, "?Init@UGameEngine@@UAEXH@Z");
    if (jmp[0] != 0xe9) {
        OutputDebugStringA("Init stub not found!");
        return 0;
    }

    DWORD nearAdr = *((DWORD*)&jmp[1]);
    InitUGameEngine = ((DWORD)jmp) + nearAdr + 5;
    pHookInitGameEngine = new Hook(L"engine.dll", "?Init@UGameEngine@@UAEXH@Z", &HookInitUGameEngine, false);
    pHookInitGameEngine->SetFlushCache(true);
    pHookInitGameEngine->Apply();

    GetName = (DWORD)GetProcAddress(engine, "?GetName@User@@QAEPAGXZ");
    if (!GetName) {
        OutputDebugStringA("GetName function not found!");
    }

    OnUserInfo = (DWORD)GetProcAddress(engine, "?OnUserInfo@UGameEngine@@UAEHPAUUser@@VFVector@@HHHDD@Z");
    if (!OnUserInfo) {
        OutputDebugStringA("OnUserInfo function not found!");
    }
    return 0;
}

// Hook function for UGameEngine::Init
DWORD hInit_UGameEngine;
void __declspec(naked) HookInitUGameEngine() {
    __asm {
        mov hInit_UGameEngine, ecx
        pushad
        push hInit_UGameEngine
        call HookInitUGameEngineImpl
        add esp, 4
        popad
        push InitUGameEngine
        retn
    }
}

// Implementation of the UGameEngine::Init hook
void HookInitUGameEngineImpl(DWORD hInit_UGameEngine) {
    DWORD** UGameEngineVMT = (DWORD**)hInit_UGameEngine;
    UGameEngineVMT = (DWORD**)UGameEngineVMT[0];
    OnUserInfo = (DWORD)UGameEngineVMT[73];

    DWORD prevProt;
    VirtualProtect(&UGameEngineVMT[73], sizeof(DWORD*), PAGE_EXECUTE_READWRITE, &prevProt);
    UGameEngineVMT[73] = (DWORD*)HookOnUserInfo;
    VirtualProtect(&UGameEngineVMT[73], sizeof(DWORD*), prevProt, &prevProt);
}

// Hook function for UGameEngine::OnUserInfo
DWORD hUI_ret;
DWORD hUI_this;
DWORD hUI_user;
void __declspec(naked) HookOnUserInfo() {
    __asm {
        mov hUI_this, ecx
        mov eax, [esp + 4]
        mov hUI_user, eax

        pushad
        push hUI_user
        push hUI_this
        call HookOnUserInfoImpl
        add esp, 8      
        popad

        jmp OnUserInfo
    }
}

// Implementation of the UGameEngine::OnUserInfo hook
wchar_t* hUI_nickname;
void HookOnUserInfoImpl(DWORD hUI_this, DWORD hUI_user) {
    __asm {
        mov ecx, hUI_user
        call GetName
        mov hUI_nickname, eax
    }

    if (playerName) {
        delete[] playerName;
    }

    playerName = new wchar_t[lstrlenW(hUI_nickname) + lstrlenW(NAMEPOSTFIX) + 1];
    wsprintf(playerName, L"%s%s", hUI_nickname, NAMEPOSTFIX);

    EnumWindows(&WndCallback, GetCurrentProcessId());
}

// DLL entry point
BOOL APIENTRY DllMain(HMODULE hModule, DWORD ul_reason_for_call, LPVOID lpReserved) {
    switch (ul_reason_for_call) {
    case DLL_PROCESS_ATTACH:
        CreateThread(nullptr, 0, &LoadHook, nullptr, 0, nullptr);
        break;
    case DLL_PROCESS_DETACH:
        if (wndProcOriginalHandler) {
            SetWindowLong(pHwnd, GWL_WNDPROC, reinterpret_cast<LONG>(wndProcOriginalHandler));
        }
        if (playerName) {
            delete[] playerName;
        }
        if (pHookInitGameEngine) {
            pHookInitGameEngine->Cancel();
            delete pHookInitGameEngine;
        }
        break;
    }
    return TRUE;
}