Paul,
Also here is a program to take an open window opened with notepad and send
keystrokes to it.
1. Open a new Notepad File (right click in folder - new text document
2. Run the program below
Notice it sends keystrokes to the Notepad document and as an aside opens up
the Font menu.
Hope it helps
Dave
*******************
* Start of Code
*
cWindow_Name="New Plain Text File.txt - Notepad"
lnMainWind = GetActiveWind()
lnHandle = FindWind(cWindow_Name)
SetForeWind(lnHandle)
If lnHandle # 0
* Start scanning and wait 2 seconds
cMessage="Hello There This has been created by VFP"
For I=1 to Len(cMessage)
? SendKey(Substr(cMessage,I,1))
Endfor
Do While FindWind(cWindow_Name) # 0
* Attempt to close the MODI Application
SendKey('ALT O')
SendKey('F')
SendKey('T')
Exit
*
Enddo
Endif
* Reactivate the calling window
SetForeWind(lnMainWind)
Return
*******************************
* Function to send keystrokes
* Eg Sendkey("ALT T") - send Alt/T
*
Function SendKey (tcChar)
Declare keybd_event In user32 ;
SHORT bVk, SHORT bScan, ;
INTEGER dwFlags, Integer dwExtraInfo
Declare SHORT VkKeyScan In user32 Integer ch
Local lcChar
lcChar = Right(tcChar, 1)
Do Case
Case 'SHIFT' $ Upper(tcChar)
* Shift key
keybd_event(0x10, 0, 0, 0)
Case 'CTRL' $ Upper(tcChar)
* Ctrl key
keybd_event(0x11, 0, 0, 0)
Case 'ALT' $ Upper(tcChar)
* Alt key
keybd_event(0x12, 0, 0, 0)
Endcase
keybd_event(VkKeyScan(Asc(lcChar)), 0, 0, 0)
Do Case
Case 'SHIFT' $ Upper(tcChar)
* Shift key
keybd_event(0x10, 0, 2, 0)
Case 'CTRL' $ Upper(tcChar)
* Ctrl key
keybd_event(0x11, 0, 2, 0)
Case 'ALT' $ Upper(tcChar)
* Alt key
keybd_event(0x12, 0, 2, 0)
*
EndCase
* Wait for response
Inkey(.01)
Return
*
EndFunc
* Establish the foreground window
Function SetForeWind(tnHandle)
Declare Integer SetForegroundWindow ;
IN user32 Integer hWindow
Declare Integer FindWindow In user32 ;
STRING lpClassName, String lpWindowName
SetForegroundWindow(tnHandle)
Return
EndFunc
* Get a specific window reference
Function FindWind(tcWindow)
Declare Integer FindWindow In user32 ;
STRING lpClassName, String lpWindowName
Local lnHandle
lnHandle = FindWindow(Null, tcWindow)
Return (lnHandle)
EndFunc
* Get reference to the active window
Function GetActiveWind
Declare Integer GetActiveWindow In user32
Return (GetActiveWindow())
*
EndFunc
-----Original Message-----
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf
Of Paul Newton
Sent: 14 January 2008 17:12
To: [email protected]
Subject: Re: Shellexecute problem
Many thanks Dave
Paul
Dave Crozier wrote:
> Paul,
> Use this to see if Notepad is running
>
> Dave Crozier
>
> *******************
> * Start of Code
> *
> ? IsRunning("Notepad")
>
> Function IsRunning
> Lparameter pctitle
>
> Declare INTEGER GetActiveWindow IN Win32API
> Declare INTEGER GetWindow IN Win32API;
> INTEGER hwnd, INTEGER dflag
> Declare INTEGER GetWindowText IN Win32API ;
> INTEGER hwnd, STRING @lptstr, INTEGER cbmax
> Declare INTEGER CloseWindow IN Win32API;
> INTEGER hwnd
> Declare INTEGER DestroyWindow IN Win32API;
> INTEGER hwnd
> Local lnhwnd, lnnext, lldone, lctitle_bar, lcsearchfor,;
> lntext_len
> lcsearchfor = UPPER(ALLTRIM(pctitle))
> lnhwnd = GetActiveWindow()
> lnnext = 2
> lctitle_bar = ""
> Do WHILE lnhwnd # 0
> If type('lnhwnd') # 'N'
> Loop
> Endif
>
> lctitle_bar = SPACE(200) + CHR(0)
> lntext_len = GetWindowText(lnhwnd, @lctitle_bar, 200)
> lctitle_bar = UPPER(LEFT(lctitle_bar, lntext_len))
> lldone = (lcsearchfor $ lctitle_bar)
> lp=lnhwnd
> lnhwnd = iif(lldone, 0, GetWindow(lnhwnd, lnnext))
> Enddo
> Return lldone
> *
> * End of Code
> ************
>
[excessive quoting removed by server]
_______________________________________________
Post Messages to: [email protected]
Subscription Maintenance: http://leafe.com/mailman/listinfo/profox
OT-free version of this list: http://leafe.com/mailman/listinfo/profoxtech
Searchable Archive: http://leafe.com/archives/search/profox
This message: http://leafe.com/archives/byMID/profox/[EMAIL PROTECTED]
** All postings, unless explicitly stated otherwise, are the opinions of the
author, and do not constitute legal or medical advice. This statement is added
to the messages for those lawyers who are too stupid to see the obvious.