Solved

Modal non-child window causes mdiform application to lose focus

Posted on 2000-03-15
5
420 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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
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…
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…

763 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