|
web
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
SendKeys Doesn't Always Work?I have a VB.NET application that uses SendKeys to close the open document in
QuarkXPress 5.0 I'm using the following commands: AppActivate(QXP_Process_ID) SendKeys.SendWait("^{F4}") in an effort to close the document currently open in QuarkXPress. However, it only works if I set a breakpoint on or shortly before the AppActivate command and then hit F5 to run it through the above commands. But if it just runs through without stopping along the way, this command pair does not work and the document stays open. What might be the cause and solution to this frustrating problem? Thanks. Hello, Phil,
I always advocate working very hard to find some other method than SendKeys. This is because you really have no "absolute" control over which application will end up "processing" the "keys" sent. Having said that, you might try adding a "DoEvents" between the AppActivate and the SendKeys. (Or better, delay in some kind of a loop testing for the active application to be QXP_Process_ID.) Even if this were to work most of the time, I believe that SendKeys does not come with any guarantee about which application the receiver will be, and there's always the chance something unintended will sneak in and catch them. Cheers, Randy Phil Galey wrote: Show quoteHide quote > I have a VB.NET application that uses SendKeys to close the open document in > QuarkXPress 5.0 > > I'm using the following commands: > > AppActivate(QXP_Process_ID) > SendKeys.SendWait("^{F4}") > > in an effort to close the document currently open in QuarkXPress. However, > it only works if I set a breakpoint on or shortly before the AppActivate > command and then hit F5 to run it through the above commands. But if it > just runs through without stopping along the way, this command pair does not > work and the document stays open. > > What might be the cause and solution to this frustrating problem? Thanks. > > Look into SendMessage API. Together with the WM_CLOSE message (or is it
SC_CLOSE?) it does what you want the RIGHT way. In VB.NET, if I know the hwnd of an external MDI program that has zero or
more child documents loaded, how can I close the child documents? It has a File\Close menu item that closes the active document. Is it possible to remotely execute the File\Close menu item? That would be great if I could do that. Otherwise, I tried the EnumChildWindows and EnumChildProc scenerio, but for some reason, I'm not able to get to the child windows. GetWindowText returns an empty string for each one and doing a SendMessage(hwndChild, WM_CLOSE, vbNull, vbNull) doesn't do anything. How can I close the child windows (loaded documents) without closing the program? Thanks. |
|||||||||||||||||||||||