Screen Capture of a Non-Word Window

S

Steve

I'm using Office 2000 and 2003
I'm writing a macro to read input from the operator and write the response
to a word document then capture a window from another application like MatLab
and past e that to the same document and repeat this process until the
operator exits by entering X. Everything works with exception of being able
to capture the desired screen. Right now I capture the inputbox screen
because it is the active window. Is there a way to select another window to
become the active window? Also, is there a way to list all the windows that
are open regardless of what application they are associated with. For example
if there is an Explorer, Word, Excel, and Powerpoint windows open can I
identify how many are open and select the one that match a title or
applicaiton? Thank you in advance for your assistance. Following is the
code I'm using.

Option Explicit
Public Declare Sub keybd_event Lib "user32" (ByVal bvk As Byte, ByVal _
bScan As Byte, ByVal dwflags As Long, ByVal dwExtrainfo As Long)

Public Const KEYEVENTF_KEYUP = &H2
Public Const VK_SNAPSHOT = &H2C
Public Const VK_MENU = &H12

Sub ScreenCapture()
keybd_event VK_MENU, 0, 0, 0
keybd_event VK_SNAPSHOT, 0, 0, 0
keybd_event VK_SNAPSHOT, 0, KEYEVENTF_KEYUP, 0
keybd_event VK_MENU, 0, KEYEVENTF_KEYUP, 0
End Sub
Do
ansrlen = 0
Answer = InputBox("Enter color and associated number and then " & vbCr & _
"click ""Ok"" ONLY when you are ready to" & vbCr & _
"capture the screen" & vbCr & vbCr & _
"Enter X or x to exit.", "Main Capture")
ansrlen = Len(Answer)
Answer = UCase(Mid(Answer, 1, 1)) & Mid(Answer, 2, ansrlen)

If Answer = "X" Then
confirmX = MsgBox("Select ""Yes"" to confirm termination" & vbCr &
vbCr & _
"Select ""No"" to continue.", vbYesNo + vbCritical +
vbDefaultButton2, "Main Capture")
If confirmX = vbYes Then
Exit Sub
End If
Else
Selection.TypeText Answer & vbCrLf
ScreenCapture
Selection.Paste
Selection.InsertBreak Type:=wdPageBreak
End If

Loop
 
S

Steve Yandl

Steve,

When running VBA from Word you can take advantage of the Word application's
'Tasks' collection. Unlike a list of running processes, tasks only includes
applications exposing a window to the user. Each task in the collection has
a '.Name' property which is the friendly name of the application (what you
would see in the bar at the top of the window). Each task has an 'Activate'
window which would allow you to do what you want although you might run into
problems if you use the InStr function to screen the return values for the
'Name' property and more than one window shares that portion of the name.
If you like to experiment, there is also a '.SendWindowMessage' method for
each task which could possibly help you with the screen capture but I've
found it takes quite a bit of poking around the application in question to
get anything useful.


Steve Yandl
 
S

Steve

Steve,

Thanks for the reply. I wanted to see all the tasks so I wrote the
following test routine. It printed out all the processes that were active
and not just those that have a window open, which at the time was only 5.
However it printed 80+ applications. Is there a way to isolate the tasks to
only those that a window open? Thanks for your assistance it's much
appreciated.
icnt = 0
For Each tasknam In Application.Tasks
icnt = icnt + 1
Debug.Print icnt & " Task name: " & tasknam.Name
Next
 

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