Saving a form as an image to disk directory

General Help regarding HMG, Compilation, Linking, Samples

Moderator: Rathinagiri

Post Reply
bluebird
Posts: 172
Joined: Wed Sep 28, 2016 3:55 am
DBs Used: DBF

Saving a form as an image to disk directory

Post by bluebird »

Dear Amigos and amigas :)

The code below fails to save a form (Form_2) as an image file but code does work if I want to print that form.
Please instruct on what I am missing.

Form_2 previously initialized and activated prior to calling the code below.

Code: Select all

*------------------------------------------------------------*
FUNCTION SaveDisplayImage()
* Called From BUTTON SaveImg or ALT + P
*------------------------------------------------------------*
  LOCAL cImageFileName:="C:\HMGBox\"+" Form2 Display"+dtoc(date()) //+".jpg"
  LOCAL lPrint:=.F.,lSave:=.F., lSuccess:=.F., hBitmap1

  lSave :=msgYesNo("Do you want to Save "+cImageFileName)
  hBitmap1:=BT_BitmapCaptureWindow("Form_2",20,20,1060,960)

  If lSave
    BT_BitmapSaveFile(hBitmap1, cImageFileName,  BT_FILEFORMAT_JPG )
	lSuccess:=FILE(cImageFileName+".jpg")
    msgbox("Sudoku Image "+cImageFileName + iif(lSuccess," Was"," Was Not")+" Saved to Disk" )
  Endif
  lPrint:=msgYesNo("Do you want to Print the Clues?")

  if lPrint
    PrintClues(hBitmap1)
  endif
  BT_BitmapRelease( hBitmap1 )
RETURN NIL



*------------------------------------------------------------*
FUNCTION Printclues(hBitmap)
* Called From SaveDisplayImage()
*----------------------------------------------==--------------*
  //  This version assumes a regular letter page printing at 600dpi
  //  The letter page Width/Length ratio is 0.7727

  LOCAL lSuccess, IsPreview

  SELECT PRINTER Default TO lSuccess PREVIEW     COLOR  PRINTER_COLOR_MONOCHROME;
    ORIENTATION PRINTER_ORIENT_PORTRAIT

  If lSuccess == .F.
    MsgInfo('Print Error')
    Return
  EndIf

  SELECT PRINTER DIALOG  TO lSuccessVar
  If lSuccess = .F.
    MsgInfo('Print Dialog Error')
    Return
  EndIf

  start printdoc
  start printpage
  hDC := OpenPrinterGetPageDC()
  BT_DrawBitmap ( hDC, 40,  40, 4220, 4220*0.7727, BT_STRETCH, hBitmap )
  end printpage
  end printdoc

return NIL

Post Reply