Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Code to Print a VFP Form
Message
General information
Forum:
Visual FoxPro
Category:
Windows API functions
Environment versions
Visual FoxPro:
VFP 9 SP2
OS:
Windows 10
Database:
Visual FoxPro
Application:
Desktop
Miscellaneous
Thread ID:
01665906
Message ID:
01665925
Views:
76
>Would anyone know how to print a portion or all of a screen image directly to a printer from a complied VFP application? I suspect it can be done by a Windows API call but don't know what that would be. If there is an API call for this, example code would help.
>
>Also, I'm assuming this isn't something that can be done with native VFP coding. Please confirm or provide code for that.
>
>TIA,
>
>Dave L.

Unzip the attached sc.dll (ScreenCap) and put it somewhere in your project's path. Change the location of "sc.dll" below to be that relative location in your app. And use as indicated. Please report any bugs and I'll post an update.

There are two attached .ZIP files. One has the debug version of the sc.dll, the other the release version. If you don't have Visual Studio 2017 installed, only the release version will work.

Usage:
* Captures the entire contents of almost any visible window in the system
DECLARE INTEGER scdll__capture_window IN sc.dll ;
                    INTEGER nHwnd, ;        && Such as a function that retrieves any Windows HWnd
                    STRING  cFilename, ;    && Such as "c:\path\to\myscreen.bmp"
                    INTEGER nX, ;           && Upper-left X coordinate, or -1 to use all
                    INTEGER nY, ;           && Upper-left Y coordinate, or -1 to use all
                    INTEGER nWidth, ;       && Width, or -1 to use all
                    INTEGER nHeight         && Height, or -1 to use all

* Captures the entire form
DECLARE INTEGER scdll__capture_form IN sc.dll ;
                    INTEGER nHwnd, ;        && Such as thisForm.HWnd
                    STRING  cFilename, ;    && Such as "c:\path\to\myscreen.bmp"
                    INTEGER nX, ;           && Upper-left X coordinate, or -1 to use all
                    INTEGER nY, ;           && Upper-left Y coordinate, or -1 to use all
                    INTEGER nWidth, ;       && Width, or -1 to use all
                    INTEGER nHeight         && Height, or -1 to use all

* Captures the entire desktop window
DECLARE INTEGER scdll__capture_screen IN sc.dll ;
                    STRING  cFilename       && Such as "c:\path\to\myscreen.bmp"

* Usage:
scdll__capture_window(_screen.HWnd, "c:\temp\window.bmp", -1, -1, -1, -1)
scdll__capture_form(thisForm.HWnd, "c:\temp\form.bmp", -1, -1, -1, -1)
scdll__capture_screen("c:\temp\screen.bmp")

* To capture a single object, or an area of a form defined by an object:
scdll__capture_form(thisForm.HWnd, "c:\temp\object.bmp", obj.Left, obj.Top, obj.Width, obj.Height)
Tamar's solution will capture scrollable parts. This will just capture the visible portion of the form. You can programmatically inject keystrokes or operations to cause it to scroll through all portions of the form if you like, and then capture each part ... but I don't use scrollable forms so it's not an issue for me / this code's needs.
Previous
Reply
Map
View

Click here to load this message in the networking platform