tagCANDY CGI VBレスキュー(花ちゃん)の Visual Basic 6.0用 掲示板
VBレスキュー(花ちゃん)の Visual Basic 6.0用 掲示板
[ツリー表示へ]  [ワード検索]  [Home]

タイトル Re^3: 2重起動の後優先
投稿日: 2008/06/23(Mon) 14:37
投稿者コーヒーブレイク
新規プロジェクトにて以下のコードで行ってみましたが、やはり
終了は出来ないようです。

何か良い手法ないでしょうか?


-----------------------------------------------------------------
Attribute VB_Name = "Module1"
Option Explicit

'クラス名又はキャプションタイトルを与えて
'ウインドウのハンドルを取得する(P81)
Private Declare Function FindWindow Lib "user32" _
    Alias "FindWindowA" (ByVal lpClassName As String, _
    ByVal lpWindowName As String) As Long

'指定のウインドウにメッセージを送る(P750)
Private Declare Function SendMessage Lib "user32" _
    Alias "SendMessageA" (ByVal hwnd As Long, _
    ByVal wMsg As Long, ByVal wParam As Long, _
        lParam As Any) As Long
'アプリケーションをクローズする時
'ウインドウに送られるメッセージ(P835)
Private Const WM_CLOSE As Long = &H10
Dim strClassName   As String  'クラス名
Dim strCaptionName As String  'キャプション名


Sub main()
'ハンドル取得及び終了処理のサブプロシージャ
    Dim hwnd As Long
    Dim ret As Long
    
'    If Len(strClassName) Then
'        'クラス名を与えてハンドルを取得
'        '起動中ならハンドルが返り、起動していなければ 0 が返る
'        hwnd = FindWindow(strClassName, vbNullString)
'    ElseIf Len(strCaptionName) Then
        'キャプション名を与えてハンドルを取得する場合
        'strCaptionName = "Microsoft Excel - Book1"  '電卓の場合  "電卓"

    If App.hInstance = True Then
                
        strCaptionName = Frm_Main.Caption
        hwnd = FindWindow(vbNullString, strCaptionName)
'    End If
    '指定のハンドルに終了のメッセージを送る
        ret = SendMessage(hwnd, WM_CLOSE, 0&, 0&)

    Else
        Frm_Main.Show
    End If
End Sub

- 関連一覧ツリー をクリックするとツリー全体を一括表示します)

古いスレッドにレスはつけられません。