Discussion Locked

VB 6 Program Exe file

0 helpful
4 replies
Closed to new repliesThis discussion is closed. It stays readable, but it takes no new replies.

Sir:

I have a VB main program that includes a menu that calls/executes another vb exe file. Problem is, I want the other vb exe file to get the focus (if it is open) should the user attempts to set the focus on the main exe. I tried to trap it inseveral events of the MDI form (e.g. Activate, mousedown) but it failed to do what I want to happen. Are there any other techniques/tips you can give me?

Thanks in advance.

Aries

4 replies

by halcyon

I'm slightly confused. Is your problem that you can't get the event when the focus is about to change, or is it that you can't switch the focus?

Events such as mousedown, probably wouldn't work as mouse events are given to the window that currently has focus. I suspect you are going to have to use some windows API calls to accomplish what you require. One way to do it, might be to have a third controller app used to switch the focus, and once working could be incorporated in to the main application code.

Cheers,

Paul.

by zorglup37

One idea: the command of the first prgm displays a modal dialog box. The InitDialog of this dialog executes the prgm2 which set a global mutex. The OK button of this dialog is disable while the mutex exists.

by kburns

If you simply want to keep the called application in the foreground, a simple solution may be to use the Windows API to keep the called program at the top of the Z-Order, keeping focus from the user's perspective.

Since you'll be calling from an external program, this would be a two-step operation. First you would need to obtain the HWND of the called program's main window. You can do this with the FindWindow win32 API. Once you have the HWND, you can make use of the SetWindowPos with theHWND_TOPMOST argument to keep the window on top.

I won't get into the details of actually making the calls here, but if you need additional assistance going down that road, please reply to the forum to allow others to benefit as well.

by kidnapyourbestmate

If you make the (I guess it's a form) set to visible = false and set its properties so that it doesn't show on the start bar then the user won't be abvle to get to it to set the focus on it.
That's the easiest solution I cna think of, it's very easy on code and you can keep the main program active to any inputs from the second program. Is there no way that you could just copy the code from the second program into the first and just run another form?

Hope that helps

Peter

This discussion is closed to new replies.