Click here to Skip to main content
15,867,834 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
(I don't see anywhere that says you can't ask for help for bots, I really hope I'm not violating any rules because I really just want help for working on a cool first project)
I'm on the second day of searching for this, closest I got was
Capturing Minimized Window: A Kid’s Trick^This article

It does everything I need (Capturing a hidden window, looks like it can search for a color in the captured picture)
http://img12.imageshack.us/img12/6663/pokemonbt.jpg[^]

This is where I'm trying to use the PixelGetColor (Mini window isn't actually in the window, I'm also trying to make it respective to the window(VisualBoyAdvance) so I can have the VisualBoyAdvance window anywhere and it will do the PixelGetColor but idk how to do that either lol)

Please help me, I'm very noob in coding and originally started this just to mess around and am loving every second of it but so limited by what I know and understand lol. Examples and explanations would help a lot too

autoit
$start = PixelGetColor(650,230) ;Checking to see if it's the start screen
		 If $start = 0x400000 Then
			ToolTip("Resets:" & $n & " Press Start Screen",0,0)
			Send("{x}")
			Sleep(750)

$profile = PixelGetColor(400,500) ;Checking to see if it's the Profile select screen
		 If $profile = 0x505890 Then
			ToolTip("Resets:" & $n & " Select Profile Screen",0,0)
			Send("{x}")
			Sleep(100)

$shiny = PixelGetColor(200,240) ;Regular charmander color
$female = PixelGetColor(330, 130) ;Female color
		 If $shiny <> 0xD84848 Then ;Shiny Charmander
			ToolTip("Resets:" & $n & " Shiny Charmander Found, checking sex",0,0)
			   If $female = 0xF8B870 Then	;Gender Color
Posted
Updated 24-Aug-12 9:37am
v2
Comments
JackDingler 24-Aug-12 15:38pm    
GetPixelColor may not be valid for a minimized window.

A minimized window doesn't get WM_PAINT messages unless it's displayed as an icon.
So I'm not sure that there would be a display buffer allocated for it.

Feel free to correct me with facts if necessary...
Member 9380471 24-Aug-12 16:43pm    
Alright I know nothing about C++, I tried looking at the source code for Capturing minimized window[^] because it Restores, keeps transparent, able to capture the picture of the program running and has a Box for "Handle:" and next to it a button "Snap", when snap is pressed I get a message "Wrong Handle(note: handle must be entered as a decimal(hex is not acceptable)"

So it's doing something with a color but like I said... Idk anything about C++ and I know very little about autoit xD

http://msdn.microsoft.com/en-us/library/windows/desktop/dd145216%28v=vs.85%29.aspx[^] Looks like it might be able to do what I need.... So I will try and work with this later but more solutions would help a lot, especially if anyone has done what I'm trying to do

Will play with the WM_PRINT when I get back in an hour/2

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

C++
#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

C++
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)
 
Share this answer
 
When the window is not minimized it draws itself when windows sends a WM_PAINT to the window. The frequency and cause of the WM_PAINT message might be different depending on the active Desktop Window Manager. In older windows operating systems with classic manager when your window is partially covered by other windows the system doesnt store the whole image of your window. Instead it asks your window to draw the client area and it gives you a HDC to do that which has a clipping region on it to exclude the covered parts. This measn that some pixels of your window might never been actually drawn/stored. This is very useful when you use a stupid video card and all you have is the framebuffer of the whole screen, with clipping you can draw all windows straight into that single screen buffer. On the other hand in a 3D accelerated window manager every window might have its own surface to draw on for the whole liftime of the windows depending on the memory management of the window manager.

What I described previously is not the only problem. Most games usually check if the window is minimzed using IsIconic()[^] and they don't draw/render at all when minimized, the same can be true for a lot of other programs too.

PS: There is a WM_PRINT[^] message that you should check out, it might work for some programs, I havent used it much though and my app handled it specially.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900