指定したウィンドウを最前面に <TOP>
異なるアプリケーションを最前面に表示させます。(Windows2000/XP)
送信部
GetProp ウィンドウに関するプロパティを取得
FindWindowクラス名またはキャプションを与えてウィンドウのハンドルを取得
AllowSetForegroundWindow 指定したプロセスにフォアグラウンドウィンドウを設定

受信部
SetForegroundWindow フォアグラウンドウィンドウの設定
SetProp ウィンドウに関するプロパティを設定
GetCurrentProcessId 現在のプロセスのプロセスIDを取得
タイマーを貼り付けます。
起動後他のアプリケーションで受信部フォームを隠します。タスクバー上で点滅し起動の確認ができています。
![]()
送信部のボタンをクリックすることにより受信部フォームが最前面に表示されます。

※Windows98では受信部フォームが常時最前面に表示されます。
'================================================================ '= 指定したウィンドウを最前面に(送信部:Window2000/XP) '= SetForegroundWindowRecとセット
'= (SetForegroundWindowSend.bas) '================================================================ #include "Windows.bi" ' ウィンドウに関するプロパティを取得 Declare Function Api_GetProp& Lib "user32" Alias "GetPropA" (ByVal hWnd&, ByVal lpString$) ' クラス名またはキャプションを与えてウィンドウのハンドルを取得 Declare Function Api_FindWindow& Lib "user32" Alias "FindWindowA" (ByVal lpClassName$, ByVal lpWindowName$) ' 指定したプロセスにフォアグラウンドウィンドウを設定 Declare Function Api_AllowSetForegroundWindow& Lib "user32" Alias "AllowSetForegroundWindow" (ByVal dwProcessId&) '================================================================ '= '================================================================ Declare Sub Button1_on edecl () Sub Button1_on() Var hWnd As Long Var hProcessID As Long Var Ret As Long
'キャプションが"SetForegroundWindow受信部"であるウィンドウのハンドルを取得
hWnd = Api_FindWindow(ByVal 0, "SetForegroundWindow受信部")
If hWnd = 0 Then
A% = MessageBox("", "目的ウィンドウは見つかりません!", 0, 2)
Exit Sub
End If
hProcessID = Api_GetProp(hWnd, "ProcessID")
Ret = Api_AllowSetForegroundWindow(hProcessID)
End Sub
'================================================================
'=
'================================================================
While 1
WaitEvent
Wend
Stop
End
'================================================================
'= 指定したウィンドウを最前面に(受信部:Window2000/XP)
'= SetForegroundWindowSend とセット
'= (SetForegroundWindowRec.bas)
'================================================================ #include "Windows.bi" ' フォアグラウンドウィンドウの設定 Declare Function Api_SetForegroundWindow& Lib "user32" Alias "SetForegroundWindow" (ByVal hWnd&) ' ウィンドウに関するプロパティを設定 Declare Function Api_SetProp& Lib "user32" Alias "SetPropA" (ByVal hWnd&, ByVal lpString$, ByVal hData&) ' 現在のプロセスのプロセス ID を取得 Declare Function Api_GetCurrentProcessId& Lib "kernel32" Alias "GetCurrentProcessId" () Var Shared Timer1 As Object
Timer1.Attach GetDlgItem("Timer1")
'================================================================
'=
'================================================================
Declare Sub MainForm_Start edecl ()
Sub MainForm_Start()
Var Ret As Long
SetWindowText "SetForegroundWindow受信部"
Ret = Api_SetProp(GethWnd, "ProcessID", Api_GetCurrentProcessId)
Timer1.SetInterval 10
Timer1.Enable -1
End Sub
'================================================================
'=
'================================================================
Declare Sub Timer1_Timer edecl ()
Sub Timer1_Timer()
Var Ret As Long
Ret = Api_SetForegroundWindow(GethWnd)
End Sub
'================================================================
'=
'================================================================
While 1
WaitEvent
Wend
Stop
End