Home > Software engineering >  Form has been obtained by GetPixel (UseForm) on a certain point the RGB values, after the operation
Form has been obtained by GetPixel (UseForm) on a certain point the RGB values, after the operation

Time:09-16

VBA, built a form (UserForm) call simple API
Returns the RGB values form a fixed position, how can after running the program, the mouse to click other applications, trigger mousemove will change again?
HDC every time change can understand why, form the return value of a certain color can change? I tried a photo is inserted in the form in results.
I understand GetPixel earned a form 50100 colors, the damage form itself does not change, the obtained RGB value should not change?

The Module class code is as follows:
Public Declare Function GetDC Lib "user32" (ByVal HWND) As Long As Long
Public Declare Function ReleaseDC Lib "user32" (ByVal HWND As Long, ByVal HDC) As Long As Long
Public Declare Function GetPixel Lib "gdi32" (ByVal HDC As Long, ByVal x As Long, ByVal y As Long) As Long
Public Colorval& Red& Green& Blue&
Public Sub GetRGB (cc As Long)
Red=cc Mod 256
Green=(cc Mod 256) Mod 256
Blue=256 cc Mod Mod 256
End Sub


Form UserForm code is as follows:
Private Sub UserForm_MouseMove (ByVal Button As an Integer, ByVal Shift As an Integer, ByVal x As Single, ByVal y As Single)
HDC=GetDC (UserForm)
'HDC=GetDC HDC to achieve zero (0), the results also such.
Colorval=GetPixel (HDC, 50, 100)
Call GetRGB (Colorval)
Me. The Caption=CStr (Colorval) & amp; "Red point:" & amp; CStr (Red) & amp; "Green point:" & amp; CStr (Green) & amp; "Blue point:" & amp; CStr (Blue) & amp; "HDC value:" & amp; HDC
ReleaseDC UserForm, HDC
End Sub
Private Sub UserForm_load ()
Me. The scalemode=3
End Sub

Direct run results (the mouse to click on other programs)


After the operation, the mouse to click on IE or other programs, for example, first to trigger the form mousemove (look for the Red/Green/Blue point these three values changed!!! )

CodePudding user response:

Which give directions, thank you very much!
  •  Tags:  
  • API
  • Related