How do I find the hwnd of an Image?

S

schlefty

Here is what I am trying to do. I need to grab the color from a pixel
that I have loaded to an Image on the form.
I am using this function to grab the pixel:

Private Declare Function GetPixel Lib "GDI32" (ByVal hDC As Long, ByVal
X As Long, ByVal Y As Long) As Long
Which means that I need the hDC of the image. In order to do that I am
using this function:

Private Declare Function GetDC Lib "user32" (ByVal hWnd As Long) As
Long
Which means that I need the hWnd of the image, but I can't find it
anywhere. I've tried using this function to grab it:

Private Declare Function FindWindow Lib "user32" Alias "FindWindowA"
(ByVal lpClassName As String, ByVal lpWindowName As String) As Long
But this function requires the caption of the Image, but Images in VBA
don't use captions. Is there any other way for me to find the hWnd of
the image? I can't simply use the hWnd of the form because my GetPixel
function won't grab the pixel from the image, only from the form
itself. I'm at a loss. Any help would be great.

Thanks
 
J

JoAnn Paules [MVP]

Wow. I've found the hex number of a color that I wanted and I didn't have to
jump thru hoops of fire with poisonous snakes slithering under them. That's
what your process sounds like to me. :-(

Is there a reason you're going thru all of that?



--

JoAnn Paules
MVP Microsoft [Publisher]

~~~~~
How to ask a question
http://support.microsoft.com/KB/555375
 
E

Ed Bennett

JoAnn said:
Wow. I've found the hex number of a color that I wanted and I didn't have to
jump thru hoops of fire with poisonous snakes slithering under them. That's
what your process sounds like to me. :-(

Is there a reason you're going thru all of that?

Well, there's a reason this group is called .programming.

Unfortunately, I have no idea either, so it's doubtful the question is
going to get answered.

(schlefty, you are working in Microsoft Publisher VBA, yes?)
 
S

Susanne Wenzel

Am 25 Jan 2007 07:00:38 -0800 schrieb schlefty:

[description partially snipped]
Private Declare Function GetDC Lib "user32" (ByVal hWnd As Long) As
Long
Which means that I need the hWnd of the image, but I can't find it
anywhere. I've tried using this function to grab it:
Private Declare Function FindWindow Lib "user32" Alias "FindWindowA"
(ByVal lpClassName As String, ByVal lpWindowName As String) As Long
But this function requires the caption of the Image, but Images in VBA
don't use captions. Is there any other way for me to find the hWnd of
the image?

I once had a similar problem, I needed the hwnd of a printer and vba did
not offer it. I used a function called CreateDC and it worked for me.

You find it here:
http://www.allapi.net/apilist/CreateDC.shtml

(But as I said, it was for a printer).

Maybe this gives you ideas. Another place to ask concerning API-Functions
is here:

microsoft.public.vb.winapi

And I recall that we once used a (grahical) program to find out about
hwnds, as far as I remember. If you're interested in the name of that
program I'll try to find out (I don't have that at home).

HTH

Greetings from Germany
Susanne
 
E

Ed Bennett

JoAnn said:
It just seems like such a long way around the process to find a color. Call
me silly.

Yes, but if the program needs the colour to do something with, then it
has to be able to find it on its own - it can't have you sitting there
and clicking to find the colours and then telling it. Unless you're
volunteering...
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top