Tutorial Creating a HWND to Chrome

Hexui Undetected CSGO Cheats Sinkicheat PUBG Cheat

Kilo

Coder
Dank Tier Donator
Nobleman
Feb 4, 2015
98
4,028
1
I'll finish this later, been busy so I haven't been active and now I'm just tired lol.
So until probably tomorrow, it's just source code with some comments.

C++:
//Chrome.h
#include <Windows.h>

#pragma once
class Chrome
{
private:
	BYTE flag; //The flag is set so in case Chrome is not open, we will open chrome only once
protected:
	HWND hwnd; //The hwnd is set to protected so we can access it from derived classes, otherwise we can set it to private
public:
	Chrome();
	~Chrome();
	void getChrome();
	void openChrome();
	void showChrome();
};
C++:
//Chrome.cpp
#include "Chrome.h"

Chrome::Chrome()
{
	flag = 0; //Setting the flag to 0
	getChrome(); //Getting our handle to chrome!
}


Chrome::~Chrome()
{
}


void Chrome::getChrome()
{
	while(true)
	{
		hwnd = FindWindowEx(0, hwnd, L"Chrome_WidgetWin_1", 0); //We are setting our hwnd to the chrome class(we can find the name of the chrome class by using a nifty tool called Spy++
		if(!hwnd && flag == 0) //If chrome is not a running process, we will start it up
		{
			openChrome(); //Our function that opens chrome
			flag++; //Increment our flag so we only run this statement once
		}
		if(IsWindowVisible(hwnd)) //If our chrome window is not visible, we'll make it visible
		{
			showChrome(); //Our function to make our chrome visible.
			return;
		}
	}
}


void Chrome::showChrome()
{
	WINDOWPLACEMENT place;
	memset(&place, 0, sizeof(WINDOWPLACEMENT));
	place.length = sizeof(WINDOWPLACEMENT);
	GetWindowPlacement(hwnd, &place);

	switch(place.showCmd)
	{
		case SW_SHOWMAXIMIZED:
			ShowWindow(hwnd, SW_SHOWMAXIMIZED);
			break;
		case SW_SHOWMINIMIZED:
			ShowWindow(hwnd, SW_RESTORE);
			break;
		default:
			ShowWindow(hwnd, SW_NORMAL);
			break;
	}
	SetForegroundWindow(hwnd);
}


void Chrome::openChrome()
{
	LPCTSTR dir = L"X:\\Program Files (x86)\\Google\\Chrome\\Application\\chrome.exe";
	LPTSTR cmdArgs = L"chrome.exe --start-maximized";

	STARTUPINFO si;
	PROCESS_INFORMATION pi;

	SecureZeroMemory(&si, sizeof(si));
	si.cb = sizeof(si);
	SecureZeroMemory(&pi, sizeof(pi));

	CreateProcess(dir,
				  cmdArgs,
				  0,
				  0,
				  0,
				  0,
			      0,
				  0,
				  &si,
				  &pi);
		
	CloseHandle(pi.hProcess);
	CloseHandle(pi.hThread);
}
C++:
//main.cpp
#include <memory>
#include "Chrome.h"

int main()
{
	std::unique_ptr<Chrome>chrome(new Chrome);
}
 
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