How-to
Print a WinCC faceplate hardcopy with PrtScr.exe and a C action
Short answer
Put a C action on a mouse click that calls the WinCC hardcopy utility: PrtScr.exe /C= "left;top;width;height" prints that pixel region and PrtScr.exe -hardcopy prints the whole screen, both to the Windows default printer. Resolve the rectangle at runtime with GetParentPicture, GetParentPictureWindow, GetLeft, GetTop, GetWidth and GetHeight, or type a fixed region. No documented switch selects another printer; change the Windows default around the call.

On this page
You do not need the report designer or a reporting template to print one faceplate: WinCC's hardcopy utility PrtScr.exe prints a rectangle of the running screen from a C action on a mouse click. PrtScr.exe /C= "left;top;width;height" prints that pixel region, and PrtScr.exe -hardcopy prints the whole screen. Both send the capture to the Windows default printer, and the parameters travel on the command line; they are not configured in the WinCC project. The steps below wire the call into a C action, resolve the faceplate rectangle from the picture window at runtime, and give the fixed-region and full-screen calls with the arithmetic that turns coordinates into the switch string.
What PrtScr.exe does #
PrtScr.exe is the hardcopy program that ships with the classic WinCC PC runtime, the V7 line including RT Professional. It grabs the pixels of the runtime screen and sends the bitmap to the Windows default printer. The complete list of PrtScr.exe parameters and their functions is documented in the WinCC Information System, and pixel coordinates count from the top-left corner of the runtime screen. Two calls cover the faceplate job:
| Call | What it prints |
|---|---|
PrtScr.exe /C= "left;top;width;height" |
the rectangle with its top-left corner at pixel left, top, sized width by height, in screen pixels |
PrtScr.exe -hardcopy |
the entire runtime screen |
Wire the call into a C action #
- In Graphics Designer, place a button beside the faceplate, or transparently over it if the operator should hit the faceplate itself to print.
- Open the C action editor on that button's mouse-click event and paste in the skeleton: the
#include "apdefap.h"line and the OnLButtonDown header that receives the picture name, the object name and the click coordinates. - Reserve two 255-byte buffers with SysMalloc, one for the picture name and one for the picture-window name.
- Fill them with GetParentPicture(lpszPictureName) and GetParentPictureWindow(lpszPictureName), which name the picture hosting the object and the picture window that contains it.
- Read the rectangle: GetLeft, GetTop, GetWidth and GetHeight, each called with the picture name and the picture-window name, return the window's position and size in pixels.
- Compose the /C= string from the four numbers and start the utility with WinExec.
- Release both buffers with SysFree before the action returns. Then save, activate runtime and click; the proving test is that the printed crop matches the faceplate on screen, window for window.
#include "apdefap.h"
void OnLButtonDown(char* lpszPictureName, char* lpszObjectName,
char* lpszPropertyName, UINT nFlags, int x, int y)
{
char *pPic, *pWin;
char cmd[255];
long int x_pos, y_pos, widthpar, heightpar;
pPic = SysMalloc(sizeof(char) * 255);
pWin = SysMalloc(sizeof(char) * 255);
strcpy(pPic, GetParentPicture(lpszPictureName));
strcpy(pWin, GetParentPictureWindow(lpszPictureName));
x_pos = GetLeft(pPic, pWin);
y_pos = GetTop(pPic, pWin);
widthpar = GetWidth(pPic, pWin);
heightpar = GetHeight(pPic, pWin);
sprintf(cmd, "PrtScr.exe /C= \"%ld;%ld;%ld;%ld\"",
x_pos, y_pos, widthpar, heightpar);
WinExec(cmd, SW_SHOWNORMAL);
SysFree(pPic);
SysFree(pWin);
}
The skeleton, the resolution calls and the WinExec line are the standard pattern for this job; the sprintf line and the cmd buffer are added here to make the example runnable end to end, and cmd is declared above as a plain character array. Because the rectangle is read at the moment of the click, the same action serves a faceplate anywhere on the screen, with nothing hardcoded. The action fires once per click and does nothing cyclically, so it cannot produce the stopped-refresh behavior covered in why a WinCC faceplate script does not auto-refresh; a faceplate that stops updating has a different cause. Keep the action to the plain call — if you extend it to load external code, check what the C-script environment accepts first, which is the subject of why a VB ActiveX DLL does not work from WinCC C-scripts.
A button laid over the faceplate intercepts the mouse events underneath it; where you want an overlay to ignore clicks instead of taking them, the technique in disable rectangle click in WinCC using C-script and SetOperation reverses that behavior.
Fixed region, full screen and the arithmetic #
Skip the resolution calls when the target never moves — a status strip, a header line:
/* print a fixed screen region */
WinExec("PrtScr.exe /C= \"392;300;80;40\"", SW_SHOWNORMAL);
/* print the whole screen */
WinExec("PRTSCR.EXE -hardcopy", SW_SHOWNORMAL);
Worked example, fixed region: the string "392;300;80;40" puts the top-left corner of the capture 392 pixels from the left edge and 300 pixels from the top, then takes 80 pixels of width and 40 of height. The rectangle runs from x = 392 to 392 + 80 = 472 and from y = 300 to 300 + 40 = 340, covering 80 x 40 = 3200 pixels — the size of a small status readout rather than a faceplate.
Worked example, faceplate: if the four resolution calls return left 1100, top 140, width 480 and height 360 for the picture window, the action composes "1100;140;480;360", which spans x = 1100 to 1100 + 480 = 1580 and y = 140 to 140 + 360 = 500. A fixed string stays valid as long as that window never moves; the resolved version tracks the window by itself.
Printers, parameters and landscape output #
Both calls print to the Windows default printer at the moment of the call, and no documented command-line switch names a different device. The decision: to print somewhere else — a PDF printer for archiving, a second printer at the line — make that device the Windows default before the call, and restore the original default afterwards if the station prints anything else.
PrtScr.exe reads its parameters once at start, so a change made during commissioning takes effect only after you end the running instance and start it again with the new parameters; that behavior is documented for WinCC V7.5 in support entry 109760739. The plain calls carry no orientation switch, and the vendor publishes a ready-made C script for landscape hardcopies in support document 22055343.
If the sheet comes out small on A4, the cause sits on the printer side of the chain rather than in the switch string; the fixes are worked through in resolving small A4 hardcopy printouts from PrtScr.exe.
A hardcopy is a snapshot of the screen pixels at the instant of the click, so where a documented record of process values is required, use tag logging or the reporting system, not a screen print.
The decision for each case #
- One faceplate with its values as displayed, position unknown at design time: the C action with GetParentPicture, GetParentPictureWindow and the four geometry calls, composed into the /C= string.
- A fixed strip that never moves: the fixed string, measured once against the runtime screen.
- The whole picture: the -hardcopy call.
- Output to a named printer or to PDF: change the Windows default printer around the call; the utility has no printer switch.
- Landscape: the published landscape script; on a hardcopy-only station, the default printer's own orientation setting.
- A record that has to stand as documentation: tag logging or reporting, not a hardcopy.
Questions asked
Does the printout show the values the faceplate had at the moment of the click?
Yes. PrtScr.exe captures the screen pixels at the instant the action runs, so the sheet shows whatever the faceplate displayed at that moment, including masked, flashing or stale values. Trigger the action after the picture and its values have settled, and not during a screen change, or the capture can catch a half-drawn picture. For a value history you can prove later, tag logging is the tool, not a screen print.
Does this work on a Comfort Panel or on WinCC Unified?
No. PrtScr.exe and the C action with the apdefap.h include belong to the classic WinCC PC runtime on Windows. Comfort Panels print through their own report and viewer functions, and WinCC Unified uses JavaScript-based scripting, so neither platform accepts this C action pattern. On those systems, use the platform's own screenshot and printing functions instead.
How do I print the hardcopy in landscape?
The /C= and -hardcopy calls carry no orientation switch. The documented route to landscape is the ready-made C script the vendor publishes for exactly this job; its support document carries the ID 22055343. For a station that only ever prints hardcopies, setting the wanted orientation on the default printer is the simple alternative.
Can the capture be saved to a file instead of printed?
Not with the calls shown here: the hardcopy utility's job is a printout to the default printer. To file screen images, run a standalone capture utility alongside the runtime and let it take the print key or a hotkey of its own; stations have used tools such as PrintKey2000 this way, with the operator choosing save or print in the tool's own dialog. That path runs outside WinCC and needs no project change.


