script wont work after adding in a another part to it

hi ya so my script wont work after i add in another part i know its a simple fix but its too hard for me where it says "case WM_CREATE - break;" thats the thing thats causing it to fail i want it to close cheat engine when it opens and the name is correct because i tried it for another process name and it worked in console application


#include <windows.h>
#include <stdlib.h>
#include <string.h>
#include <tchar.h>
#include <iostream>

using namespace std;


static TCHAR szWindowClass[] = _T("win32app");
static TCHAR szTitle[] = _T("Win32 Guided Tour Application");

HINSTANCE hInst;

LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);

int WINAPI WinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR lpCmdLine,
int nCmdShow)
{
WNDCLASSEX wcex;

wcex.cbSize = sizeof(WNDCLASSEX);
wcex.style = CS_HREDRAW | CS_VREDRAW;
wcex.lpfnWndProc = WndProc;
wcex.cbClsExtra = 0;
wcex.cbWndExtra = 0;
wcex.hInstance = hInstance;
wcex.hIcon = LoadIcon(hInstance, MAKEINTRESOURCE(IDI_APPLICATION));
wcex.hCursor = LoadCursor(NULL, IDC_ARROW);
wcex.hbrBackground = (HBRUSH)(COLOR_WINDOW + 1);
wcex.lpszMenuName = NULL;
wcex.lpszClassName = szWindowClass;
wcex.hIconSm = LoadIcon(wcex.hInstance, MAKEINTRESOURCE(IDI_APPLICATION));

if (!RegisterClassEx(&wcex))
{
MessageBox(NULL,
_T("Call to RegisterClassEx failed!"),
_T("Win32 Guided Tour"),
NULL);

return 1;
}

hInst = hInstance;
HWND hWnd = CreateWindow(
szWindowClass,
szTitle,
WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT, CW_USEDEFAULT,
500, 100,
NULL,
NULL,
hInstance,
NULL
);

if (!hWnd)
{
MessageBox(NULL,
_T("Call to CreateWindow failed!"),
_T("Win32 Guided Tour"),
NULL);

return 1;
}
ShowWindow(hWnd,
nCmdShow);
UpdateWindow(hWnd);
MSG msg;
while (GetMessage(&msg, NULL, 0, 0))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}

return (int)msg.wParam;
}
LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
switch (message)
{
case WM_DESTROY:
PostQuitMessage(0);
break;
case WM_CREATE:


HWND process = FindWindow(NULL, L"Cheat Engine 6.3");
DWORD id;
GetWindowThreadProcessId(process, &id);
HANDLE hProc = OpenProcess(PROCESS_ALL_ACCESS, FALSE, id);
TerminateProcess(hProc, 0);

break;


default:
return DefWindowProc(hWnd, message, wParam, lParam);
break;
}

return 0;
}
OP wrote:
i tried it for another process name and it worked in console application


FindWindow Documentation wrote:
For a description of a potential problem that can arise, see the Remarks for GetWindowText.


GetWindowText Documentation wrote:
If the window does not have a caption, the return value is a null string.


You are better off using "CreateToolhelp32Snapshot()", "Process32First()" and "Process32Next()" to find process based on the name of the executable, then pull the 'th32ProcessID' from the 'PROCESSENTRY32' struct that the later two populate. Not that you couldn't fix this issue or find some other metric to base your search off, but in my experience "FindWindow()" has always been a bit clunky.

"CreateToolhelp32Snapshot()": https://msdn.microsoft.com/en-us/library/windows/desktop/ms682489(v=vs.85).aspx

"Process32First()": https://msdn.microsoft.com/en-us/library/windows/desktop/ms684834(v=vs.85).aspx

"Process32Next()": https://msdn.microsoft.com/en-us/library/windows/desktop/ms684836(v=vs.85).aspx

PROCESSENTRY32: https://msdn.microsoft.com/en-us/library/windows/desktop/ms684839(v=vs.85).aspx

EDIT: Oh! I almost forgot. A cheat engine will, by necessity, have loaded hooks into the target application that probably get cleaned up when it exits. But the function "TerminateProcess()" just drops the target process on the floor and doesn't allow destructors to run so those hooks will probably be left in the target process. If this is what you want then great, otherwise consider using "ExitProcess()": https://msdn.microsoft.com/en-us/library/windows/desktop/ms682658(v=vs.85).aspx
Last edited on
ya well im learning and i did try creatoolhelp32snapshot but it didnt work but is there any possible way to fix that script above
Topic archived. No new replies allowed.