Using Win32 functions in Visual FoxPro Image Gallery
Code examples:
How to change display settings: screen resolution, screen refresh rate
Capturing keyboard activity of another application with the Raw Input API (VFP9)
Converting Unicode data from the Clipboard to a character string using a given code page
Copying picture of the active form to the Clipboard using Enhanced Metafile API functions
Enumerating data formats currently available on the clipboard
Enumerating raw input devices attached to the system (keyboard, mouse, human interface device)
GDI+: copying to the Clipboard (a) image of active FoxPro window/form, (b) image file
Disabling mouse and keyboard input for the main VFP window (with the app still running)
Storing content of the Clipboard to a bitmap file
Current keyboard type
Displaying icons in the system tray (VFP9)
Custom HttpRequest class (WinINet)
How to activate Windows Calculator
Attaching menu to a top-level form
Storing screen shot of a form to bitmap file
Using Beep and Sleep functions to make the old tin buzz sing (WinNT only?)
Using InternetSetFilePointer when resuming interrupted download from the Internet
Obtaining current Internet Explorer browser version and UserAgent
How to print a bitmap file
Minimizing all running applications
Sending email messages with Simple MAPI
Drawing Windows predefined bitmaps using the LoadBitmap functions
Using EnumPrinters function to enumerate locally installed printers
Using Path functions from Shell Lightweight Utility APIs (shlapi.dll)
Running MSDOS Shell as a child process with redirected input and output (smarter RUN command)

User rating: 0/10 (0 votes)
Rate this code sample:
  • ~
More code examples    Listed functions    Add comment     W32 Constants      Translate this page Printer friendly version of this code sample
Before you begin:
The following class allows to run a set of MSDOS commands and get back a response as a string. The MSDOS window is present but not visible.

This is how the class can be tested from the VFP Command Window:



If CreateMsdosSession method returns True, then RunCommand method can be used to launch msdos commands. An output of the command processor is collected in a buffer. GetResponse method returns the content and clears the buffer.

Use this program code to test the class:

LOCAL cmd As msdos, cResponse
cmd = CREATEOBJECT("msdos")

IF NOT cmd.createmsdossession()
        ? "CreateMsdosSession call failed."
        RETURN
ENDIF

cmd.runcommand("dir *.bmp")
cmd.runcommand("ipconfig")
= INKEY(2) && gives MSDOS some time to return

cResponse = cmd.getresponse()
STORE cResponse TO _cliptext && for reviewing later

SET MEMOWIDTH TO 120
? cResponse

The INKEY() is here to provide some time for the command processor to generate an output. The WaitForSingleObject API, which could be an ideal solution, does not wait for a console output. May be the Timer object can do better than the INKEY() does.

See also:
  • Running external applications from VFP using WinExec
  • Using ShellExecute for performing operations on files
  • Running external applications from VFP using CreateProcess
  • Running an external program from FoxPro and waiting for its termination
  • Creating a console window for Visual FoxPro application
  •  
      Members area. Log in to view this example.
     
      User name:
      Password:
     
     
      Forgot your password?
     
      Sign up for
    the Membership
     
      Buy this example for $10.00
    Instant email delivery.

    Read more...
     


    User rating: 0/10 (0 votes)
    Rate this code sample:
    • ~
    7232 bytes  
    Created: 2004-12-18 09:14:35  
    Modified: 2013-09-20 13:26:56  
    Visits in 7 days: 144  
    Listed functions:
    CloseHandle
    CreatePipe
    CreateProcess
    DuplicateHandle
    GetCurrentProcess
    GetFileInformationByHandle
    GetSystemDirectory
    ReadFile
    TerminateProcess
    WriteFile
    Printer friendly API declarations
    My comment:
    The VFP class starts the command processor (cmd.exe) as a child process using the CreateProcess. Through input parameters for this call the standard input and output handles of the child process are redirected to two anonymous pipes.

    The msdos window is put in a hidden state by placing STARTF_USESHOWWINDOW in STARTUPINFO structure. So the usual black msdos window does not blink and does not appear in the Task Bar.

    Though it has an unexpected effect:

    cmd.RunCommand("C:\myprog.exe")


    The code line above will start myprog.exe and place it in a hidden state. Only after the cmd object is released, the myprog.exe becomes visible and appears in the Task Bar.

    * * *
    Through one pipe the command processor receives commands (RunCommand method). The other pipe is used to get an output generated by the command processor (GetResponse method).

    An anonymous pipe is an unnamed, one-way pipe that typically transfers data between a parent process and a child process.

    This is like a temporary file that is shared by two processes. One of these processes can write to the pipe, and the other one can read from the pipe, which is what "one-way" means.

    MSDN links:

  • Creating a Child Process with Redirected Input and Output -- the FoxPro class above actually uses a translation of a large part of this C code

  • How To Spawn Console Processes with Redirected Standard Handles
  • Word Index links for this example:
    Translate this page:
      Spanish    Portuguese    German    French    Italian  
    FreeTranslation.com offers instant, free translations of text or web pages.
    User Contributed Notes:
    A.M. | 2006-10-10 14:04:47
    Does not return output when tested under W2K 5.00.2195
    John Clarke | 2007-12-18 20:06:32
    I'm not sure how to terminate grand-child process. If CMD.EXE (child) launches an application (grand-child) that takes a long time to run, I'd like to be able to handle a timeout on that process. I wonder if there is a way to retrieve the process handle for the app that we send in WriteToPipe(cCommand...). If so, we could use the WaitForSingleObject() API to trap for timeouts.

    Copyright 2001-2014 News2News, Inc. Before reproducing or distributing any data from this site please ask for an approval from its owner. Unless otherwise specified, this page is for your personal and non-commercial use. The information on this page is presented AS IS, meaning that you may use it at your own risk. Microsoft Visual FoxPro and Windows are trade marks of Microsoft Corp. All other trademarks are the property of their respective owners. 

    Privacy policy
    Credits: PHP (4.4.9), an HTML-embedded scripting language, MySQL (5.1.68), the Open Source standard SQL database, AceHTML Freeware Version 4, freeware HTML Editor of choice.   Hosted by Korax Online Inc.
    Last Topics Visited (54.227.62.141)
    3 sec.Example: 'Displaying dimmed window behind VFP top-level form'
    8 sec.Function: 'GetDriveType'
    Function group: 'File Management'
    7.39 hrs.Example: 'The original LoadPicture() function in VFP returns valid handles to bitmaps, icons, cursors, and metafiles'
     Example: 'How to obtain Content-Type value for a file type from the System Registry'
     Example: 'Using WM_COPYDATA for interprocess communication (VFP9)'
     
    Function group: 'Raw Input'
     Function: 'HeapFree'
    7.4 hrs.Function: 'SQLTables'
    1 day(s)
    Function group: 'GDI+ Brush'
     Example: 'Winsock: connecting to a news server (NNTP, port 119)'
    Google
    Advertise here!