| マウスの移動範囲を制限する方法(API関数ClipCursorの使用例) | |||||
| 動作環境 | Windows95/98 | 開発環境 | Visual Basic 6.0 (+SP3) | ||
| 説明 | API関数ClipCursorを使用して、マウスの移動範囲をフォーム内に制限します。 | ||||
| 用意するもの:標準フォーム(Form1)、コマンドボタン(Command1,Command2) | |||||
| '変数の明示的な宣言を強制します。 Option Explicit 'API関数ClipCursorの利用を宣言します。 Private Declare Function ClipCursor Lib "user32" (lpRect As Any) As Long 'マウスの移動範囲である矩形の四点の座標を格納するRECT構造体。 Private Type RECT Left As Long Top As Long Right As Long Bottom As Long End Type 'RECT型の変数:API関数の引数に指定するもの。 Dim MyRect As RECT Private Sub Command1_Click() 'API関数の戻り値 Dim ret As Long 'マウスの移動範囲である矩形の四点をPixel単位で指定します。 '(ここではフォームのサイズを指定しています) With MyRect .Left = (Form1.Left) / Screen.TwipsPerPixelX .Top = (Form1.Top) / Screen.TwipsPerPixelY .Right = (Form1.Left + Form1.Width) / Screen.TwipsPerPixelX .Bottom = (Form1.Top + Form1.Height) / Screen.TwipsPerPixelY End With 'マウスの移動範囲を制限します。 ret = ClipCursor(MyRect) End Sub Private Sub Command2_Click() 'API関数の戻り値 Dim ret As Long 'マウスの移動範囲の制限を解除します。 ret = ClipCursor(ByVal 0&) End Sub Private Sub Form_Load() Form1.Caption = "マウスの移動範囲を制限する方法" Command1.Caption = "マウスの移動範囲を制限" Command2.Caption = "マウスの移動範囲の制限を解除" End Sub |
|||||