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
************
-----Original Message-----
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf
Of Paul Newton
Sent: 14 January 2008 16:10
To: [email protected]
Subject: Shellexecute problem
Hi all
I placed Dave's code in a PRG called PrintFile.PRG which accepts as a
parameter the full path and name of the file to print.
Elsewhere I have some code that looks like this:
<pseudocode> Create text file MyFile.TXT
= PrintFile("MyFile.TXT")
ERASE("MyFile.TXT")
This causes a problem because notepad cannot find the file to print - I
need to somehow wait until Notepad finsihes with the file and only then
let the ERASE command execute. Any suggestions ?
Also is there a way to prevent Notepad printing the file with a
(filename) header and (page number) footer ?
Many thanks
Paul Newton
Dave Crozier wrote:
> * API Call to print out or OPEN a document
>
> Declare Integer ShellExecute In Shell32.Dll ;
> INTEGER nWinHandle,;
> STRING cOperation,;
> STRING cFileName,;
> STRING cParameters,;
> STRING cDirectory,;
> INTEGER nShowWindow
>
> ShellExec("test.pdf","","c:\temp\")
>
> *********
> Procedure ShellExec (exeName, exeParms, exePath)
> Local nStat, errorDesc
>
> * Use the next line to View
> * nStat = ShellExecute(0,"open",exeName,exeParms,exePath,1)
>
> * Use the next line to Print
> nStat = ShellExecute(0,"print",exeName,exeParms,exePath,1)
>
> * If nStat > 32, then it is the Instance Handle
> * To get a Windows Handle see support.microsoft.com/kb/q242308/
> If nStat <= 32
> errorDesc = Icase(nStat=2,"Invalid path or filename", ;
> nStat=8,"Insufficient memory", ;
> nStat=11,"invalid EXE file", ;
> nStat=31,"Invalid action, or no application
> associated with the specified file", ;
> "Error description not available")
> Messagebox("Error "+Ltrim(Str(nStat))+" ...
> "+errorDesc,16,"Program did not start.",2000)
> Endif
>
> Return
>
> Dave Crozier
>
[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.