タイトル | : Re^7: 2重起動の後優先 |
記事No | : 12623 |
投稿日 | : 2008/06/23(Mon) 15:44 |
投稿者 | : YK |
こんにちは。 テストで作ってみました。 VBのフォームが他にあればそちらも対象になります。 スタートアップを Sub Main にして下さい。
Option Explicit Declare Function EnumWindows Lib "user32.dll" _ (ByVal lpEnumFunc As Long, _ ByVal lParam As Long) As Long
Declare Function GetClassName Lib "user32.dll" _ Alias "GetClassNameA" _ (ByVal hwnd As Long, _ ByVal lpClassName As String, _ ByVal nMaxCount As Long) As Long
Declare Function GetWindowText Lib "user32.dll" _ Alias "GetWindowTextA" _ (ByVal hwnd As Long, _ ByVal lpString As String, _ ByVal nMaxCount As Long) As Long
Public 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 WM_CLOSE = &H10 Dim AppFlag As Boolean Dim ApphWnd As Long
' コールバック関数 Function EnumWindowsProc(ByVal hwnd As Long, _ lParam As Long) As Long Dim strClassBuff As String * 128 Dim strClass As String Dim strTextBuff As String * 516 Dim strText As String Dim lngRtn As Long Dim lngStyle As Long ' クラス名をバッファに lngRtn = GetClassName(hwnd, strClassBuff, Len(strClassBuff)) ' クラス名取得 strClass = Left(strClassBuff, InStr(strClassBuff, vbNullChar) - 1) If strClass = "ThunderRT6FormDC" Then AppFlag = True ApphWnd = hwnd EnumWindowsProc = False Exit Function End If ' 列挙を継続 EnumPass: EnumWindowsProc = True End Function
Public Sub Main() Dim lngRtn As Long If App.PrevInstance Then lngRtn = EnumWindows(AddressOf EnumWindowsProc, 0&) If ApphWnd > 0 And AppFlag Then lngRtn = PostMessage(ApphWnd, WM_CLOSE, 0&, 0&) End If Form1.Text1.Text = "BBBB" Else Form1.Text1.Text = "AAAA" End If Form1.Show End Sub
|