Function DoAndWait(cExe, cWindowMode)
Declare Integer CreateProcess In kernel32.Dll ;
INTEGER lpApplicationName, ;
STRING lpCommandLine, ;
INTEGER lpProcessAttributes, ;
INTEGER lpThreadAttributes, ;
INTEGER bInheritHandles, ;
INTEGER dwCreationFlags, ;
INTEGER lpEnvironment, ;
INTEGER lpCurrentDirectory, ;
STRING @lpStartupInfo, ;
STRING @lpProcessInformation
Declare Integer WaitForSingleObject In kernel32.Dll ;
INTEGER hHandle, ;
INTEGER dwMilliseconds
Declare Integer CloseHandle In kernel32.Dll ;
INTEGER hObject
#Define NORMAL_PRIORITY_CLASS 32
#Define IDLE_PRIORITY_CLASS 64
#Define HIGH_PRIORITY_CLASS 128
#Define REALTIME_PRIORITY_CLASS 1600
* Return code from WaitForSingleObject() if * it timed out.
#Define WAIT_TIMEOUT 0x00000102
* This controls how long, in milli secconds, WaitForSingleObject()
* waits before it times out. Change this to suit your preferences.
#Define WAIT_INTERVAL 200
* STARTUPINFO is 68 bytes, of which we need to
* initially populate the 'cb' or Count of Bytes member
* with the overall length of the structure.
* The remainder should be 0-filled
* cStartUpInfo = long2str(68) + Replicate(Chr(0), 64)
If (Vartype(cWindowMode) # "C") Or (Not Inlist(cWindowMode, "NOR",
"MIN", "MAX", "HID"))
cWindowMode = "" && Use default of application
Endif
cWindowMode = Upper(cWindowMode)
Do Case
Case cWindowMode = "HID"
* Hide - use STARTF_USESHOWFLAG and value of 0
cStartUpInfo = Chr(68) + Repl(Chr(0), 43) + Chr(1) +
Repl(Chr(0), 3) + Chr(0) + Repl(Chr(0), 19)
Case cWindowMode = "NOR"
* Normal - use STARTF_USESHOWFLAG and value of 1
cStartUpInfo = Chr(68) + Repl(Chr(0), 43) + Chr(1) +
Repl(Chr(0), 3) + Chr(1) + Repl(Chr(0), 19)
Case cWindowMode = "MIN"
* Minimize - use STARTF_USESHOWFLAG and value of 2
cStartUpInfo = Chr(68) + Repl(Chr(0), 43) + Chr(1) +
Repl(Chr(0), 3) + Chr(2) + Repl(Chr(0), 19)
Case cWindowMode = "MAX"
* Maximize - use STARTF_USESHOWFLAG and value of 3
cStartUpInfo = Chr(68) + Repl(Chr(0), 43) + Chr(1) +
Repl(Chr(0), 3) + Chr(3) + Repl(Chr(0), 19)
Otherwise
* Use default of application
cStartUpInfo = Chr(68) + Repl(Chr(0), 43) + Chr(0) +
Repl(Chr(0), 3) + Chr(0) + Repl(Chr(0), 19)
Endcase
* PROCESS_INFORMATION structure is 4 longs,
* or 4*4 bytes = 16 bytes, which we'll fill with nulls.
cProcessInfo = Replicate(Chr(0), 16)
* EXE name must be null-terminated
cExe = cExe + Chr(0)
* Call CreateProcess, obtain a process handle. Treat the
* application to run as the 'command line' argument, accept
* all other defaults. Important to pass the cStartUpInfo and
* cProcessInfo by reference.
RetCode = CreateProcess(0, cExe, 0, 0, 1, ;
NORMAL_PRIORITY_CLASS, 0, 0, @cStartUpInfo, @cProcessInfo)
* Unable to run, exit now. IF RetCode = 0 RETURN .F. ENDIF
* Extract the process handle from the
* PROCESS_INFORMATION structure.
hProcess = str2long( Substr( cProcessInfo, 1, 4))
Do While .T.
* Use timeout of TIMEOUT_INTERVAL msec so the display
* will be updated. Otherwise, the VFP window never repaints until
* the loop is exited.
If WaitForSingleObject( hProcess, WAIT_INTERVAL) != WAIT_TIMEOUT
Exit
Else
DoEvents
Endif
Enddo
* Close the process handle afterwards.
RetCode = CloseHandle( hProcess)
Return .T.
Endfunc
**************************************************************
*--
Function Long2Str(tnLongVal)
Local lcResult, i
#If Version(5) >= 900
lcResult = BinToC(tnLongVal, [4RS])
#Else
lcResult = ""
For i = 24 To 0 Step -8
lcResult = Chr(Int(tnLongVal / (2 ^ i))) + lcResult
tnLongVal = Mod(tnLongVal, (2 ^ i))
Endfor
#Endif
Return lcResult
Endfunc
*--
Function Str2Long(tcLongStr)
Local lnResult, i
#If Version(5) >= 900 Then
lnResult = CToBin(tcLongStr, [4RS])
#Else
lnResult = 0
For i = 0 To 24 Step 8
lnResult = lnResult + (Asc(tcLongStr) * (2 ^ i))
tcLongStr = Right(tcLongStr, Len(tcLongStr) - 1)
Endfor
#Endif
Return lnResult
Endfunc
> -----Original Message-----
> From: [email protected] [mailto:profoxtech-
> [email protected]] On Behalf Of Joe Yoder
> Sent: Friday, February 18, 2011 4:00 AM
> To: [email protected]
> Subject: Getting a complete file list from a removable disc into VFP
>
> I want to store a copy of the complete directory structure of each optical
disc
> in my media storage system in a VFP table memo field. I considered using
> recursion with adir() but concluded that it makes more sense to use
> something like the Windows internal command "dir" with the
> "/s"subdirectories option as this automatically includes file and folder
sizes.
>
> I have been experimenting with Microsoft example code which uses
> CreateProcess and WaitForSingleObject and can have it execute an exe such
> as Notepad and wait for it to be closed before returning control to VFP.
> When I try to execute the command "Dir" rather than
> "C:\Windows\System32\Notepad" I get an error. I think the difference is
> that 'Dir" is an internal command but maybe it is just a syntax problem.
>
> Can someone help me out with the correct CreateProcess syntax or point me
> to another function?
>
> As always - a suggestion for another approach would also be welcome.
>
> TIA - Joe
>
>
> --- StripMime Report -- processed MIME parts --- multipart/alternative
> text/plain (text body -- kept)
> text/html
> ---
>
[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.