Solved

Modal non-child window causes mdiform application to lose focus

Posted on 2000-03-15
5
423 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
VBA filters 2 81
Recommendation vb6 to vb.net or others 14 240
Child Form in front 4 65
VB6 - Scroll Mouse wheel on Picturebox 13 120
When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
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 …
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
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…

734 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