Sending keystrokes via API call 
Author Message
 Sending keystrokes via API call

I certainly hope someone out there can help me with this one.

I have an application that I am opening with the OpenProcess API call.
I then use FindWindow to get the handle to the window of this program,
and use GetMenu, GetMenuItemCount, GetMenuItemID, GetMenuString,
GetSubMenu, and GetMenuItemID to get the handle of the menu option (in
this case, the File... Print) that I need to send a message.  Lastly, I
use SendMessage to select this option.

All that works fine.  When I look at the application, I see that up to
this point, the Print dialog box is up as it should be.  My problem is
that I now need to send a series of keystrokes to this dialog box in
order to select one of the printers in my printer list.  I need to send
the "A" key twice.  I've tried doing a SendKeys and it didn't work.  I
also tried SendMessage, but couldn't get that to work either (although
I'm not sure I used the right parameters).  I've tried getting the
handle to the dialog box that appears, but to no avail.

If anyone has any ideas of any kind, please let me know!

Thank you,
Chris Valdivia
Phelps Dodge Corporation

Sent via Deja.com
http://www.*-*-*.com/



Sun, 08 Jun 2003 04:49:39 GMT  
 Sending keystrokes via API call
Quote:
>...I've tried getting the handle to the dialog box that appears,
>but to no avail...

Presuming you're referring to the standard Print dialog (classname
"#32770"), FindWindow("#32770", vbNullString) should do it. Also you
should verify that the dialog belongs to the app you're working with,
for example by checking it's owner with GetWindow. If it's some custom
beastie, spend a few minutes with Spy++ to get the classname and
whatever else.
Once the dialog's hwnd has been determined, you could pass it to
SetForegroundWindow and try SendKeys.
A more robust approach would be to enumerate the dialog's child
windows (EnumChildWindows) and obtain the hwnd of the specific
control(s) of interest so they could be manipulated directly with the
Api. Control IDs don't change and are in fact pre-defined for the
standard Windows dialogs. You could use GetWindowLong with GWL_ID on
the child windows in the EnumChildWindowProc callback to look for
specific IDs.

Quote:

>I certainly hope someone out there can help me with this one.

>I have an application that I am opening with the OpenProcess API call.
>I then use FindWindow to get the handle to the window of this program,
>and use GetMenu, GetMenuItemCount, GetMenuItemID, GetMenuString,
>GetSubMenu, and GetMenuItemID to get the handle of the menu option (in
>this case, the File... Print) that I need to send a message.  Lastly, I
>use SendMessage to select this option.

>All that works fine.  When I look at the application, I see that up to
>this point, the Print dialog box is up as it should be.  My problem is
>that I now need to send a series of keystrokes to this dialog box in
>order to select one of the printers in my printer list.  I need to send
>the "A" key twice.  I've tried doing a SendKeys and it didn't work.  I
>also tried SendMessage, but couldn't get that to work either (although
>I'm not sure I used the right parameters).  I've tried getting the
>handle to the dialog box that appears, but to no avail.

>If anyone has any ideas of any kind, please let me know!

>Thank you,
>Chris Valdivia
>Phelps Dodge Corporation

>Sent via Deja.com
>http://www.deja.com/

-Tom
(please post replies to the newsgroup)


Sun, 08 Jun 2003 06:21:16 GMT  
 Sending keystrokes via API call
Have you looked for the dialog with Spy++ or similar?  If you can get the
class name and window title, you should be able to get its hWnd.  You have
several options:  the FindWindow API is fine if you have both pieces of
information.  Otherwise, you can Enumerate Windows or use the
FindWindowsLike function (VB sample) described in the knowledgebase.

One tidbit that the FindWindowsLike article(s) forget to mention is if you
are looking for one of the windows with a #<number> class name, you must
enclose the # in square bracket in order for it to be treated as a literal
character (because it is a "pattern" character to the LIKE operator).

When sending a message to a control in a window in another app, I have found
that I usually need to send a WM_ACTIVATE message to the top level window
(i.e. not the target control) first, then use the SendMessage to the
control.

HTH,
Tore.

Quote:

> I certainly hope someone out there can help me with this one.

> I have an application that I am opening with the OpenProcess API call.
> I then use FindWindow to get the handle to the window of this program,
> and use GetMenu, GetMenuItemCount, GetMenuItemID, GetMenuString,
> GetSubMenu, and GetMenuItemID to get the handle of the menu option (in
> this case, the File... Print) that I need to send a message.  Lastly, I
> use SendMessage to select this option.

> All that works fine.  When I look at the application, I see that up to
> this point, the Print dialog box is up as it should be.  My problem is
> that I now need to send a series of keystrokes to this dialog box in
> order to select one of the printers in my printer list.  I need to send
> the "A" key twice.  I've tried doing a SendKeys and it didn't work.  I
> also tried SendMessage, but couldn't get that to work either (although
> I'm not sure I used the right parameters).  I've tried getting the
> handle to the dialog box that appears, but to no avail.

> If anyone has any ideas of any kind, please let me know!

> Thank you,
> Chris Valdivia
> Phelps Dodge Corporation

> Sent via Deja.com
> http://www.deja.com/



Sun, 08 Jun 2003 06:22:52 GMT  
 Sending keystrokes via API call


Quote:
>One tidbit that the FindWindowsLike article(s) forget to mention is if you
>are looking for one of the windows with a #<number> class name, you must
>enclose the # in square bracket in order for it to be treated as a literal
>character (because it is a "pattern" character to the LIKE operator).

Huh??
Including brackets in the FindWindow classname arg would cause it to
~fail~ unless the window's classname actually had brackets in it.
VB doesn't do any sort of symbolic interpretation on a string outside
the context of it being an argument to Like, Format, etc. It would
only be a factor if you were using Like to compare classnames.

-Tom
(please post replies to the newsgroup)



Sun, 08 Jun 2003 08:09:31 GMT  
 Sending keystrokes via API call
No - not in FindWindow.

But the VB function "FindWindowLike" (described (and code provided) in
"HOWTO: Get a Window Handle Without Specifying an Exact Title" (ID: Q147659)
and mentioned in "Ask Dr. GUI #39") uses GetWindow etc. to "enumerate"
windows (this was originally written for VB3, and upgraded for the 32-bit
version of VB4 - no callbacks), using a string LIKE comparison against the
window title and class name - allowing wildcards.  I have used various
instances of this function in several scenarios.  For instance longevity:
the class names for VB forms change between versions, and versatility: forms
have a different class name when running in the IDE.  Also, it is useful
when looking for a window that modifies its title based on what document it
is displaying.

The FindWindowLike function as presented by MS does NOT work with the #32770
class name - because of the following line of code:

    If sWindowText Like WindowText And sClassname Like Classname Then

(WindowText and ClassName are parameters to the function).

Therefore, when looking for a #32770 class name, you must call the function:

    r = FindWindowLike(hWnds(), hWnds(1), "*", "[#]32770", vbNullString)

Hope this clears up any confusion I may have caused.

Regards,
Tore.


Quote:


> >One tidbit that the FindWindowsLike article(s) forget to mention is if
you
> >are looking for one of the windows with a #<number> class name, you must
> >enclose the # in square bracket in order for it to be treated as a
literal
> >character (because it is a "pattern" character to the LIKE operator).

> Huh??
> Including brackets in the FindWindow classname arg would cause it to
> ~fail~ unless the window's classname actually had brackets in it.
> VB doesn't do any sort of symbolic interpretation on a string outside
> the context of it being an argument to Like, Format, etc. It would
> only be a factor if you were using Like to compare classnames.

> -Tom
> (please post replies to the newsgroup)



Sun, 08 Jun 2003 08:34:42 GMT  
 Sending keystrokes via API call


Quote:
>...But the VB function "FindWindowLike" (described (and code provided) in
>"HOWTO: Get a Window Handle Without Specifying an Exact Title" (ID: Q147659)
>...

Sorry, careless reading. Missed the fact you were referring to a KB
article. <g>

-Tom
(please post replies to the newsgroup)



Sun, 08 Jun 2003 21:49:42 GMT  
 
 [ 6 post ] 

 Relevant Pages 

1. Sending Keystrokes to Internet Explorer via VB6.0

2. Win API - Sending keystrokes to a hWnd

3. Sending Keystrokes with API

4. Question about sending keystrokes to another window w/ API

5. PROBLEM: Adding a printer via API, then creating a printer Share via API (source included)

6. I need a way to bypass the confirm on send to recyle bin (via api)

7. API for sending and receiving SMS messages via GSM modem

8. API for sending and receiving SMS messages via GSM modem

9. I need a way to bypass the confirm on send to recyle bin (via api)

10. Calling Oracle7 Stored Procedures via the ODBC 2.10 API

11. Extracting Network Info via Windows API calls How ???

12. API call for SmartCard via PC/SC interface

 

 
Powered by phpBB® Forum Software