History:
Slow Down Proc
Slow down another process
Suspension of any external processes using functions OpenThread(), SuspendThread() a ResumeThread().
Code
#include <Windows.h> #include <TlHelp32.h> HWND GetProcessMainWindows( DWORD dwProcessID ); DWORD GetProcessID( TCHAR *lpszProcessName ); DWORD WINAPI Vlakno(void*); int _tmain(int argc, _TCHAR* argv[]) { HWND windowHandle = FindWindow(NULL, _T("Test")); printf("HWND: %d\n", GetWindowThreadProcessId(windowHandle, NULL) ); DWORD hThread = GetWindowThreadProcessId(windowHandle, NULL); printf( "%d\n", hThread ); //HANDLE handle = CreateThread( NULL, NULL, &Vlakno, (void*)11 , 0, 0 ); HANDLE thread = OpenThread(THREAD_ALL_ACCESS, FALSE, hThread); printf( "%d\n", thread ); //printf( "Resume: %d\n", ResumeThread( thread ) ); while(true) { printf( "Suspend: %d\n", SuspendThread( thread ) ); Sleep(1000); // some number of milliseconds - larger values will slow down more //printf( "Resume: %d\n", ResumeThread( thread ) ) while ( ResumeThread( thread ) > 0); Sleep(100); } while ( ResumeThread( thread ) > 0); return 0; } DWORD WINAPI Vlakno(void*) { for(u_int i=0; true; i++ ) printf("[%d] Hello\n", i); return true; } HWND GetProcessMainWindows( DWORD dwProcessID ) { HWND hwnd = NULL; do{ hwnd = FindWindowEx (NULL, hwnd, NULL, NULL); DWORD dwPID = 0; GetWindowThreadProcessId (hwnd, &dwPID); if (dwPID == dwProcessID) return hwnd; }while( hwnd != NULL ); return NULL; } DWORD GetProcessID( TCHAR *lpszProcessName ) { DWORD processID = NULL; HANDLE hSnapShot = CreateToolhelp32Snapshot ( TH32CS_SNAPPROCESS, 0); PROCESSENTRY32* processInfo = new PROCESSENTRY32; processInfo->dwSize = sizeof ( PROCESSENTRY32); while ( Process32Next ( hSnapShot,processInfo ) != FALSE) { if( strcmp( processInfo->szExeFile, lpszProcessName ) == 0 ) { processID = processInfo->th32ProcessID; break; } } CloseHandle( hSnapShot); delete processInfo; return processID; }
Code.Tode.cz by Henry - 2014