Skip to content

Instantly share code, notes, and snippets.

@RyuaNerin
Last active August 12, 2016 18:21
Show Gist options
  • Save RyuaNerin/0b929b3f937ab5ce0ee5aa6e72a7e347 to your computer and use it in GitHub Desktop.
Save RyuaNerin/0b929b3f937ab5ce0ee5aa6e72a7e347 to your computer and use it in GitHub Desktop.
팟플레이어 최상위 고정
#include <Windows.h>
static HWND hPotPlayer;
void CALLBACK WinEventProc(HWINEVENTHOOK hWinEventHook, DWORD event, HWND hwnd, LONG idObject, LONG idChild, DWORD idEventThread, DWORD dwmsEventTime)
{
if (idObject != 0 || idChild != 0 || hwnd == hPotPlayer)
return;
SetWindowPos(hPotPlayer, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE);
}
int main(void)
{
MSG msg;
DWORD pid;
HANDLE hProc;
HWINEVENTHOOK hHook;
if (!ShowWindow(GetConsoleWindow(), 0))
return 0;
hPotPlayer = FindWindowW(L"PotPlayer", NULL);
if (hPotPlayer == NULL)
return 0;
if (GetWindowThreadProcessId(hPotPlayer, &pid) == 0 || pid == 0)
return 0;
hProc = OpenProcess(SYNCHRONIZE, FALSE, pid);
if (hProc == 0)
return 0;
hHook = SetWinEventHook(EVENT_SYSTEM_FOREGROUND, EVENT_SYSTEM_FOREGROUND, 0, &WinEventProc, 0, 0, WINEVENT_OUTOFCONTEXT | WINEVENT_SKIPOWNPROCESS);
if (hHook == 0)
return 0;
while (WaitForSingleObjectEx(hProc, 0, FALSE) != 0)
{
if (PeekMessage(&msg, 0, 0, 0, PM_REMOVE))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
else
Sleep(100);
}
CloseHandle(hProc);
UnhookWinEvent(hHook);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment