Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C++ C# hidden minimized
(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
 
$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 24-Aug-12 10:32am
Edited 24-Aug-12 10:37am
Wes Aday94.3K
v2
Comments
JackDingler at 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 at 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
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

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.
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 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
 
#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)
  Permalink  

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

  Print Answers RSS
0 OriginalGriff 381
1 Sergey Alexandrovich Kryukov 245
2 Marcin Kozub 225
3 Praneet Nadkar 217
4 /\jmot 189
0 OriginalGriff 8,284
1 Sergey Alexandrovich Kryukov 7,407
2 DamithSL 5,614
3 Maciej Los 4,989
4 Manas Bhardwaj 4,986


Advertise | Privacy | Mobile
Web03 | 2.8.1411023.1 | Last Updated 27 Aug 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100