Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Modal non-child window causes mdiform application to lose focus

Posted on 2000-03-15
5
Medium Priority
?
436 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 200 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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
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…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
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…
Suggested Courses

722 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