Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Printer name from hDC printer handle?
Message
General information
Forum:
Visual FoxPro
Category:
Windows API functions
Miscellaneous
Thread ID:
00931585
Message ID:
00931613
Views:
23
Hello Edmond.

I get the hDC handle to the printer but how do I use that handle to get a printer name? I have a feeling that it might have to do with the API GetPrinter but I'm stumped at this point.

You are making this too difficult < s >. You can do this all with native VFP. Simply create a toolbar class that contains a drop down list of the installed printers. This code in the Init() of the toolbar's dropdown list:
lnPrinters = APRINTERS( This.Parent.aPrintArray )
FOR lnIdx = 1 TO lnPrinters
  *** Note below that you are adding a leading space. This
  *** prevents a network printer from appearing
  *** disabled in the combo due the leading "\"
  This.Parent.aPrintArray[ lnIdx, 1 ] = SPACE( 1 ) + ;
  This.Parent.aPrintArray[ lnIdx, 1 ]
ENDFOR

*** Make Sure we have some printers
IF lnPrinters = 0
  RETURN
ENDIF

This.Requery()
For lnIdx = 1 TO lnPrinters
  IF UPPER(SET('PRINTER',2)) $ UPPER( This.Parent.aPrintArray[ lnIdx, 1 ] )
    This.Value = This.Parent.aPrintArray[ lnIdx, 1 ]
    EXIT
  Endif
ENDFOR
*** Make sure we actually have a valid printer
IF NOT EMPTY( This.Value )
  TRY
    SET PRINTER TO NAME ( ALLTRIM( This.Value ) )
  CATCH
  ENDTRY
ENDIF
You also need to put the code that sets the printer in the Valid of the drop down list.

Now, create a FormSet class that has its Visible property set to .F. In the Init of the formset, instantiate the custom print toolbar. Add a method called DoPreview to your formset. This code in the DoPreview() method:
LOCAL lcCaption, lcCmd
WITH This
  IF .FormCount = 1
    .ShowToolbar()
  ENDIF

  .oToolBar.cmdPrint.Enabled = .T.  &&Enable Print
  lcCmd = [REPORT FORM ( .cReportForm ) ] + ALLTRIM( .cScope ) + [ PREVIEW WINDOW Form1]
  &lcCmd
    
  *** Get rid of the formset after running the report
  IF TYPE( [Thisformset.oToolBar] ) = [O] AND NOT ISNULL( Thisformset.oToolBar )
    Thisformset.oToolBar.Release()
  ENDIF
  Thisformset.release()
  Thisformset.Hide()
ENDWITH
Now, in order to preview a report using your formset and custom toolbar, you use code like this:
*** Instantiate the correct form
loPreviewForm = NEWOBJECT( [frsReportPreview], [stdReport.vcx] )
IF VARTYPE( loPreviewForm ) = [O]
  WITH loPreviewForm 
    .Form1.Caption = .Form1.Caption + [ for My Spiffy Report ]
    .cReportForm = [SpiffyReport.frx]
  ENDWITH
  loPreviewForm.DoPreview()
  loPreviewForm = .NULL.
ENDIF
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform