Microsoft KB Archive/255279

= How To Create a COM DLL with Visual FoxPro that Prints Screen Image =

Article ID: 255279

Article Last Modified on 6/29/2004

-

APPLIES TO


 * Microsoft Visual FoxPro 6.0 Professional Edition

-



This article was previously published under Q255279



SUMMARY
This article demonstrates, by example, the general ease with which Component Object Model (COM) DLLs can be created within Microsoft Visual FoxPro 6.0. The program code contained in this article enables the user to create a useful example of a simple COM DLL.



MORE INFORMATION
In order for the example to be put to use, the host computer must have a properly installed copy of Microsoft Office for Windows 95 (or higher). The COM DLL offers the following functionalities:
 * It captures the screen image of the open and active window.


 * An OLE instance of Microsoft Word is created for the purpose of printing the captured screen image.


 * The captured screen image is pasted into a Microsoft Word document.


 * The Microsoft Word Document is printed to the computer's default printer.

To create the COM DLL described in this example, perform the following steps:  Within Microsoft Visual FoxPro 6.0, create a new project called olepscrn .  Add a new program to the olepscrn project, and input the following code: *!* Beginning of program code example: DEFINE CLASS p_screen AS CUSTOM OLEPUBLIC Name = "p_screen" ScreenPrinted = .F.   oWordObj = "" PROCEDURE ScreenCapture This.ReleaseWord This.ScreenPrinted = .T.       DECLARE INTEGER keybd_event IN Win32API ; INTEGER, INTEGER, INTEGER, INTEGER VK_SNAPSHOT = 44 =keybd_event(VK_SNAPSHOT, 1, 0, 0) This.oWordObj=CREATEOBJECT("Word.Application") This.oWordObj.Documents.Add This.oWordObj.ActiveDocument.PageSetup.Orientation = 1 WITH This.oWordObj.WordBasic .EditPaste .FilePrint .FileClose(2) ENDWITH RELEASE keybd_event, vk_snapshot ENDPROC PROCEDURE ReleaseWord IF This.ScreenPrinted This.oWordObj.Quit This.oWordObj = "" This.ScreenPrinted = .F.       ENDIF ENDPROC PROCEDURE Destroy This.ReleaseWord ENDPROC ENDDEFINE  Save the program as p_screen . On the Project Manager, select the Build button, and choose Single-threaded COM server (DLL) in Visual FoxPro 6.0 with SP3, or choose Build COM DLL in Visual FoxPro 6.0. From the Command window, you can use the DLL by entering the following three commands:   This command creates an object reference to the DLL and loads it into memory: oPScreen = CREATEOBJECT("olepscrn.p_screen") This command executes the Print Screen: oPScreen.ScreenCapture This third and final command removes the DLL from memory. When the object is released, the instance of Microsoft Word that it created releases as well: RELEASE oPScreen   This command executes the Print Screen: oPScreen.ScreenCapture This third and final command removes the DLL from memory. When the object is released, the instance of Microsoft Word that it created releases as well: RELEASE oPScreen </li>  This third and final command removes the DLL from memory. When the object is released, the instance of Microsoft Word that it created releases as well: RELEASE oPScreen </li></ol> </li></ol>
 * !* End of program code example:

<div class="references_section">