Solved

message boxes and "always on top" forms

Posted on 2004-08-08
7
214 Views
Last Modified: 2012-08-14
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 ?
0
Comment
Question by:adeljad
  • 4
  • 2
7 Comments
 
LVL 22

Accepted Solution

by:
DarkoLord earned 50 total points
ID: 11746128
Hi, try this:

MsgBox "Hello World", vbApplicationModal

Darko
0
 
LVL 7

Expert Comment

by:Burbble
ID: 11749327
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
0
 
LVL 22

Expert Comment

by:DarkoLord
ID: 11750984
vbApplicationModal should put it on top in all cases...

Darko
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 7

Expert Comment

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

-Burbble
0
 
LVL 7

Expert Comment

by:Burbble
ID: 11763711
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
0
 

Author Comment

by:adeljad
ID: 11776918
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  :(
0
 
LVL 7

Expert Comment

by:Burbble
ID: 11777099
Ahh, ok.

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

-Burbble
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

863 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

25 Experts available now in Live!

Get 1:1 Help Now