tags:

views:

32

answers:

2

I have a VB6 ActiveX exe that is launched from a third-party CRM App. On launch, the main form opens but it starts to flash and then loses focus. If you move the form, you'll see a server busy screen with the Switch To, Retry button.

I've tried using SetFocus and the SetFocusAPI in the OnActivate event of the form, but that doesn't work. Are there any suggestions on how I can have this form have focus when launched from the other app?

Additional Info:

The OnLoad event calls the SetWindowPos API in order to center the app over the calling app and sets HWND_TOPMOST.

Additional Info:

  • The Active Window is the correct window(but it's clearly not in focus)

  • The foreground window is the calling application. SetForegroundWindow switches the foreground window, but immediately returns back to the calling app. It's not until I click on the form that the form is in the foreground. I'm attempting all of this within a loop in the module that calls the form (and not in the calling app).

A: 

Have you tried setting the tab order on the form? Your user control should have a tab order of 0 so it gets the focus.

Also, where does the focus go after it is launched?

bugtussle
I'm not sure, how setting the forms tab order will affect the focus of the form itself, however the tab order 0 is set to the frame, 1 to a label next to a textbox and 2 to the text box within that frame.I added additional info above.
Clownish Carnage
A: 

The CRM application has to call AllowSetForegroundWindow to "authorize" the ActiveX ProcessID to "steal" the focus from the current process.

wqw
Unfortunately, the calling app doesn't allow API Calls.
Clownish Carnage
Without AllowSet... there is no legitimate way to change focus to a window which is owned by another process in XP and above. AllowSet... informs the OS 'He is with me. Treat his windows as mine, regarding focus'
wqw