Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Problem with getPrinter() and SYS(1037)
Message
 
À
04/01/2000 15:35:38
Information générale
Forum:
Visual FoxPro
Catégorie:
Gestionnaire de rapports & Rapports
Divers
Thread ID:
00294947
Message ID:
00313554
Vues:
40
Stephane,

Forgive me if I go over board here but I feel that it is somethimes better to explain too much than to explain too little.

You will be needing to drop an ActiveX Control (OLE Control) onto your Form from the Forms Control Toolbar but before you do that you need to make sure that the Common Dialog Control is available.

From the main VFP menu go to Tools -> Options -> Controls. Select ActiveX Controls and select to "Show Insertable Objects" and "Controls". In the Selected: box check "Microsoft Common Dialog Control" and then click on "Set as Default" and then "OK".

Now, with your Form open, select the ActiveX Control (OLE Control) tool and drop it on your form. It won't show when the form is run so you can drop it anywhere. An "Insert Object" window will open. Select the "Insert Control" radio button and then select "Microsoft Common Dialog Control" and then "Add".

If you select the OLE Control icon that is now on your Form and open the Properties window, you will see the Methods and Properties that you can now read and/or modify. You will be using your button's Methods to interact and control the OLE Control's Properties and Methods, however. The key thing to notice in this OLE Control's Methods is that instead of a "Show" Method there are several because this ActiveX Control has several Dialog Controls imbedded. For the Set Printer Dialog Box to pop up you need to insert into your button's Click Event "THISFORM.oleControl1.showprinter" (assuming that your OLE Control is named oleControl1). Notice that instead of " Show" it is "ShowPrinter".

With SYS(1037) it was the VFP Default Printer that was getting set and not the Windows Default Printer. Even though there is a DefaultPrinter property in this ActiveX control I have found that using either .t. or .f. will still set the Windows Default Printer to what the user chooses. That is fine for me since I was having some problems with users selecting printers through Windows sometimes and through my app's SYS(1037) other times. I set DefaultPrinter to .t. just in case. To get the printer that the user selected, then, use SET('PRINTER',2) and then to change the VFP Default Printer issue a SET PRINTER TO NAME SET('Printer',2). Another way instead of SET('PRINTER') is to do ShowPrinter to a memvar as in:
lcPrinter = THISFORM.oleControl1.showprinter
The Control will return the printer that the user selected.

For all of this to work in a distributed application the ActiveX control needs to be registered on the user's system. If you use the Setup Wizard to distribute your application then check off "ActiveX Controls" in the first Setup Wizard window and then choose the "Microsoft Common Dialog Control" from the list. VFP's setup program will take care of the rest.

If, however, you are not using the Setup Wizard, then you need to register the ComDlg32.ocx control programmatically. You need to distribute not only the ComDlg32.ocx file but also the comcat.dll file and the Regsvr32.exe file. The comcat.dll file will be in your Windows\system directory but the Regsvr32.exe file could be in several possible places so do a Start -> Find to locate it.

To register the ocx, then, from your app issue a
RUN /N Regsvr32 /s ComDlg32.ocx.
The /N is like a NOWAIT and the /s is to run in silent mode where the user will not see any dialog box.

RUN Regsvr32 /u ComDlg32.ocx. will un-register the control if you need to for testing.

One last thing. If you want to run the ActiveX control programmatically and not by dropping it on a Form (like from a menu selection) do something like this:

oComDlg = CREATEOBJECT("MScomdlg.CommonDialog")
oComDlg.PrinterDefault = .t.
lcPrinter = oComDlg.showprinter
lnOrientation = oComDlg.Orientation
RELEASE oComDlg

Hope this helps.

Let me know if you have any problems.

Ed


>Can you send me an example of code using this control ?
>It will really helps me !
>
>
> >Stephane,
>>
>>I was able to finally solve the problem by using the Common Dialoge ActiveX Control (ComDlg32.ocx). It gives me must more control over the Set Printer Dialoge box and does not cause the crashes that sys(1037) did.
>>
>>Ed
>>
>>>no, sorry I didn't found something reallygood !
>>>
>>>The only way I found is to have to command button to print :
>>> (one with h the option "REPORT FORM .... PROMPT" and the other without it) :(
>>>
>>>good luck Ed !
>>>
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform