Question GDI Drawing Crosshair

Hexui Undetected CSGO Cheats Sinkicheat PUBG Cheat

Fleep

Founder
Meme Tier VIP
May 20, 2012
572
11,023
6
Good luck, feel free to give us a preview of it working if you like.

Fleep
 

bzh

Newbie
Full Member
Oct 3, 2012
28
292
1
GetSystemMetrics or GetClientRect for 4)
Don't I just use the the X/Y coordinates of the window I'm drawing over?

I put them in an array as fleep did in his tutorial.

Also do I need to use World2Screen?

Edit : I put my current source so far in an attachment, if someone could comment in or show me what I'm doing wrong.
 
Last edited:

bzh

Newbie
Full Member
Oct 3, 2012
28
292
1
I really would just appreciate it if someone helped me.

I figured out that I should use a Pen to draw the lines as it's easier. As I also found out brushes are mainly used for filling objects.

I'm using this to create and select a drawing device

C++:
//Assign a Drawing Device
//Select Pen Sytle, Width, Color
HPEN REDPEN = CreatePen(PS_SOLID, 3, RGB(255,0,0));
HGDIOBJ oldPen=SelectObject(hdesktop,REDPEN);
Now how do I just grab the Resolution variables of the X/Y coords for my CenterofScreen array for the UpdateResolution function Fleep used in his examples?
 
Last edited:

till0sch

Respected Hacker
Dank Tier VIP
Dank Tier Donator
Oct 14, 2012
1,104
12,593
51

bzh

Newbie
Full Member
Oct 3, 2012
28
292
1
1. Get the rect
2. Get Screen res
3. (Screen Width - right - left ) / 2 should be right, same for height (( Screen width - top - bot )) /2
I am yet, still trying to explain to people I'm not trying to get my SCREEN metrics what so ever. I'm trying to get my WINDOW metrics, which I receive from doing the following calculations!

C++:
xCenter = REC.right - REC.left;
yCenter = REC.bottom - REC.top;
This gives me Width and Height, now when I divide them.

C++:
xCenter = REC.right - REC.left / 2;
yCenter = REC.bottom - REC.top / 2;
I don't get the center, or even half of the value. That's the problem. To give you the simple reason why I don't want the SCREEN metrics is because the window won't always be in the center of my screen.
 

till0sch

Respected Hacker
Dank Tier VIP
Dank Tier Donator
Oct 14, 2012
1,104
12,593
51
I am yet, still trying to explain to people I'm not trying to get my SCREEN metrics what so ever. I'm trying to get my WINDOW metrics, which I receive from doing the following calculations!

C++:
xCenter = REC.right - REC.left;
yCenter = REC.bottom - REC.top;
This gives me Width and Height, now when I divide them.

C++:
xCenter = REC.right - REC.left / 2;
yCenter = REC.bottom - REC.top / 2;
I don't get the center, or even half of the value. That's the problem. To give you the simple reason why I don't want the SCREEN metrics is because the window won't always be in the center of my screen.

Shouldn't the mid of window be at Left + (WindowWidth/2) ? And Top + WindowHeight/2
 

brinkz

Coder
Meme Tier VIP
Sep 3, 2012
209
1,688
12
C++:
Resolution.x = clientRect.right;
Resolution.y = clientRect.bottom;
Center.x = Resolution[ 0 ] / 2;
Center.y = Resolution[ 1 ] / 2;
 

bzh

Newbie
Full Member
Oct 3, 2012
28
292
1
C++:
Resolution.x = clientRect.right;
Resolution.y = clientRect.bottom;
Center.x = Resolution[ 0 ] / 2;
Center.y = Resolution[ 1 ] / 2;
My way is the same, just not in an array.

I figured it out, I was just doing the wrong math.

Is there a reason why my crosshair is turning black and losing it's Width?

My green rectangle is also turning black aswell, but the text keeps it's color.

nKHsoxh.jpg

C++:
#include <iostream>
#include <Windows.h>

#define Window "Battlefield 3™"

int main()
{
	//ShowWindow(FindWindowA("ConsoleWindowClass", NULL), false); //Hide Window
	HWND wHANDLE = FindWindow(0, Window); 	//Find WindowNames Window
	HDC hDCArea = GetDC(wHANDLE); //Retrieve DEVICE CONTEXT for the client specified window.
	DWORD ProcessID;
	GetWindowThreadProcessId(wHANDLE, &ProcessID);
	HANDLE wProcHandle;

	//If we obtain okay PID, continue.
	if( ProcessID != 0 ) 
	{ 
		// Get Process Handle 
		wProcHandle = OpenProcess( PROCESS_ALL_ACCESS, FALSE, ProcessID ); 
		if( wProcHandle == INVALID_HANDLE_VALUE || wProcHandle == NULL ) 
		{ 
			MessageBoxA(NULL, "Failed to obtain handle!", NULL, NULL); 
			exit(0);
		} 
		else
		{
			printf("Process " Window " found!\n");
		}
	}
	//Lets start drawing!

	SetBkMode(hDCArea, TRANSPARENT);

	//start while loop
	while(1)
	{

	//Get Window Demensions
	RECT REC;
	//dont really need window rect unless I plan on drawing on the titlebar or some shit
	GetWindowRect(wHANDLE, &REC);
	POINT ptClientUL;
	POINT ptClientLR;

	//Get Client Dimension
	GetClientRect(wHANDLE, &REC);
	ptClientUL.x = REC.left; 
    ptClientUL.y = REC.top;

	//Compensate for missing 2 pixels, add them
	ptClientLR.x = REC.right + 1; 
    ptClientLR.y = REC.bottom + 1;

	ClientToScreen(wHANDLE, &ptClientUL); 
    ClientToScreen(wHANDLE, &ptClientLR);

	//copy client coords to client area
	SetRect(&REC, ptClientUL.x, ptClientUL.y, 
		ptClientLR.x, ptClientLR.y);

	//Calculates for Width / Height of client area
	int xCenter, yCenter;
	xCenter = ptClientLR.x - ptClientUL.x;
	yCenter = ptClientLR.y - ptClientUL.y;

	//printf("Resolution: %d x %d \n \n", xCenter, yCenter);

	//Text
	PAINTSTRUCT ps;

	BeginPaint(wHANDLE, &ps);

	COLORREF PINK(RGB(253, 215, 228));
	SetTextColor(hDCArea, PINK);
	TextOut(hDCArea, 10, 10, "The color PINK", 14);

	COLORREF BLUE(RGB(0, 0, 255));
	SetTextColor(hDCArea, BLUE);
	TextOut(hDCArea, 10, 30, "The color BLUE", 14);

	COLORREF RED(RGB(255, 0, 0));
	SetTextColor(hDCArea, RED);
	TextOut(hDCArea, 10, 50, "The color RED", 13);

	COLORREF YELLOW(RGB(255, 255, 0));
	SetTextColor(hDCArea, YELLOW);
	TextOut(hDCArea, 10, 70, "The color YELLOW", 16);

	COLORREF ORANGE(RGB(255, 165, 0));
	SetTextColor(hDCArea, ORANGE);
	TextOut(hDCArea, 10, 90, "The color ORANGE", 16);

	COLORREF GREEN(RGB(0, 255, 0));
	SetTextColor(hDCArea, GREEN);
	TextOut(hDCArea, 160, 30, "The Color GREEN", 15);

	EndPaint(wHANDLE, &ps); // End Text Paint

	//Line
	HPEN redPen=CreatePen(PS_DOT, 1, RGB(255, 0, 0));
	HGDIOBJ redPObject=SelectObject(hDCArea,redPen);
	
	POINT pntUD[2];
	pntUD[0].x=xCenter/2-10;
	pntUD[0].y=yCenter/2;
	pntUD[1].x=xCenter/2+10;
	pntUD[1].y=yCenter/2;
	Polyline(hDCArea, pntUD, 2);
	
	POINT pntT[2];
	pntT[0].x=xCenter/2;
	pntT[0].y=yCenter/2-10;
	pntT[1].x=xCenter/2;
	pntT[1].y=yCenter/2+10;
	Polyline(hDCArea, pntT, 2);
	
	//Delete Red Pen
	SelectObject(hDCArea,redPObject);

	//Pen for drawing Rectangle
	HPEN greenPen=CreatePen(PS_SOLID, 2, RGB(0, 255, 0));
	HGDIOBJ greenPObject=SelectObject(hDCArea,greenPen);
	//Select stock object HOLLOW_BRUSH to Fill Rectangle transparent
	SelectObject(hDCArea, GetStockObject(HOLLOW_BRUSH));
	Rectangle(hDCArea, 160,50, 250,230);
	SelectObject(hDCArea,greenPObject);

	//Redraw
	InvalidateRect(wHANDLE,&REC,TRUE);
	
	}
	return 0;
	
}
 
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