投稿日 | : 2007/01/26(Fri) 00:52 |
投稿者 | : sakusaku |
Eメール | : |
URL | : |
タイトル | : [解決] 画面上のある点の色の取得 |
とりあえずこんな感じでフォーム以外の色も取れそうなんで解決とします
(まだ色のコードは取れてないですが)
Option Explicit
'位置座標を受け取る構造体
Private Type POINTAPI
x As Long
y As Long
End Type
'現在のマウスカーソルの位置座標を取得する
Private Declare Function GetCursorPos Lib "user32" _
(lpPoint As POINTAPI) As Long
Private MoP As POINTAPI '現在のマウスポインタの位置座標
Private Declare Function GetDC Lib "user32" _
(ByVal hwnd As Long) As Long
Private Declare Function WindowFromPoint Lib "user32" _
(ByVal xPoint As Long, ByVal yPoint As Long) As Long
Private Declare Function GetPixel Lib "gdi32.dll" _
(ByVal hTargetDC As Long, ByVal x As Long, ByVal y As Long) As Long
Dim MyColor
Dim hTargetDC As Long
Dim hTargetWin As Long
Private Sub Form_Load()
Timer3.Interval = 500 'ミリ秒で指定
End Sub
Private Sub Timer3_Timer()
hTargetWin = WindowFromPoint(0, 0)
hTargetDC = GetDC(hTargetWin)
GetCursorPos MoP
Labelx.Caption = MoP.x
Labely.Caption = MoP.y
MyColor = GetPixel(hTargetDC, MoP.x, MoP.y)
Label4.Caption = MyColor
End Sub