Link to home
Start Free TrialLog in
Avatar of adeljad
adeljad

asked on

message boxes and "always on top" forms

When I make a form always on top and then try to show a message box from that form , the message box is displayed behind the form . how can I make the message box appear if front of the form ?
ASKER CERTIFIED SOLUTION
Avatar of DarkoLord
DarkoLord
Flag of Slovenia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
What code are you using? I can't get a message box to be concealed by the form.

Module1
-----
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

Sub KeepOffTop(Form As Form)
    SetWindowPos Form.hWnd, -2, 0, 0, 0, 0, 2 Or 1
End Sub

Sub KeepOnTop(Form As Form)
    SetWindowPos Form.hWnd, -1, 0, 0, 0, 0, 2 Or 1
End Sub
-----

Form1
----
Private Sub Command1_Click()
    MsgBox "hi"
End Sub

Private Sub Form_Load()
    KeepOnTop Me
End Sub

Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer)
    KeepOffTop Me
    Unload Me
    Set Form1 = Nothing
End Sub
-----

Maybe it is an operating system problem? I am using Windows Millenium.

-Burbble
vbApplicationModal should put it on top in all cases...

Darko
True, but there is no reason for the message box being concealed to begin with. Unless it is being called from another form?

-Burbble
Looks like you got it working. I would still like to see why the message box was being concealed, but if it works for you, then I guess that's all that matters :-)

Good luck

-Burbble
Avatar of adeljad
adeljad

ASKER

I think that the code I was using for Keeping on top where wrong

==================================
----------------
-Module1
-----------------
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
Global Const conHwndTopmost = -1
Global Const conHwndNoTopmost = -2
Global Const conSwpNoActivate = &H10
Global Const conSwpShowWindow = &H40
--------------
-Form1
--------------
Private Sub Form_Load()
If mnuStayOnTop.Enabled = True Then
SetWindowPos hWND, conHwndTopmost, 0, 0, 774, 120, conSwpNoActivate Or conSwpShowWindow
Else
mnuStayOnTop.Enabled = False
SetWindowPos hWND, conHwndNoTopmost, 0, 0, 774, 120, conSwpNoActivate Or conSwpShowWindow
End If
End Sub
=====================


It's a wrong code I now when I use the other one it works
I wanted to Accept the tow answers and I didn't now that i have to accept only one
sory  :(
Ahh, ok.

If you want to have the answer "unaccepted" so you can select both, you can post a question in https://www.experts-exchange.com/Community_Support/

-Burbble