View Single Post
  #3   Report Post  
Posted to microsoft.public.excel.programming
Michel Pierron Michel Pierron is offline
external usenet poster
 
Posts: 214
Default Extracting Colors from Image loaded in userform

Hi Emsfeld,
In the UserForm Module:
Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" _
(ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Private Declare Function GetDC Lib "user32" (ByVal hWnd As Long) As Long
Private Declare Function GetPixel Lib "gdi32" (ByVal hDC As Long _
, ByVal X As Long, ByVal Y As Long) As Long
Private hDC As Long

Private Sub UserForm_Activate()
hDC = GetDC(FindWindow(vbNullString, Me.Caption))
End Sub

Private Sub UserForm_MouseMove(ByVal Button As Integer _
, ByVal Shift As Integer, ByVal X As Single, ByVal Y As Single)
Label1.Caption = "X= " & X & " Y= " & Y
Dim Color As Long
Color = GetPixel(hDC, X * 4 / 3, Y * 4 / 3)
Label2.Caption = "&H" & Hex(Color)
Label3.BackColor = Label2.Caption
End Sub

Regards,
MP

"emsfeld " a écrit dans le message
de ...
Hi Guys,

I am new to programming in Excel VBA, so I am quite
unexperienced....Anyways, I would like to extract the colors of pixels
of an image that'd been loaded into an userform. I am kinda stuck on
this and got no clue how to do that. I have been searching the web on
this for three days, but couldnt find anything....

Help would be appreciated a lot

emsfeld


---
Message posted from http://www.ExcelForum.com/