Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations John Tel on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Launching a modal form from a top-level form

Status
Not open for further replies.

Mike Lewis

Programmer
Jan 10, 2003
17,516
Scotland
Just come across an interesting problem. I wonder if anyone else has seen this.

1. The application has a main form that runs in the main VFP window in the usual way (in other words, the main form's ShowWindow is "1 In Screen").

2. The main form launches a top-level form (ShowWindow = 2 - As Top-Level Form), with its own taskbar button.

3. The top-level form launches a modal form. Because I want the modal form to be contained within the bounds of the top-level form, I set its ShowWindow to "1 In Top-Level Form".

So far, no problem. Everything works as expected.

But what if the user switches back to the main form (via Alt-Tab or the Windows taskbar) while the modal form is open?

The behaviour I see in those circumstances is not completely consistent, but most of the time the application appears to hang. That's not surprising, given the the app is in a modal state, so the user cannot interact with the main form.

When the user then tries to go back to the top-level form (again, via Alt-Tab or the Windows taskbar), either that doesn't work (the top-level form cannot be activated), or the top-level form does become activated but is now completely frozen. The only way out is to switch back to the main form and attempt to close the app, which itself doesn't always work.

Has anyone else come across this scenario? And if so, any suggestions for avoiding it?

Mike


__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro tips, advice, training, consultancy
Custom software for your business
 
In my view, the problem here is having both Screen and a top-level form available. My apps use one or the other as their base.

Tamar
 
Tamar,

I take your point. In most cases, I would use either a top-level form and the main ("in screen" form), and not try mix them.

However, in this case, I need a main form, plus a top-level form (in fact, multiple top-level forms) to be active at the same time.

Think of an application like Outlook Express. The main interface is the "in screen" form. Each time the user opens a message window, that's a new top-level form.

That's the sort of interface that I'm trying to create.

Mike


__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro tips, advice, training, consultancy
Custom software for your business
 
I wonder if what you need for the message windows is a desktop form rather than a top-level form?

Tamar
 
OK, I've tried using a desktop form, but unfortunately it doesn't quite cut the mustard.

As far as I can see, the desktop form stays always on top of the main form, which is not helpful to the user. Also, you can't give it a taskbar button. I really want to let the user switch easily between the main form and these subsidiary forms, and not to have one form partly obscure another. I can't see any way to achieve that with a desktop form.

Still, it was worth a shot.

Mike



__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro tips, advice, training, consultancy
Custom software for your business
 
The point of having a MODAL form is that the user can't switch to another part of the same application until you're done that the function the MODAL form addresses.

If you need this switching capability while the MODAL form is open, you will probably need to re-write the function of the MODAL form as a modeless form.

Andy Snyder
SnyAc Software Services Hyperware Inc. a division of AmTech Software
 
Andy,

Thanks for your reply.

The point of having a MODAL form is that the user can't switch to another part of the same application until you're done that the function the MODAL form addresses.

Yes, I realise that. It's not that I want them to be able to switch to another part of the application. The point is that, in the scenario I described, I can't prevent them from switching.

I suppose I could make the main part of the application invisible while the modal form is active, but I'm not sure what the implications of that would be. Maybe I'll try that next.

Mike


__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro tips, advice, training, consultancy
Custom software for your business
 
I think that is the only way you'll be able to prevent them from switching back to the screen (set it's visible property to .F.) which is the desired end-result (preventing them from doing what you don't want them to do).

Andy Snyder
SnyAc Software Services Hyperware Inc. a division of AmTech Software
 
I've now tried making the main form invisible while the modal form is active. It's not ideal, mainly because of its potential to confuse the user (you open one form, only to see another form completely disappear). But it does at least avoid the original problem.

So, assuming no-one can come up with a better solution, that's the one I'll go with.

Thanks to Andy and Tamar for you suggestions.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro tips, advice, training, consultancy
Custom software for your business
 
Instead of using a modal form maybe you can simulate one.


I did a quick test and putting a setfocus in the forms deactivate event prevented me from accessing any other objects in the VFP session. But I could still access other applications.
 
Mike, take a look at Bernard Bout's Lightbox class. I think it will solve your problem. It basically overlays all forms with a GDI+ image except for the modal one. By doing this, form switching is not even an option until the modal form is closed. But the real beauty of this class is that the other forms are still visible but dimmed (dimming intensity can be adjusted from very dark to very light).
 
Brad,

Thanks for your post. I'm familiar with Bernard's work, and have played with his Lightbox in the past. It's very impressive.

But, to be honest, I think it would be overkill for my present problem. If I used it for the top-level "modal" forms, I feel I would have to use it for all the modal forms in the app, and I'm not sure I want to do that at this stage.

The app is in beta testing right now, and I've had no negative feedback from the solution I adopted, so I think I'll stay with it. Thanks anyway for a useful suggestion.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro tips, advice, training, consultancy
Custom software for your business
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top