I am using code from this thread: http://www.powerbasic.com/support/pb...ad.php?t=24583
to capture the contents of the screen - since they can be obscured by either sizing limitations on the users computer - or the taskbar, etc. Wanted to try and make sure all the contents of the window are there no matter what.
I have hit a snag - It seems that WM_PRINT only gets the non-client portion of the RichEdit control to print to the destination device context. Anybody have any idea why?
Any suggestions as to a possible workaround?
to capture the contents of the screen - since they can be obscured by either sizing limitations on the users computer - or the taskbar, etc. Wanted to try and make sure all the contents of the window are there no matter what.
I have hit a snag - It seems that WM_PRINT only gets the non-client portion of the RichEdit control to print to the destination device context. Anybody have any idea why?
Any suggestions as to a possible workaround?
Code:
#PBFORMS CREATED V1.51 '----------------------------------------------------------------------------------------------------------------- ' The first line in this file is a PB/Forms metastatement. ' It should ALWAYS be the first line of the file. Other ' PB/Forms metastatements are placed at the beginning and ' end of "Named Blocks" of code that should be edited ' with PBForms only. Do not manually edit or delete these ' metastatements or PB/Forms will not be able to reread ' the file correctly. See the PB/Forms documentation for ' more information. ' Named blocks begin like this: #PBFORMS BEGIN ... ' Named blocks end like this: #PBFORMS END ... ' Other PB/Forms metastatements such as: ' #PBFORMS DECLARATIONS ' are used by PB/Forms to insert additional code. ' Feel free to make changes anywhere else in the file. '----------------------------------------------------------------------------------------------------------------- #COMPILE EXE #DIM ALL '----------------------------------------------------------------------------------------------------------------- ' ** Includes ** '----------------------------------------------------------------------------------------------------------------- #PBFORMS BEGIN INCLUDES #IF NOT %DEF(%WINAPI) #INCLUDE "WIN32API.INC" #ENDIF #IF NOT %DEF(%RICHEDIT_INC) #INCLUDE "RICHEDIT.INC" #ENDIF #INCLUDE "PBForms.INC" #PBFORMS END INCLUDES '----------------------------------------------------------------------------------------------------------------- '----------------------------------------------------------------------------------------------------------------- ' ** Constants ** '----------------------------------------------------------------------------------------------------------------- #PBFORMS BEGIN CONSTANTS %IDD_DIALOG_CAPTURETEST = 101 %IDC_RICHEDIT1 = 1001 %IDC_BUTTON1 = 1002 %IDC_BUTTON2 = 1003 %IDC_BUTTON3 = 1004 %IDC_BUTTON4 = 1005 %IDC_BUTTON_CAPTURE = 1006 #PBFORMS END CONSTANTS '----------------------------------------------------------------------------------------------------------------- '----------------------------------------------------------------------------------------------------------------- ' ** Declarations ** '----------------------------------------------------------------------------------------------------------------- DECLARE CALLBACK FUNCTION ShowDIALOG_CAPTURETESTProc() DECLARE FUNCTION ShowDIALOG_CAPTURETEST(BYVAL hParent AS DWORD) AS LONG #PBFORMS DECLARATIONS '----------------------------------------------------------------------------------------------------------------- '----------------------------------------------------------------------------------------------------------------- ' ** Main Application Entry Point ** '----------------------------------------------------------------------------------------------------------------- FUNCTION PBMAIN() PBFormsRichEdit () ' Load RichEdit ShowDIALOG_CAPTURETEST %HWND_DESKTOP PBFormsRichEdit (%TRUE) ' Unload RichEdit END FUNCTION '----------------------------------------------------------------------------------------------------------------- '----------------------------------------------------------------------------------------------------------------- ' hWnd, form or control to print to file. ' sFileName, file to save to, if "" the hDIB (hBITMAP) handle is returned FUNCTION FormToFile( BYVAL hWnd AS LONG, BYVAL sFileName AS STRING ) AS LONG DIM FF AS LONG DIM hDC AS LONG DIM hMemDC AS LONG DIM hDIB AS LONG DIM hOldDIB AS LONG DIM bm AS BITMAP DIM bmi AS BITMAPINFO DIM lpBITMAPFILEHEADER AS BITMAPFILEHEADER DIM lpBITMAPINFOHEADER AS BITMAPINFOHEADER DIM PA AS POINTAPI DIM PA1 AS POINTAPI DIM R AS Rect IF hWnd = 0 THEN EXIT FUNCTION IF IsWindow( hWnd ) = 0 THEN EXIT FUNCTION '// Measure window GetWindowRect hWnd, R ClientToScreen hWnd, PA '// Create a memory dc. hDC = GetDC( hWnd ) hMemDC = CreateCompatibleDC( hDC ) '// Make it a DIB. bmi.bmiHeader.biSize = SIZEOF( bmi.bmiHeader ) bmi.bmiHeader.biWidth = ( R.nRight - R.nLeft ) bmi.bmiHeader.biHeight = ( R.nBottom - R.nTop ) bmi.bmiHeader.biPlanes = 1 bmi.bmiHeader.biBitCount = 24 bmi.bmiHeader.biCompression = %BI_RGB hDIB = CreateDIBSection( hMemDC, bmi, %DIB_RGB_COLORS, 0, 0, 0 ) hOldDIB = SelectObject( hMemDC, hDIB ) RedrawWindow hWnd, BYVAL 0&, BYVAL 0&, %RDW_INTERNALPAINT OR %RDW_UPDATENOW OR %RDW_ALLCHILDREN '// Print the non-client area first. SendMessage hWnd, %WM_PRINT, hMemDC, %PRF_NONCLIENT '// Print the client area using an offset. OffsetWindowOrgEx hMemDC, R.nLeft - PA.x, R.nTop - PA.y, PA1 SendMessage hWnd, %WM_PRINT, hMemDC, %PRF_CHILDREN OR %PRF_CLIENT OR %PRF_OWNED OR %PRF_ERASEBKGND OffsetWindowOrgEx hMemDC, PA1.x, PA1.y, BYVAL 0& GetObject hDIB, SIZEOF( bm ), bm lpBITMAPFILEHEADER.bfType = CVI("BM") lpBITMAPFILEHEADER.bfSize = LEN(lpBITMAPFILEHEADER) + LEN(lpBITMAPINFOHEADER) + bm.bmWidthBytes * bm.bmHeight lpBITMAPFILEHEADER.bfOffBits = 54 lpBITMAPINFOHEADER.biSize = 40 lpBITMAPINFOHEADER.biWidth = bm.bmWidth lpBITMAPINFOHEADER.biHeight = bm.bmHeight lpBITMAPINFOHEADER.biPlanes = 1 lpBITMAPINFOHEADER.biBitCount = 24 lpBITMAPINFOHEADER.biSizeImage = 54& + bm.bmWidthBytes * bm.bmHeight IF sFileName > "" THEN FF = FREEFILE OPEN sFileName FOR OUTPUT AS #FF PRINT #FF, lpBITMAPFILEHEADER; PRINT #FF, lpBITMAPINFOHEADER; PRINT #FF, PEEK$( bm.bmBits, bm.bmWidthBytes * bm.bmHeight ); CLOSE #FF END IF SelectObject hMemDC, hOldDIB ReleaseDC hWnd, hDC DeleteDC hMemDC IF sFileName > "" THEN DeleteObject hDIB ELSE FUNCTION = hDIB END IF END FUNCTION '----------------------------------------------------------------------------------------------------------------- ' ** CallBacks ** '----------------------------------------------------------------------------------------------------------------- CALLBACK FUNCTION ShowDIALOG_CAPTURETESTProc() SELECT CASE AS LONG CBMSG CASE %WM_INITDIALOG ' Initialization handler CASE %WM_NCACTIVATE STATIC hWndSaveFocus AS DWORD IF ISFALSE CBWPARAM THEN ' Save control focus hWndSaveFocus = GetFocus() ELSEIF hWndSaveFocus THEN ' Restore control focus SetFocus(hWndSaveFocus) hWndSaveFocus = 0 END IF CASE %WM_COMMAND ' Process control notifications SELECT CASE AS LONG CBCTL CASE %IDC_RICHEDIT1 CASE %IDC_BUTTON1 IF CBCTLMSG = %BN_CLICKED OR CBCTLMSG = 1 THEN MSGBOX "%IDC_BUTTON1=" + FORMAT$(%IDC_BUTTON1), %MB_TASKMODAL END IF CASE %IDC_BUTTON2 IF CBCTLMSG = %BN_CLICKED OR CBCTLMSG = 1 THEN MSGBOX "%IDC_BUTTON2=" + FORMAT$(%IDC_BUTTON2), %MB_TASKMODAL END IF CASE %IDC_BUTTON3 IF CBCTLMSG = %BN_CLICKED OR CBCTLMSG = 1 THEN MSGBOX "%IDC_BUTTON3=" + FORMAT$(%IDC_BUTTON3), %MB_TASKMODAL END IF CASE %IDC_BUTTON4 IF CBCTLMSG = %BN_CLICKED OR CBCTLMSG = 1 THEN MSGBOX "%IDC_BUTTON4=" + FORMAT$(%IDC_BUTTON4), %MB_TASKMODAL END IF CASE %IDC_BUTTON_CAPTURE IF CBCTLMSG = %BN_CLICKED OR CBCTLMSG = 1 THEN FormToFile CBHNDL, "C:\CAPTURETEST.BMP" END IF END SELECT END SELECT END FUNCTION '----------------------------------------------------------------------------------------------------------------- '----------------------------------------------------------------------------------------------------------------- ' ** Dialogs ** '----------------------------------------------------------------------------------------------------------------- FUNCTION ShowDIALOG_CAPTURETEST(BYVAL hParent AS DWORD) AS LONG LOCAL lRslt AS LONG #PBFORMS BEGIN DIALOG %IDD_DIALOG_CAPTURETEST->-> LOCAL hDlg AS DWORD DIALOG NEW hParent, "WM_PRINT Capture Test", 70, 70, 298, 228, %WS_POPUP OR %WS_BORDER OR %WS_DLGFRAME OR _ %WS_SYSMENU OR %WS_MINIMIZEBOX OR %WS_CLIPSIBLINGS OR %WS_VISIBLE OR %DS_MODALFRAME OR %DS_3DLOOK OR _ %DS_NOFAILCREATE OR %DS_SETFONT, %WS_EX_CONTROLPARENT OR %WS_EX_LEFT OR %WS_EX_LTRREADING OR _ %WS_EX_RIGHTSCROLLBAR, TO hDlg CONTROL ADD PBFormsRichEdit(), hDlg, %IDC_RICHEDIT1, "RichEdit1", 5, 5, 290, 135, %WS_CHILD OR %WS_VISIBLE _ OR %WS_TABSTOP OR %WS_VSCROLL OR %WS_HSCROLL OR %ES_LEFT OR %ES_MULTILINE OR %ES_AUTOVSCROLL OR _ %ES_AUTOHSCROLL OR %ES_WANTRETURN, %WS_EX_CLIENTEDGE OR %WS_EX_LEFT OR %WS_EX_LTRREADING OR _ %WS_EX_RIGHTSCROLLBAR CONTROL ADD BUTTON, hDlg, %IDC_BUTTON1, "Button1", 5, 140, 50, 15 CONTROL ADD BUTTON, hDlg, %IDC_BUTTON2, "Button2", 5, 155, 50, 15 CONTROL ADD BUTTON, hDlg, %IDC_BUTTON3, "Button3", 5, 170, 50, 15 CONTROL ADD BUTTON, hDlg, %IDC_BUTTON4, "Button4", 5, 185, 50, 15 CONTROL ADD BUTTON, hDlg, %IDC_BUTTON_CAPTURE, "&Capture", 245, 210, 50, 15 #PBFORMS END DIALOG DIALOG SHOW MODAL hDlg, CALL ShowDIALOG_CAPTURETESTProc TO lRslt #PBFORMS BEGIN CLEANUP %IDD_DIALOG_CAPTURETEST #PBFORMS END CLEANUP FUNCTION = lRslt END FUNCTION '-----------------------------------------------------------------------------------------------------------------
Comment