1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
| #include <windows.h>
#include <TlHelp32.h>
#include <Shlwapi.h>
#include <Psapi.h>
LRESULT CALLBACK msgBoxHook(int nCode, WPARAM wParam, LPARAM lParam) {
LRESULT CALLBACK msgBoxHook(int, WPARAM, LPARAM); // j'ai un sérieux doute sur cette ligne :P :P :P
DWORD WINAPI messageBoxThread(LPVOID); // et sur celle-ci aussi
/* Elles ressemblent beaucoup plus à la déclaration de fonctions
* qu'à leur appel
*/
if (nCode == HCBT_CREATEWND) {
CREATESTRUCT *pcs = ((CBT_CREATEWND *)lParam)->lpcs;
if ((pcs->style & WS_DLGFRAME) || (pcs->style & WS_POPUP)) {
HWND hwnd = (HWND)wParam;
/* Hummm ... rand est une fonction en pur C, et nécessite
* l'invocation de srand, qui n'apparait nulle part
*/
int x = rand() % (GetSystemMetrics(SM_CXSCREEN) - pcs->cx);
int y = rand() % (GetSystemMetrics(SM_CYSCREEN) - pcs->cy);
pcs->x = x;
pcs->y = y;
}
}
return CallNextHookEx(0, nCode, wParam, lParam);
}
int main() {
HHOOK hook = SetWindowsHookEx(WH_CBT, msgBoxHook, 0, GetCurrentThreadId());
MessageBoxW(NULL, L"Msgbox | Test", L"MessageBox", MB_SYSTEMMODAL | MB_OK | MB_ICONIFORMATION);
UnhookWindowsHookEx(hook);
} |
Partager