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:
00931649
Views:
23
Marcia,

I really appreciate the response. It takes me awhile sometimes to finally realize that native Fox code is the way to go. I do tend to make things complicated by looking for the easiest way to do them <g>.

Some of my "reports" could actually consist of 1 or more separate reports. I didn't want to do a PRINTER PROMPT for each so I was hoping to catch the PROMPT selection on the fist one only and realized that it couldn't be done. My first thought was to pull up the equivalent Win API dialog box and capture the choice there but PrintDlg had pointers to structures within structures and got too complicated. That led me to CommonDialog, ShowPrinter, etc. etc. All of that because I wanted to keep it simple. I guess I had too much time on my hands.

The only thing that I see to add below is to captuer the VFP printer setting before the user's choice and then re-set it after this particular print job which would more parallel the PRINTER PROMPT logic.

Thanks again. This is a great help.

Ed

>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