ディスプレイ上の指定点座標を含むハンドルを取得 <TOP>
MonitorFromPoint 指定の点座標を含むディスプレイモニターのハンドルを取得
ClientToScreen 指定されたウィンドウ上の点の座標を、クライアント領域の座標からスクリーン座標に変換
例では、モニタ座標(0,0)を指定しています。
'================================================================ '= ディスプレイ上の指定点座標を含むハンドル取得 '= (MonitorFromPoint.bas) '================================================================ #include "Windows.bi" #define MONITOR_DEFAULTTONULL &H0 '0を返す #define MONITOR_DEFAULTTOPRIMARY &H1 '主モニターのハンドルを返す #define MONITOR_DEFAULTTONEAREST &H2 '最も近いモニターのハンドルを返す Type POINTAPI x As Long y As Long End Type ' 指定の点座標を含むディスプレイモニターのハンドルを取得 Declare Function Api_MonitorFromPoint& Lib "user32" Alias "MonitorFromPoint" (ByVal x&, ByVal y&, ByVal dwFlags&) ' 指定されたウィンドウ上の点の座標を、クライアント領域の座標からスクリーン座標に変換 Declare Function Api_ClientToScreen& Lib "user32" Alias "ClientToScreen" (ByVal hWnd&, lpPoint As POINTAPI) Var Shared Text1 As Object Var Shared Button1 As Object Text1.Attach GetDlgItem("Text1") : Text1.SetFontSize 14 Button1.Attach GetDlgItem("Button1") : Button1.SetFontSize 14 ShowWindow -1 '================================================================ '= '================================================================ Declare Function GetMonitorByPoint(x As Single, y As Single) As Long Function GetMonitorByPoint(x As Single, y As Single) As Long Var pt As POINTAPI Var Ret As Long pt.x = x pt.y = y Ret = Api_ClientToScreen(GethWnd, pt) GetMonitorByPoint = Api_MonitorFromPoint(pt.x, pt.y, MONITOR_DEFAULTTONEAREST) End Function '================================================================ '= '================================================================ Declare Sub Button1_on edecl () Sub Button1_on() Var hMonitor As Long Var x As Single Var y As Single x = 0 y = 0 hMonitor = GetMonitorByPoint(x, y) Text1.SetWindowText "Monitor Handle = &&H" & Hex$(hMonitor) End Sub '================================================================ '= '================================================================ While 1 WaitEvent Wend Stop End