How to Alt-Tab via code to another running App?

G

Gary Schuldt

In a formC lose event handler, can I switch to another application (do the
equivalent of an alt-tab in VBA code)? If so, what does the code look like?

The app in question is a photo editor called ACDSee. I have used code to
paste some info from my database onto the clipboard and need to pick it up
in ACDSee.

Thanks.

Gary
 
D

Dirk Goldgar

Gary Schuldt said:
In a formC lose event handler, can I switch to another application
(do the equivalent of an alt-tab in VBA code)? If so, what does the
code look like?

The app in question is a photo editor called ACDSee. I have used
code to paste some info from my database onto the clipboard and need
to pick it up in ACDSee.

Gary, you may be able to use the AppActivate statement to do it. You'll
find it in the online help on the VB side.
 
G

Gary Schuldt

Thanks, Dirk; I'll check it out. It would be great if that'll do the job!

Gary
 
G

Gary Schuldt

Dirk,

I tried adding the AppActivate statement, and it triggers Runtime error 5:
Invalid
procedure call or argument. "Help" for that error is not very enlightening
in this case: The syntax is pretty straightforward. Do I have to include
some library (that I've never specified before) for this to work?

Here's the code:

==========
Private Sub Form_Close()
'
' Puts a string containing botanical name and photo ID onto the clipboard
for use
' in ACDSee
'
Dim strPhotoDescTmp As String

With Me
strPhotoDescTmp = "DB " & .Descriptors & _
" PID " & .trelPlantPhotoDepiction!PlantID & _
" PhID " & .trelPlantPhotoDepiction!PhotoID
Clipboard.SetText strPhotoDescTmp

End With

AppActivate "ACDSee"

End Sub
==================

The foregoing part of the code works fine without the AppActivate statement.

Gary
 
D

Dirk Goldgar

Gary Schuldt said:
Dirk,

I tried adding the AppActivate statement, and it triggers Runtime
error 5: Invalid
procedure call or argument. "Help" for that error is not very
enlightening in this case: The syntax is pretty straightforward. Do
I have to include some library (that I've never specified before) for
this to work?

Here's the code:

==========
Private Sub Form_Close()
'
' Puts a string containing botanical name and photo ID onto the
clipboard for use
' in ACDSee
'
Dim strPhotoDescTmp As String

With Me
strPhotoDescTmp = "DB " & .Descriptors & _
" PID " & .trelPlantPhotoDepiction!PlantID & _
" PhID " & .trelPlantPhotoDepiction!PhotoID
Clipboard.SetText strPhotoDescTmp

End With

AppActivate "ACDSee"

End Sub
==================

The foregoing part of the code works fine without the AppActivate
statement.

What does the window title of the ACDSee application look like? You
have to pass either the exact window title, or a string that matches the
beginning of the window title. If you don't, the window can't be found,
and you get that error.
 
G

Gary Schuldt

Dirk:

I'm assuming that the "title" referenced is the text that appears in the
blue bar at the top of the active window (and also in the flyover text for
the icon in the taskbar when the app is running). :)

When ACDSee is running in its "browse" (folder display) mode, the title bar
reads
<icon>ACDSee v3.1 Trial Version - <name of open folder>

I tried using "Exploring" as the title arg to AppActivate, and the code
worked--it switched to W.E. Then I added a trailing space to the original
arg--i.e., "ACDSee " . . . and it works!

(Notice that there is no trailing space after "Exploring": This is why I
gave up programming as a career a long time ago.)

There is an unintended side-effect in the Close handler: When I switch from
Form to Design view, the Close event is triggered. I guess I need to beef
up the logic in this procedure to make it more bulletproof. Anyway, the
feasibility is established!

Gary
 
D

Dirk Goldgar

Gary Schuldt said:
Dirk:

I'm assuming that the "title" referenced is the text that appears in
the blue bar at the top of the active window (and also in the flyover
text for the icon in the taskbar when the app is running). :)

Uh huh.
When ACDSee is running in its "browse" (folder display) mode, the
title bar reads
<icon>ACDSee v3.1 Trial Version - <name of open folder>

I tried using "Exploring" as the title arg to AppActivate, and the
code worked--it switched to W.E. Then I added a trailing space to
the original arg--i.e., "ACDSee " . . . and it works!

(Notice that there is no trailing space after "Exploring": This is
why I gave up programming as a career a long time ago.)

I don't know why you need the trailing space after "ACDSee". I haven't
done anything with AppActivate up to this point beyond reading the help
entry, and I don't know its ins and outs. I don't see anything in the
help entry that explains this behavior to me. Maybe if I were to delve
into the details of the API calls that are probably used to implement
the AppActivate statement, it would become clear ... but there doesn't
seem to be any immediate need to do that.
There is an unintended side-effect in the Close handler: When I
switch from Form to Design view, the Close event is triggered.
Yep.

I
guess I need to beef up the logic in this procedure to make it more
bulletproof. Anyway, the feasibility is established!

Full speed ahead!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top