Solved

Modal non-child window causes mdiform application to lose focus

Posted on 2000-03-15
5
407 Views
Last Modified: 2006-11-17
Hi:

I'm running an MDI application.  I have a routine which requires a modal window to pop up.  After this modal window is closed, my entire application always loses focus and the next application in the MS Windows lineup gains focus instead.  Given that, here's my question...  how can I prevent or workaround this?  Examples or specifics are always nice.

Looking forward to your response.
Thank you.
0
Comment
Question by:ksm
  • 3
  • 2
5 Comments
 
LVL 28

Expert Comment

by:AzraSound
ID: 2621694
you may be able to use the api call SetWindowPos. Put this in a module:


Declare Function SetWindowPos Lib "user32.dll" (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 Const SWP_NOMOVE = &H2
Public Const SWP_NOSIZE = &H1
Public Const HWND_TOP = 0


and you could implement it in this way:

Function StayOnTop(Form As Form)
Dim lFlags As Long
Dim lStay As Long

lFlags = SWP_NOSIZE Or SWP_NOMOVE
lStay = SetWindowPos(Form.hwnd, HWND_TOP, 0, 0, 0, 0, lFlags)
End Function

you could call this in the Unload event of the form that is giving you problems
0
 

Author Comment

by:ksm
ID: 2621865
I actually wrote a "StayOnTop" function a while ago but didn't think to use it here.  I'm not really sure how this would work, though.  There's no use putting this in my modal form, since it's modal and would always be visible anyway.  If I put it in my mdiform, then it would stay on top of all other applications, which would not be good.

Maybe I can try some sort of Zorder call in my mdiform just after the modal window closes.
0
 
LVL 28

Accepted Solution

by:
AzraSound earned 50 total points
ID: 2621877
yes that was what I was suggesting...HWND_TOP will just move it to the top of the Z Order whereas using HWND_TOPMOST leaves it on top permanently. You could implement it in a way that would do what you need it to do i believe by calling something like this after the modal window is closed
0
 

Author Comment

by:ksm
ID: 2621900
Ah, OK.  I was thinking "permanant" when I saw StayOnTop.  Anyhow, I just got done my ZOrder tests and it seems like it's the way to go in this case.  In fact, after I ran the tests, I found an MS article which indicates this...  "For an MDIForm or Form object, ZOrder sends the form to either the front or the back of the screen, depending on the value of position. As a result, forms can be displayed in front of or behind other running applications."

Thanks very much, though.  Thanks for the quick response.
0
 

Author Comment

by:ksm
ID: 2621906
Thanks.
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

Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…

914 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

19 Experts available now in Live!

Get 1:1 Help Now