1、设计一个半透明窗体后,我想让该窗体把鼠标事件“让”给被它盖着的窗口(注:这个窗口可能是windows的其他程序或者桌面),请问这一步怎么实现?
2、如何得到屏幕上任意一个点的颜色属性值?这个点可以不在窗体内?有没有API函数实现该功能?我看过有可以复制图形的,可是似乎并没有返回一个像素点的颜色属性值。暂时先请教这两个问题,谢谢!
2、如何得到屏幕上任意一个点的颜色属性值?这个点可以不在窗体内?有没有API函数实现该功能?我看过有可以复制图形的,可是似乎并没有返回一个像素点的颜色属性值。暂时先请教这两个问题,谢谢!
Private Type POINTAPI
x As Long
y As Long
End Type
Private Declare Function BitBlt Lib "gdi32" (ByVal hDestDC As Long, ByVal x As Long, ByVal y As Long, ByVal nWidth As Long, ByVal nHeight As Long, ByVal hSrcDC As Long, ByVal xSrc As Long, ByVal ySrc As Long, ByVal dwRop As Long) As Long
Private Declare Function GetCursorPos Lib "user32" (lpPoint As POINTAPI) 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 Declare Function ScreenToClient Lib "user32" (ByVal hwnd As Long, lpPoint As POINTAPI) As Long
Private Declare Function WindowFromPoint Lib "user32" (ByVal xPoint As Long, ByVal yPoint As Long) As LongPrivate Sub Form_Load()
Timer1.Interval = 500
End SubPrivate Sub Timer1_Timer()
Static lX As Long, lY As Long
On Local Error Resume Next
Dim P As POINTAPI, h As Long, hD As Long, c As Long
Dim R As Long, G As Long, B As Long
GetCursorPos P
If P.x = lX And P.y = lY Then Exit Sub
lX = P.x: lY = P.y
h = WindowFromPoint(lX, lY)
hD = GetDC(h)
ScreenToClient h, P c = GetPixel(hD, P.x, P.y) R = c And &HFF
G = (c And &HFF00&) / &H100&
B = (c And &HFF0000) / &H10000
Me.BackColor = RGB(R, G, B)
End Sub
Const LWA_COLORKEY = &H1
Const LWA_ALPHA = &H2
Const GWL_EXSTYLE = (-20)
Const WS_EX_LAYERED = &H80000
Const WS_EX_TRANSPARENT As Long = &H20&
Private Declare Function GetWindowLong Lib "user32" Alias "GetWindowLongA" (ByVal hWnd As Long, ByVal nIndex As Long) As Long
Private Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" (ByVal hWnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long
Private Declare Function SetLayeredWindowAttributes Lib "user32" (ByVal hWnd As Long, ByVal crKey As Long, ByVal bAlpha As Byte, ByVal dwFlags As Long) As LongPrivate Sub Form_Load()
Dim Ret As Long
Ret = GetWindowLong(Me.hWnd, GWL_EXSTYLE)
Ret = Ret Or WS_EX_LAYERED Or WS_EX_TRANSPARENT
SetWindowLong Me.hWnd, GWL_EXSTYLE, Ret SetLayeredWindowAttributes Me.hWnd, 0, 200, LWA_ALPHA
End Sub