Sign in to follow this  
Followers 0
Makalele

Getting pixel in hidden window

29 posts in this topic

Hi! I have next problem with my bot. It works sweet but if i hide the Internet Explorer Window or i open another window function GetPixelColor doesn't work ;/ for example : PixelGetColor($X,$Y,$WinHandle) etc... i thought that if i add $WinHandle parameter it'll work when window is hidden... maybe any1 know another method to get pixel in hidden window ?


Share this post


Link to post
Share on other sites

any way to do it exist ?


Share this post


Link to post
Share on other sites

help me plz :)


Share this post


Link to post
Share on other sites

Well rather than having you rack your brain on this... the short answer is "no". There's no way currently to get the device content of a minimized or hidden window because it isn't drawn when in these states.


Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Share this post


Link to post
Share on other sites

Hello there,

firstly the topics,

http://www.autoitscript.com/forum/index.ph...mp;#entry528636

http://www.autoitscript.com/forum/index.ph...mp;#entry567936

I'm trying to do it from few months. Still no effect. But i know it's possible, but no by straight method - i got another idea. I'm sure it'll be working in C++. So it's possible to make the small dll library in C++ and use this by DllCall function. But there is a problem - i know C++ language very low. And now, i'm making a request for users of this forum to help me. I think if you know C++ well, you'll make it very fast. Someone told me that it's impossible to read the pixel from hidden window, because windows don't draw the pixel when they are hidden. It's true, BUT if you use command called "Send Message" the window can send the data to our script :) (http://www.fengyuan.com/article/wmprint.html) Looks good? I think yes. The rest are in these topics. If you don't want to help me, please don't post here.

Sorry for my english - it isn't perfect yet ^^.

Regards,

Makalele


Share this post


Link to post
Share on other sites

If you are looking for C++ help, you should try a C++ forum, or perhaps put this in chat as it is not an au3 issue/request.

Happy hunting.

Share this post


Link to post
Share on other sites

If you are looking for C++ help, you should try a C++ forum, or perhaps put this in chat as it is not an au3 issue/request.

Happy hunting.

Thanks for a tip. I'll do it. But maybe someone want to help me here :)


Share this post


Link to post
Share on other sites

#8 ·  Posted (edited)

I've replied to one of these posts already. It isn't about a desire to help you or not, I personally would love for it to be possible. But you've answered your own question with a fact.

I saw that cppman says it "should" be possible, but he's talking about Vista with no code to back it up. If you want to do it in XP, the fact that the last time you started a topic on this is still the same.

Do not start another thread on the same topic.

Edit:

Topics merged

Edited by SmOke_N

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Share this post


Link to post
Share on other sites

I've replied to one of these posts already. It isn't about a desire to help you or not, I personally would love for it to be possible. But you've answered your own question with a fact.

I saw that cppman says it "should" be possible, but he's talking about Vista with no code to back it up. If you want to do it in XP, the fact that the last time you started a topic on this is still the same.

Do not start another thread on the same topic.

Edit:

Topics merged

Sry for starting new topic, thanks for merge :)

If it's working in C++ so it's possible in Windows XP >_<


Share this post


Link to post
Share on other sites

Sry for starting new topic, thanks for merge :)

If it's working in C++ so it's possible in Windows XP >_<

So where is this C++ code that it's working in?

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Share this post


Link to post
Share on other sites

So where is this C++ code that it's working in?

http://www.fengyuan.com/article/wmprint.html

This is a guide how to capture the window to the clipboard. So someone can change this function:

void PrintWindow(HWND hWnd)
{
    HDC hDCMem = CreateCompatibleDC(NULL);

    RECT rect;

    GetWindowRect(hWnd, & rect);

    HBITMAP hBmp = NULL;

    {
        HDC hDC = GetDC(hWnd);
        hBmp = CreateCompatibleBitmap(hDC, rect.right - rect.left, rect.bottom - rect.top);
        ReleaseDC(hWnd, hDC);
    }

    HGDIOBJ hOld = SelectObject(hDCMem, hBmp);
    SendMessage(hWnd, WM_PRINT, (WPARAM) hDCMem, PRF_CHILDREN | PRF_CLIENT | PRF_ERASEBKGND | PRF_NONCLIENT | PRF_OWNED);

    SelectObject(hDCMem, hOld);
    DeleteObject(hDCMem);

    OpenClipboard(hWnd);

    EmptyClipboard(); 
    SetClipboardData(CF_BITMAP, hBmp);
    CloseClipboard();
}

To something like that:

int GetPixelColor(int x,y, HWND hwnd)
{
the code from last function ...

}

but on the end not copy bitmap to clipboard, just straight read the pixel using GetPixel or something like that :) Easy to make in my opionion, but i don't know how to do it exatcly. My c++ knowledge is bad >_<


Share this post


Link to post
Share on other sites

http://www.fengyuan.com/article/wmprint.html

This is a guide how to capture the window to the clipboard. So someone can change this function:

void PrintWindow(HWND hWnd)
{
    HDC hDCMem = CreateCompatibleDC(NULL);

    RECT rect;

    GetWindowRect(hWnd, & rect);

    HBITMAP hBmp = NULL;

    {
        HDC hDC = GetDC(hWnd);
        hBmp = CreateCompatibleBitmap(hDC, rect.right - rect.left, rect.bottom - rect.top);
        ReleaseDC(hWnd, hDC);
    }

    HGDIOBJ hOld = SelectObject(hDCMem, hBmp);
    SendMessage(hWnd, WM_PRINT, (WPARAM) hDCMem, PRF_CHILDREN | PRF_CLIENT | PRF_ERASEBKGND | PRF_NONCLIENT | PRF_OWNED);

    SelectObject(hDCMem, hOld);
    DeleteObject(hDCMem);

    OpenClipboard(hWnd);

    EmptyClipboard(); 
    SetClipboardData(CF_BITMAP, hBmp);
    CloseClipboard();
}

To something like that:

int GetPixelColor(int x,y, HWND hwnd)
{
the code from last function ...

}

but on the end not copy bitmap to clipboard, just straight read the pixel using GetPixel or something like that :) Easy to make in my opionion, but i don't know how to do it exatcly. My c++ knowledge is bad >_<

GetDC <-- And thus your problem. When the window is minimized or hidden, you can't get the correct Device Content. This C++ code does not do what you claim it does.

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Share this post


Link to post
Share on other sites

GetDC <-- And thus your problem. When the window is minimized or hidden, you can't get the correct Device Content. This C++ code does not do what you claim it does.

Hmm but maybe that method by making 3 functions:

first (used on script start when window is visible)

void RememberWindow(HWND hWnd)

{

HDC hDCMem = CreateCompatibleDC(NULL);

RECT rect;

GetWindowRect(hWnd, & rect);

HBITMAP hBmp = NULL;

{

HDC hDC = GetDC(hWnd);

hBmp = CreateCompatibleBitmap(hDC, rect.right - rect.left, rect.bottom - rect.top);

ReleaseDC(hWnd, hDC);

}

}

second

int RefreshPixelData

{

HGDIOBJ hOld = SelectObject(hDCMem, hBmp);

SendMessage(hWnd, WM_PRINT, (WPARAM) hDCMem, PRF_CHILDREN | PRF_CLIENT | PRF_ERASEBKGND | PRF_NONCLIENT | PRF_OWNED);

SelectObject(hDCMem, hOld);

DeleteObject(hDCMem);

}

int GetPixel(int x,y)

{

GetPixel(....

}

is it possible now ?


Share this post


Link to post
Share on other sites

What difference would it make if you divided the same function up into 10 individual functions?


Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Share this post


Link to post
Share on other sites
Is this not just showing how to rewrite an app to display the clientdata differently, so that it can be read while not visible? This can be done if you are creating the app from scratch or have access to the source, but for any other purpose this is unusable. For example if you wanted to read the pixels on a minimized game window, this code does not apply. :)

There is always a butthead in the crowd, no matter how hard one tries to keep them out.......Volly

Share this post


Link to post
Share on other sites

I did some tests too but no luck on WINXP  :)

Here is link to my post:

http://www.autoitscript.com/forum/index.ph...st&p=523910

I translated it:
_PrintWindow(WinGetHandle(""))

Func _PrintWindow($h_wnd)
    
    Local Const $CF__BITMAP      = 0x002
    Local Const $PRF__CHILDREN   = 0x0010
    Local Const $PRF__CLIENT     = 0x004
    Local Const $PRF__ERASEBKGND = 0x008
    Local Const $PRF__OWNED      = 0x0020
    Local Const $WM__PRINT       = 0x00317
    
    Local $h_gdi32 = DllOpen("gdi32.dll")
    Local $h_user32 = DllOpen("user32.dll")
    
    Local $h_dc_mem = DllCall($h_gdi32, "hwnd", "CreateCompatibleDC", "hwnd", 0)
    
    Local $t_rect = DllStructCreate("int left;int top;int right;int bottom")
    DllCall($h_user32, "int", "GetWindowRect", "hwnd", $h_wnd, "ptr", DllStructGetPtr($t_rect))
    
    Local $h_dc = DllCall($h_user32, "hwnd", "GetDC", "hwnd", $h_wnd)
    Local $h_bmp = DllCall($h_gdi32, "hwnd", "CreateCompatibleBitmap", "hwnd", $h_dc[0], _
        "int", DllStructGetData($t_rect, "right") - DllStructGetData($t_rect, "left"), _
        "int", DllStructGetData($t_rect, "bottom") - DllStructGetData($t_rect, "top"))
    DllCall($h_gdi32, "int", "ReleaseDC", "hwnd", $h_dc[0])
    
    Local $h_old = DllCall($h_gdi32, "hwnd", "SelectObject", "hwnd", $h_dc_mem[0], "hwnd", $h_bmp[0])
    DllCall($h_user32, "int", "SendMessage", "hwnd", $h_wnd, _
        "int", $WM__PRINT, "wparam", $h_dc_mem[0], _
        "lparam", BitOR($PRF__CHILDREN, $PRF__CLIENT, $PRF__ERASEBKGND, $PRF__OWNED))
    
    DllCall($h_gdi32, "hwnd", "SelectObject", "hwnd", $h_dc_mem[0], "hwnd", $h_old[0])
    
    DllCall($h_user32, "int", "OpenClipboard", "hwnd", $h_wnd)
    DllCall($h_user32, "int", "EmptyClipboard")
    
    DllCall($h_user32, "int", "SetClipboardData", "long", $CF__BITMAP, "hwnd", $h_bmp[0])
    DllCall($h_user32, "int", "CloseClipboard")
    
    DllCall($h_gdi32, "int", "DeleteObject", "hwnd", $h_dc_mem[0])
    DllClose($h_gdi32)
    DllClose($h_user32)
    Return
EndFunc
But the bmp is always black.

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Share this post


Link to post
Share on other sites

I translated it:

_PrintWindow(WinGetHandle(""))

Func _PrintWindow($h_wnd)
    
    Local Const $CF__BITMAP      = 0x002
    Local Const $PRF__CHILDREN   = 0x0010
    Local Const $PRF__CLIENT     = 0x004
    Local Const $PRF__ERASEBKGND = 0x008
    Local Const $PRF__OWNED      = 0x0020
    Local Const $WM__PRINT       = 0x00317
    
    Local $h_gdi32 = DllOpen("gdi32.dll")
    Local $h_user32 = DllOpen("user32.dll")
    
    Local $h_dc_mem = DllCall($h_gdi32, "hwnd", "CreateCompatibleDC", "hwnd", 0)
    
    Local $t_rect = DllStructCreate("int left;int top;int right;int bottom")
    DllCall($h_user32, "int", "GetWindowRect", "hwnd", $h_wnd, "ptr", DllStructGetPtr($t_rect))
    
    Local $h_dc = DllCall($h_user32, "hwnd", "GetDC", "hwnd", $h_wnd)
    Local $h_bmp = DllCall($h_gdi32, "hwnd", "CreateCompatibleBitmap", "hwnd", $h_dc[0], _
        "int", DllStructGetData($t_rect, "right") - DllStructGetData($t_rect, "left"), _
        "int", DllStructGetData($t_rect, "bottom") - DllStructGetData($t_rect, "top"))
    DllCall($h_gdi32, "int", "ReleaseDC", "hwnd", $h_dc[0])
    
    Local $h_old = DllCall($h_gdi32, "hwnd", "SelectObject", "hwnd", $h_dc_mem[0], "hwnd", $h_bmp[0])
    DllCall($h_user32, "int", "SendMessage", "hwnd", $h_wnd, _
        "int", $WM__PRINT, "wparam", $h_dc_mem[0], _
        "lparam", BitOR($PRF__CHILDREN, $PRF__CLIENT, $PRF__ERASEBKGND, $PRF__OWNED))
    
    DllCall($h_gdi32, "hwnd", "SelectObject", "hwnd", $h_dc_mem[0], "hwnd", $h_old[0])
    
    DllCall($h_user32, "int", "OpenClipboard", "hwnd", $h_wnd)
    DllCall($h_user32, "int", "EmptyClipboard")
    
    DllCall($h_user32, "int", "SetClipboardData", "long", $CF__BITMAP, "hwnd", $h_bmp[0])
    DllCall($h_user32, "int", "CloseClipboard")
    
    DllCall($h_gdi32, "int", "DeleteObject", "hwnd", $h_dc_mem[0])
    DllClose($h_gdi32)
    DllClose($h_user32)
    Return
EndFunc
But the bmp is always black.
Finally i found that topic >_<

http://www.autoitscript.com/forum/index.php?showtopic=55564

That section is the section that requires the assembly.

So i think it'll only work in C++.. I need to read pixel's from Flash Object in Internet Explorer, maybe is another way to do it ? :) Maybe someone test it in C++ ?

Share this post


Link to post
Share on other sites

#19 ·  Posted (edited)

okay , i don't have an answer for you but it is just an idea

your problem starts on hiding the internet explorer window

maybe you can just move the window off screen , show it

and use the PixelGetColor Function then hide it and get it

back to it's original position

Edited by komalo

[font="Palatino Linotype"][size="3"]AutoIt Script Examples :[/size][/font][font="Palatino Linotype"][size="3"]_CaptureBehindWindowGlass CMD for Windows Vista/Seven[/size][/font][left][/left][font="Palatino Linotype"][size="3"]Non AutoIt Script programs : Border Skin - Aero Glass On XP[/size][/font]

Share this post


Link to post
Share on other sites

okay , i don't have an answer for you but it is just an idea

your problem starts on hiding the internet explorer window

maybe you can just move the window off screen , show it

and use the PixelGetColor Function then hide it and get it

back to it's original position

so you think i move visible window 2000pixels for right it will be working ?


Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0