カーソル情報を取得          <TOP>


指定した個所のカーソルに関する情報を取得します。

GetCursorInfo グローバルカーソルの情報を取得

DrawIcon アイコンを描画

GetDC デバイスコンテキストのハンドルを取得 GetDC

ReleaseDC デバイスコンテキストを解放

 

カーソルで指定した個所のカーソルおよびハンドルを表示させています。

 

'================================================================
'= カーソル情報を取得
'=    (GetCursorInfo.bas)
'================================================================
#include "Windows.bi"

Type POINTAPI
    x As Long
    y As Long
End Type

Type CURSORINFO
    cbSize      As Long
    flags       As Long
    hCursor     As Long
    ptScreenPos As POINTAPI
End Type

' グローバルカーソルに関する情報を取得
Declare Function Api_GetCursorInfo& Lib "user32" Alias "GetCursorInfo" (pci As CURSORINFO)

' アイコンを描画
Declare Function Api_DrawIcon& Lib "user32" Alias "DrawIcon" (ByVal hDC&, ByVal x&, ByVal y&, ByVal exhIcon&)

' 指定されたウィンドウのクライアント領域または画面全体を表すディスプレイデバイスコンテキストのハンドルを取得
Declare Function Api_GetDC& Lib "user32" Alias "GetDC" (ByVal hWnd&)

' デバイスコンテキストを解放
Declare Function Api_ReleaseDC& Lib "user32" Alias "ReleaseDC" (ByVal hWnd&, ByVal hDC&)

Var Shared Picture1 As Object
Var Shared Text1 As Object
Var Shared Timer1 As Object

Picture1.Attach GetDlgItem("Picture1")
Text1.Attach GetDlgItem("Text1") : Text1.SetFontSize 14
Timer1.Attach GetDlgItem("Timer1")

Var Shared hDC As Long

'================================================================
'=
'================================================================
Declare Sub MainForm_Start edecl ()
Sub MainForm_Start()
    hDC = Api_GetDC(Picture1.GethWnd)
    Timer1.SetInterval 10
    Timer1.Enable -1
End Sub

'================================================================
'=
'================================================================
Declare Sub Timer1_Timer edecl ()
Sub Timer1_Timer()
    Var ci As CURSORINFO
    Var Ret As Long

    ci.cbSize = Len(ci)

    Ret = Api_GetCursorInfo(ci)

    Text1.SetWindowText Str$(ci.hCursor)

    Picture1.Cls
    Ret = Api_DrawIcon(hDC, 0, 0, ci.hCursor)
End Sub

'================================================================
'=
'================================================================
Declare Sub MainForm_QueryClose edecl ()
Sub MainForm_QueryClose()
    Var Ret As Long

    Ret = Api_ReleaseDC(Picture1.GethWnd, hDC)
End Sub

'================================================================
'=
'================================================================
While 1
    WaitEvent
Wend
Stop
End