|
こんばんわ。
↓これの続きってことなんかな?
http://www.vbalab.net/vbaqa/c-board.cgi?cmd=ntr;tree=39008;id=excel
ま、出来へんことはないんやけど・・・
(標準モジュール)------------------------------------------------------------------------
Public Declare Function GetForegroundWindow Lib "user32" () As Long
Public Declare Function SetForegroundWindow Lib "user32" (ByVal hWnd As Long) As Long
Public Declare Function GetActiveWindow Lib "user32" () As Long
Public Declare Function SetWindowPos Lib "user32" _
(ByVal hWnd As Long, _
ByVal hWndInsertAfter As Long, _
ByVal X As Long, _
ByVal Y As Long, _
ByVal cx As Long, _
ByVal cy As Long, _
ByVal wFlags As Long) As Long
Public Declare Function FindWindow Lib "user32" _
Alias "FindWindowA" _
(ByVal lpszClassName As String, _
ByVal lpszWindow As String) As Long
Public Const SWP_NOMOVE = &H2
Public Const SWP_NOSIZE = &H1
Public Const SWP_NOACTIVATE = &H10
Public Const HWND_TOPMOST = -1
Public Const HWND_NOTOPMOST = -2
Public Flg As Boolean
Public Sub test()
Flg = False
UserForm1.Show vbModeless
End Sub
Public Sub SetTopMost()
Dim hWnd As Long
hWnd = FindWindow("ThunderDFrame", UserForm2.Caption)
SetWindowPos hWnd, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOMOVE Or SWP_NOSIZE Or SWP_NOACTIVATE
End Sub
Public Sub ActivateForm(ByRef FormCaption As String)
Dim hWnd As Long
hWnd = FindWindow("ThunderDFrame", FormCaption)
If hWnd <> GetForegroundWindow() Then
SetForegroundWindow hWnd
End If
End Sub
(UserForm1)-------------------------------------------------------------------------------
Private Sub CommandButton1_Click()
Flg = True
UserForm2.Show vbModeless
End Sub
Private Sub CommandButton1_MouseMove(ByVal Button As Integer, ByVal Shift As Integer, ByVal X As Single, ByVal Y As Single)
ActivateForm Me.Caption
End Sub
Private Sub UserForm_Activate()
If Flg Then SetTopMost
End Sub
Private Sub UserForm_MouseMove(ByVal Button As Integer, ByVal Shift As Integer, ByVal X As Single, ByVal Y As Single)
ActivateForm Me.Caption
End Sub
Private Sub UserForm_Terminate()
Unload UserForm2
End Sub
(UserForm2)-------------------------------------------------------------------------------
Private Sub UserForm_Activate()
Dim hWnd As Long
hWnd = GetActiveWindow()
SetWindowPos hWnd, HWND_NOTOPMOST, 0, 0, 0, 0, SWP_NOMOVE Or SWP_NOSIZE
End Sub
Private Sub UserForm_MouseMove(ByVal Button As Integer, ByVal Shift As Integer, ByVal X As Single, ByVal Y As Single)
ActivateForm Me.Caption
End Sub
Private Sub UserForm_Terminate()
Flg = False
End Sub
但し、実際はユーザーフォーム上にあるすべてのコントロールのMouseMoveイベントで
ActivateForm Me.Captionを実行する必要があります。
それに、試したみたらわかると思うけど、ちかちかしてそんなにええもんとちゃいまっせ。
ま、お好みでっけど・・・
ほな。
|
|