Skip to content

Instantly share code, notes, and snippets.

@kumatti1
Last active January 8, 2021 04:21
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kumatti1/afe2db1147aeadff4af6 to your computer and use it in GitHub Desktop.
Save kumatti1/afe2db1147aeadff4af6 to your computer and use it in GitHub Desktop.
ImageMerge制御
Option Explicit
Declare PtrSafe Function FindWindowEx Lib "user32" Alias "FindWindowExA" (ByVal hWnd1 As LongPtr, ByVal hWnd2 As LongPtr, ByVal lpsz1 As String, ByVal lpsz2 As String) As LongPtr
Declare PtrSafe Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As LongPtr, ByVal wMsg As Long, ByVal wParam As LongPtr, lParam As Any) As LongPtr
Declare PtrSafe Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)
Const WM_SETTEXT = &HC
Const BM_CLICK = &HF5
Const WM_GETTEXT = &HD
Sub Main()
Dim howner As LongPtr
'ImageMergeが未起動なら抜ける
howner = FindWindowEx(0, 0, "TFormMain", "ImageMerge")
If howner = 0 Then Exit Sub
'結合ファイル数
Dim hEdit1 As LongPtr
hEdit1 = FindWindowEx(howner, 0, "TLabeledEdit", vbNullString)
SendMessage hEdit1, WM_SETTEXT, 0, ByVal "20"
'画像を保存するディレクトリ
Dim hEdit2 As LongPtr
hEdit2 = FindWindowEx(howner, hEdit1, "TLabeledEdit", vbNullString)
SendMessage hEdit2, WM_SETTEXT, 0, ByVal "パス"
'画像の保存されているディレクトリ
Dim hEdit3 As LongPtr
hEdit3 = FindWindowEx(howner, hEdit2, "TLabeledEdit", vbNullString)
SendMessage hEdit3, WM_SETTEXT, 0, ByVal "パス"
'実行ボタン押下
Dim hBtn As LongPtr
hBtn = FindWindowEx(howner, 0, "TPanel", vbNullString)
hBtn = FindWindowEx(hBtn, 0, "TBitBtn", "実行")
SendMessage hBtn, BM_CLICK, 0, ByVal 0&
'処理終了を待ち合わせ
Dim hMemo As LongPtr
hMemo = FindWindowEx(howner, 0, "TMemo", vbNullString)
Dim s As String
s = String$(1024, 0)
Do
DoEvents
Sleep 200&
SendMessage hMemo, WM_GETTEXT, Len(s), ByVal s
If s Like "*処理を終了しました。*" Then
Exit Do
End If
Loop
End Sub
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment