I'm puzzled,
I have a application (with invisible form) that runs at startup.
Trigered by some event it can display a message box.
The first time this message box will be behind the active application.
All next times the messagebox will go in front of the active application.
I tried lots of things to get the messagebox the first time in front of the application.
See the code below. Nothing worked. Does anyone have an idea?
Code:Const SWP
SHOWWINDOW = &H40
Const HWNDTOPMOST = -1
Const SW_SHOWNORMAL = 1
Public Declare Function ShowWindow Lib "user32" (ByVal hwnd As Long, ByVal nCmdShow As Long) As Long
Public Declare Function BringWindowToTop Lib "user32" (ByVal hwnd As Long) As Long
Public Declare Function SetForegroundWindow Lib "user32" (ByVal hwnd As Long) As Long
Public Declare Function SetFocus Lib "user32" (ByVal hwnd As Long) As Long
Public Declare Function SetActiveWindow Lib "user32.dll" (ByVal hwnd As Long) 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 Sub activateWindow()
' Atempt 1
frmStartup.Visible = True
frmStartup.Show
DoEvents
' Atempt 2
ShowWindow frmStartup.hwnd, SWSHOWNORMAL
' Atempt 3
SetWindowPos frmStartup.hwnd, HWNDTOPMOST, 9999, 1, 1, 1, SWP_SHOWWINDOW
' Atempt 4
BringWindowToTop frmStartup.hwnd
' Atempt 5
SetActiveWindow frmStartup.hwnd
' Atempt 6
SetForegroundWindow frmStartup.hwnd
' Atempt 7
SetFocus frmStartup.hwnd
End Sub
Enter your message below
Sign in or Join us (it's free).