Excel VBA質問スレ Pa ..
[2ch|▼Menu]
477:デフォルトの名無しさん
09/01/09 03:10:36
>>473
穴だらけのコードだけど、とりあえず…
環境依存かもしれない

Option Explicit

Declare Function GetWindowText Lib "user32" Alias "GetWindowTextA" (ByVal hwnd As Long, ByVal lpString As String, ByVal cch As Long) As Long
Declare Function GetClassName Lib "user32" Alias "GetClassNameA" (ByVal hwnd As Long, ByVal lpClassName As String, ByVal nMaxCount As Long) As Long
Declare Function EnumWindows Lib "user32" (ByVal lpEnumFunc As Long, ByVal lParam As Long) As Long
Declare Function PostMessage Lib "user32" Alias "PostMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
Public Const GW_HWNDLAST = 1
Public Const GW_HWNDNEXT = 2
Public Const WM_CLOSE = &H10
Public Const ml = 255
Dim wh1 As Long

' コールバック関数
Public Function EnumWindowsProc(ByVal Handle As Long, ByVal lParam As Object) As Long
  Dim strClassName As String * ml
  Dim strCaption As String * ml
  GetClassName Handle, strClassName, ml  ' クラス名取得
  GetWindowText Handle, strCaption, ml    ' キャプション取得
  If Left(strClassName, 7) = "IEFrame" And Mid(strCaption, 4, 22) = "Documents and Settings" Then wh1 = Handle
  EnumWindowsProc = True
End Function

Private Sub test1() '「ブラウザでプレビュー」を閉じる
  wh1 = 0
  Dim Ret As Long
  Ret = EnumWindows(AddressOf EnumWindowsProc, ByVal 0&)
  If wh1 <> 0 Then Call PostMessage(wh1, WM_CLOSE, 0, 0)
End Sub


次ページ
最新レス表示
スレッドの検索
類似スレ一覧
話題のニュース
おまかせリスト
▼オプションを表示
暇つぶし2ch

5142日前に更新/259 KB
担当:undef