Well after hours and hours and hours of searching and getting help from someone on a different forum I got this code to work for C++ that will get a pixel color from a hidden window
#include <iostream>
#define _WIN32_WINNT 0x0501
#include <windows.h>
#define PixelGetColor(x, y) PixelGet(mDC, x, y)
int CreateContext(char *window_name, HDC *hDC, HDC *mDC, HBITMAP *hBM) {
RECT win_stats;
HWND hwnd = FindWindow(NULL, window_name);
if(!GetClientRect(hwnd, &win_stats)) {
return 1;
}
*hDC = GetDC(hwnd);
*mDC = CreateCompatibleDC(*hDC);
*hBM = CreateCompatibleBitmap(*hDC, win_stats.right, win_stats.bottom);
SelectObject(*mDC, *hBM);
PrintWindow(hwnd, *mDC, 0);
return 0;
}
void DeleteContext(HDC *hDC, HDC *mDC, HBITMAP *hBM) {
ReleaseDC(NULL, *hDC);
DeleteDC(*mDC);
DeleteObject(*hBM);
}
COLORREF PixelGet(HDC mDC, int x, int y) {
return GetPixel(mDC, x, y);
}</windows.h></iostream>
I also got a way to do it in autohotkey
SetTitleMatchMode, 2
CoordMode, Mouse, Screen
CoordMode, Pixel, Screen
wintitle := "" ;Name of your window.
;First 3 are variable placeholders. 4th is the variable above
CreateContext(hDC, context, pixels, wintitle)
;Move your window offscreen (My screen is 1920x1200)
WinMove, %wintitle%,, 1921, 200
;Grab the color on window at x/y (0,0)
color := DllCall("GetPixel", UInt, context, Int, 0, Int, 0)
;Convert the integer to RGB format, then convert to hex and show
Msgbox % DecToHex(ConvertColor(color))
;Move window back to viewable area
WinMove, %wintitle%,, 0, 0
;Cleanup to avoid memory leaks.
DeleteContext(hDC, context, pixels)
;Everything below here shouldn't be modified unless you know what you're doing
CreateContext(ByRef hDC, ByRef mDC, ByRef hBM, wintitle)
{
WinGet, w_id, ID, %wintitle%
hDC := DllCall("GetDC", UInt, w_id)
IfWinExist, %wintitle%
{
WinGetPos, x, y, w, h
}
mDC := DllCall("gdi32.dll\CreateCompatibleDC", "UInt", hDC)
hBM := DllCall("gdi32.dll\CreateCompatibleBitmap", "uint", hDC, "int", w, "int", h)
DllCall("gdi32.dll\SelectObject", UInt, mDC, UInt, hBM)
DllCall("PrintWindow", "UInt", w_id, UInt, mDC, UInt, 0)
}
DeleteContext(ByRef hDC, ByRef mDC, ByRef hBM)
{
DllCall("ReleaseDC", "UInt", 0, "UInt", hDC)
DllCall("DeleteDC", "Uint", mDC)
DllCall("DeleteObject", "Uint", hBM)
}
ConvertColor( BGRValue )
{
BlueByte := ( BGRValue & 0xFF0000 ) >> 16
GreenByte := BGRValue & 0x00FF00
RedByte := ( BGRValue & 0x0000FF ) << 16
return RedByte | GreenByte | BlueByte
}
DecToHex(dec)
{
oldfrmt := A_FormatInteger
hex := dec
SetFormat, IntegerFast, hex
hex += 0
hex .= ""
SetFormat, IntegerFast, %oldfrmt%
return hex
}
Only to find out that what I wanted to do this for would not work unless the window was active (It has to be active to send the key otherwise it won't read it and it will do nothing)