Consultor Eletrônico



Kbase 34729: How to print a screen shot (content of a window) from a 4GL program?
Autor   Progress Software Corporation - Progress
Acesso   Público
Publicação   5/10/1998
Solution ID: P4729

GOAL:

How to print the snapshot of window from 4GL?

GOAL:

Using the APPLY Statement in Progress 4GL, it is not possible to fill the keyboard buffer via PrntScrn or Alt+PrntScrn to copy the whole screen or the active window to the clipboard

FACT(s) (Environment):

Progress 8.X
Progress 9.X

FIX:

The code below shows you how to capture and print a snapshot of either
the whole screen or the active window using Windows API and ActiveX
programming techniques.

/* #define VK_SNAPSHOT 44 from the winuser.h include file */
&SCOPED-DEFINE VK_SNAPSHOT 44
DEFINE VARIABLE vchWord       AS COM-HANDLE NO-UNDO.
DEFINE VARIABLE viAltPrntScrn AS INTEGER    NO-UNDO.

DEFINE BUTTON btnPrintScreen
    LABEL "Print Whole &Screen":U
    SIZE 38 BY 1.14.

DEFINE BUTTON btnPrintWindow
    LABEL "Print Active &Window":U
    SIZE 38 BY 1.14.

DEFINE FRAME DEFAULT-FRAME
    btnPrintScreen AT ROW 2.43 COL 8
    btnPrintWindow AT ROW 2.43 COL 47
   WITH 1 DOWN NO-BOX KEEP-TAB-ORDER OVERLAY
        SIDE-LABELS NO-UNDERLINE THREE-D
        AT COL 1 ROW 1
        SIZE 93.3 BY 3.9.

ASSIGN
  CURRENT-WINDOW:TITLE         = "Sample program to simulate ":U +
                                 "the Windows' Print Screen ":U +
                             "functionality":U
  CURRENT-WINDOW:HEIGHT        = 3.91
  CURRENT-WINDOW:WIDTH         = 93.4
  CURRENT-WINDOW:ALWAYS-ON-TOP = TRUE.

ON CHOOSE OF btnPrintScreen,btnPrintWindow IN FRAME DEFAULT-FRAME
DO:
   ASSIGN viAltPrntScrn = IF SELF:NAME = "btnPrintScreen":U THEN
                            0
                          ELSE
                            1.
 /* Minimize this program before taking a snapshot of the screen */
   ASSIGN CURRENT-WINDOW:WINDOW-STATE = 2.
   PAUSE 1 NO-MESSAGE.
   RUN keybd_event({&VK_SNAPSHOT}, viAltPrntScrn, 0, 0).
   /* Restore this program's screen */
   ASSIGN CURRENT-WINDOW:WINDOW-STATE = 3.
   RUN initiateWordApplication NO-ERROR.
   IF ERROR-STATUS:ERROR THEN
   DO:
     MESSAGE "Error initializing MS-Word Application.":U
        VIEW-AS ALERT-BOX ERROR.
     RETURN.
   END.
   IF VALID-HANDLE(vchWord) THEN
   DO:
     vchWord:ENABLE-EVENTS('WordEvents':U).
     
MESSAGE "MS-Word is currently printing snapshot of the":U
             (IF viAltPrntScrn = 0 THEN
               "whole screen...":U
             ELSE
               "active window...":U).
     RUN printScreen.
     PAUSE 5 NO-MESSAGE.
     MESSAGE "MS-Word successfully printed snapshot of the":U
             (IF viAltPrntScrn = 0 THEN
               "whole screen!":U
             ELSE
               "active window!":U)
        VIEW-AS ALERT-BOX INFO.
     RUN closeWordApplication.
   END.
   ELSE
   DO:
     MESSAGE "Word Application does not have a valid handle"
             "within this program.":U
        VIEW-AS ALERT-BOX ERROR.
     RETURN.
   END.
   APPLY "CLOSE":U TO THIS-PROCEDURE.
   RETURN NO-APPLY.
END.

ENABLE ALL WITH FRAME DEFAULT-FRAME.
WAIT-FOR CLOSE OF THIS-PROCEDURE.

PROCEDURE keybd_event EXTERNAL "USER32.DLL":U:
   DEFINE INPUT  PARAMETER bVk         AS SHORT.
   DEFINE INPUT  PARAMETER bScan       AS SHORT.
   DEFINE INPUT  PARAMETER dwFlags     AS LONG.
   DEFINE INPUT  PARAMETER dwExtraInfo AS LONG.
END PROCEDURE.

PROCEDURE initiateWordApplication:
   CREATE "Word.Application":U vchWord NO-ERROR.
   IF ERROR-STATUS:ERROR THEN
     RETURN ERROR.
END PROCEDURE.

PROCEDURE printScreen:
   vchWord:Documents:ADD().
   NO-RETURN-VALUE vchWord:Selection:Paste().
   NO-RETURN-VALUE vchWord:ActiveDocument:PrintOut().
END PROCEDURE.

PROCEDURE closeWordApplication:
 NO-RETURN-VALUE vchWord:QUIT(FALSE,,).
END PROCEDURE.

PROCEDURE WordEvents.Quit:
 IF VALID-HANDLE(vchWord) THEN
   RELEASE OBJECT vchWord.
 ASSIGN vchWord = ?.
END PROCEDURE.