Source Code Multithread WINAPI

Hexui Undetected CSGO Cheats Sinkicheat PUBG Cheat


Full Member
Nov 8, 2014

Since i'm back and starting to study c++/winapi fundaments again, i'm posting a multithread example to save it here and help someone that can need this too.
And i could not find a simple example using search option.

1- Create a Console c++ project in VS 2013.
2- Copy/paste

It will create 2 threads + main
One thread to check ESC to exit, one thread to get mouse position and display and the main thread doing nothing. Threads from member functions. Very simple.:rolleyes:
I think this is the most easy way to do it, but there is others.

#include <iostream>
#include <Windows.h>

class Test{


	bool exitEsc = false;


	DWORD mouseThreadId;
	DWORD exitThreadId;

	void startCheckExit();
	void startMousePosition();

	static DWORD CheckExit(LPVOID lpParam);
	static DWORD MousePosition(LPVOID lpParam);

} tst;

void Test::startMousePosition(){
	HANDLE mouseId = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)&MousePosition, NULL, 0, &mouseThreadId);
	if (mouseId)
		WaitForSingleObject(mouseId, INFINITE);

DWORD Test::MousePosition(LPVOID lpParam){
	while (GetCursorPos(&tst.p)){
		std::cout << "x: " << tst.p.x << " y: " << tst.p.y << std::endl;
		if (tst.exitEsc)
			return 0;
	return 0;

void Test::startCheckExit(){
	HANDLE checkId = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)&CheckExit, NULL, 0, &exitThreadId);
	if (checkId){
		WaitForSingleObject(checkId, INFINITE);

DWORD Test::CheckExit(LPVOID lParam){
	while (!tst.exitEsc){
		if (GetAsyncKeyState(VK_ESCAPE))
			tst.exitEsc = true;
	return 0;

int main(){

	return 0;
Last edited:
Attention! Before you post:

Read the How to Ask Questions Guide
99% of questions are answered in the Beginner's Guide, do it before asking a question.

No Hack Requests. Post in the correct section.  Search the forum first. Read the rules.

How to make a good post:

  • Fill out the form correctly
  • Tell us the game name & coding language
  • Post everything we need to know to help you
  • Ask specific questions, be descriptive
  • Post errors, line numbers & screenshots
  • Post code snippets using code tags
  • If it's a large project, zip it up and attach it

If you do not comply, your post may be deleted.  We want to help, please make a good post and we will do our best to help you.

Community Mods