LoginSignup
1
1

More than 5 years have passed since last update.

AutoItからDLLを使う

Posted at

AutoItからdllを呼び出して使ってみる。
サンプルとして、user32.dllの関数を呼び出して、アクティブウインドウのサイズを取得してみる。

サンプルコード

CallUser32.au3
;---------------------------------------------
;アクティブウインドウのサイズを取得してみる
;---------------------------------------------

$user32 = DllOpen("user32.dll")

;座標値を入れる構造体を作成
$srect = "long left; long top; long right; long bottom"
$testrect = DllStructCreate($srect)

;初期化
DllStructSetData($testrect, "left", 0)
DllStructSetData($testrect, "top", 0)
DllStructSetData($testrect, "right", 0)
DllStructSetData($testrect, "bottom", 0)

;アクティブウインドウのハンドルを取得
$activehwnd = DllCall($user32, "HWND", "GetForegroundWindow")

;アクティブウインドウのウインドウサイズを取得し$testrectに
$rect = DllCall($user32, "bool", "GetClientRect", "HWND", $activehwnd[0], "ptr", DllStructGetPtr($testrect))

;画面に座標を表示
$right =  DllStructGetData($testrect, "right")
$bottom = DllStructGetData($testrect, "bottom")
MsgBox(0, "CallUser32.dll", "右下の相対座標は(" & $right & "," & $bottom & ")")

;公式で推奨されているのでClose
DllClose($user32)

ここでは左上端と右下端の座標値を取得しているが、
座標値は相対座標になっている。つまり左上端の座標値は常に(0,0)。
ということは、アクティブウインドウの右下端の座標値がアクティブウインドウの大きさですね。

参考

1
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1