Skip to content

Instantly share code, notes, and snippets.

@kumatti1
Created March 23, 2017 03:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kumatti1/4172e69ff8b1e840ed6a415f67f64178 to your computer and use it in GitHub Desktop.
Save kumatti1/4172e69ff8b1e840ed6a415f67f64178 to your computer and use it in GitHub Desktop.
メモ帳のダイアログを閉じる
Option Explicit
'参照設定 UIAutomationClient
Private 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
Sub hoge()
Dim o As IUIAutomation
Dim e As IUIAutomationElement
Set o = New CUIAutomation
Dim h As LongPtr
h = FindWindowEx(0, 0, "#32770", "メモ帳")
If h = 0 Then Exit Sub
Set e = o.ElementFromHandle(ByVal h)
Dim iCnd As IUIAutomationCondition
Set iCnd = o.CreatePropertyCondition(UIA_NamePropertyId, "保存する(S)")
Dim Button As IUIAutomationElement
Set Button = e.FindFirst(TreeScope_Subtree, iCnd)
Dim InvokePattern As IUIAutomationInvokePattern
Set InvokePattern = Button.GetCurrentPattern(UIA_InvokePatternId)
InvokePattern.Invoke
End Sub
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment