// KDEBUG is defined to enable debugging facilities in the K* classes // This preprocessor directive is set as a 'project setting' to affect all files. //#define KDEBUG #define STRICT #define WIN32_LEAN_AND_MEAN #define _CRT_SECURE_NO_DEPRECATE #include #include #include #include #include #define INITGUID #include #pragma comment (lib, "ddraw.lib") #include #include #include #include #include #include #include "engine.h" #include "launcher.h" #include "HookDLL.h" #pragma comment (lib, "..\\Debug\\spy.lib") #include #include #include int WINAPI WinMain(HINSTANCE hInst, HINSTANCE, LPSTR, int nShow) { try { // Initialisations. KLauncher launcher; HWND target_window, controller_window; DWORD target_tid, target_pid, controller_tid, controller_pid; // The timer blocks the process when waiting for the target process // or window to come up. // Slept counts how many times Sleep was called. In effect it // keeps track of the time spent sleeping = (slept*timer/1000)/60 minutes. DWORD timer = 1000, slept = 0; launcher.LaunchApp(); do { //target_window = FindWindow( L"DUMB", L"dumb" ); target_window = FindWindow(L"Notepad", NULL); Sleep(timer); slept++; }while( target_window == NULL && slept < 600 ); // Look at most for 10 minutes. SetTargetHwnd(target_window); target_tid = GetWindowThreadProcessId( target_window, & target_pid ); InstallHook(WH_MOUSE, target_tid); InstallHook(WH_CBT, target_tid); KEngine engine(hInst, target_window, target_pid); engine.CreateEx( 0, L"overlay", L"overlay", WS_OVERLAPPEDWINDOW, 0, 0, 200, 200, NULL, NULL, hInst ); controller_window = engine.GetEngineWindowHandle(); SetControllerHwnd(controller_window); controller_tid = GetWindowThreadProcessId( controller_window, & controller_pid ); AttachThreadInput(controller_tid, target_tid, true); //engine.ShowWindow(nShow); //engine.UpdateWindow(); engine.InitScene(); engine.MessageLoop(); AttachThreadInput(controller_tid, target_tid, false); UninstallHook(); } catch(KException::KDxException& e_dx) { e_dx.ConstructErrorMsg(); e_dx.WriteErrorMsg(); } catch(KException::KWinException& e_win) { e_win.ConstructErrorMsg(); e_win.WriteErrorMsg(); } catch(KException::ZGrpException& e_zgrp) { e_zgrp.ConstructErrorMsg(); e_zgrp.WriteErrorMsg(); } return 0; }