|
-
August 29th, 2007, 10:16 AM
#1
How to get hdc and pixel from window with sendmessage?
Hello, I want to get some pixels of a window that doesn't belong to my application, I mean that I have a window of a program and from my own application I want to get pixels of that window.
Well, so I need the hdc and perhaps using that hdc I could get the pixels I want. But I think that perhaps windows doesn't allow you using functions like getDC(hwnd) or getPixel(hdc, x, y) because that window and my application are part of different applications, does it?
So probaly I'll have to use sendmessage winapi function... I'm a bit lost.
There is an application that gives you lots of information about windows only pointing the mouse over the window. It gives hwnd, hdc, name of the class, text... This application is WinID, it is free if you don't use it with commercial purposes. Well if WinID can do it there is at leas one solution.
Well I use VB.NEt but the WinApi works the same so probably I can translate the calls to VB.NET. Someone knows something about it?
-
August 29th, 2007, 11:48 AM
#2
Re: How to get hdc and pixel from window with sendmessage?
-
August 29th, 2007, 01:58 PM
#3
Re: How to get hdc and pixel from window with sendmessage?
Thanks kirants, the solution you posted is quite similar the one I found in other web.
Well I think there must be at leas one way to get the pixel directly from the window, but for the moment I don't know how, so this solution probably could work for me, it stores a copy of the window in a image file so now I have to manage that file to get the pixel I want. I hope not to have many problems
-
August 29th, 2007, 04:43 PM
#4
Re: How to get hdc and pixel from window with sendmessage?
 Originally Posted by fonx
Thanks kirants, the solution you posted is quite similar the one I found in other web.
Well I think there must be at leas one way to get the pixel directly from the window, but for the moment I don't know how, so this solution probably could work for me, it stores a copy of the window in a image file so now I have to manage that file to get the pixel I want. I hope not to have many problems 
If you want to get single pixel from a window look ::GetPixel() api.
Cheers
-
August 30th, 2007, 07:40 AM
#5
Re: How to get hdc and pixel from window with sendmessage?
 Originally Posted by golanshahar
If you want to get single pixel from a window look ::GetPixel() api.
But GetPixel only works if you want to capture pixels of a window of your own application, am I wrong Golanshahar?
-
August 30th, 2007, 03:47 PM
#6
Re: How to get hdc and pixel from window with sendmessage?
 Originally Posted by fonx
But GetPixel only works if you want to capture pixels of a window of your own application, am I wrong Golanshahar?
What you can do is use ::GetPixel() to get pixel from screen dc (0) but for that you have to be sure that the window you want to get the pixel from is visible on the screen.
here is a sample:
Code:
HDC hdc = ::GetDC(0);
HWND hwnd = ::FindWindow(0,"Calculator");
if (hwnd )
{
RECT r;
::GetWindowRect(hwnd,&r);
COLORREF color = ::GetPixel(hdc,r.left+1,r.top+1);
}
::ReleaseDC(0,hdc);
Cheers
-
September 3rd, 2007, 03:10 AM
#7
Re: How to get hdc and pixel from window with sendmessage?
Golanshahar, your solution gets a pixel from the screen (dc=0), the problem of this is that I need to know the exact position of the window on the screen, isn't it? So I have other problem which is to know where is the window that I want.
With the first solution I capture only the window that I want, so I only have to get the pixel I want, I know the exact coordenates x and y where it is. Well I'm using this solution for the moment. Perhaps there is a better solution, but for the moment I'll use this because I want to have the first release (the application is only for me) as soon as possible and then I'll try to improve al the features to the best solution.
This solution has a problem:
The window has to be visible to capture it. If another pop up window appears my solution doesn't work ... For instance my free antivirus throws popup windows....and the application which throws the windows that I want to capture also throws popup messages...
I am wondering If it is possible to know If the window I want to capture is behind other window and if so order the window to move to front position (my english is quite poor, do you understand me?) using the WinApi and sendmessage....is it possible?
-
September 3rd, 2007, 06:17 AM
#8
Re: How to get hdc and pixel from window with sendmessage?
 Originally Posted by golanshahar
Code:
HWND hwnd = ::FindWindow(0,"Calculator");
Well perhaps I'm wrong, your solution find the window that matches with tittle...but I still need that window visible on the screen... :S
-
September 3rd, 2007, 04:13 PM
#9
Re: How to get hdc and pixel from window with sendmessage?
 Originally Posted by fonx
Golanshahar, your solution gets a pixel from the screen (dc=0), the problem of this is that I need to know the exact position of the window on the screen, isn't it? So I have other problem which is to know where is the window that I want.
Yes you need the window to be visible and not covered by any other window and you need to get it bound rect, (I mentioned it in my post )
This solution has a problem:
The window has to be visible to capture it. If another pop up window appears my solution doesn't work  ... For instance my free antivirus throws popup windows....and the application which throws the windows that I want to capture also throws popup messages...
I am wondering If it is possible to know If the window I want to capture is behind other window and if so order the window to move to front position (my english is quite poor, do you understand me?) using the WinApi and sendmessage....is it possible?
In that case read kirants post he gave you an article that can help you capture also "covered" windows 
Cheers
-
September 4th, 2007, 02:19 AM
#10
Re: How to get hdc and pixel from window with sendmessage?
 Originally Posted by golanshahar
In that case read kirants post he gave you an article that can help you capture also "covered" windows 
Well I have to admidt that yesterday I learned what is z-order....I didn't know what it was...
I'm looking this solution, it looks good, now I have (if it's possible) to translate from c++ to vb.net ...
-
September 5th, 2007, 05:44 AM
#11
Re: How to get hdc and pixel from window with sendmessage?
 Originally Posted by fonx
Well I have to admidt that yesterday I learned what is z-order....I didn't know what it was...
I'm looking this solution, it looks good, now I have (if it's possible) to translate from c++ to vb.net ... 
Good luck 
Cheers
-
September 5th, 2007, 05:57 AM
#12
Re: How to get hdc and pixel from window with sendmessage?
Hey Golan I got it !!
I dindn't have to translate your code to VB.NET, just some little changes in my code. Your article put me in the correct way, now I use PrintWindow api call and it works fine, it captures the window even if the window is totally hidden.
Thanks for the help in this point. My application still needs many hours of work and I have more doubts, so I'll continue around CodeGuru Forums for a long time 
Once more thanks
-
July 21st, 2009, 06:44 AM
#13
Re: How to get hdc and pixel from window with sendmessage?
sry for bumping this thread but i have the same problem, could anyone help me get a screenshot from a program that is minimized. Fonx i read u got it fixed u mind sharing?
i already tried using getpixel api to get pixel from programs in the background but it seems getpixel only works if ur window is focussed. And now i have found that printwindow might be the solution. Could anyone help me out?
cheers!
-
August 5th, 2009, 12:03 AM
#14
Re: How to get hdc and pixel from window with sendmessage?
 Originally Posted by soul444
sry for bumping this thread but i have the same problem, could anyone help me get a screenshot from a program that is minimized. Fonx i read u got it fixed u mind sharing?
i already tried using getpixel api to get pixel from programs in the background but it seems getpixel only works if ur window is focussed. And now i have found that printwindow might be the solution. Could anyone help me out?
cheers!
This article shows how to use ::PrintWindow() however minimized window wont work with it.
Cheers
-
August 8th, 2009, 03:01 AM
#15
Re: How to get hdc and pixel from window with sendmessage?
 Originally Posted by golanshahar
This article shows how to use ::PrintWindow() however minimized window wont work with it.
Because this article is wrong.
You must use a hook (among others methods..) to get it from minimized windows..
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|