Impression spécifique sous Visual Basic Express 2008

mindseu Messages postés 3 Date d'inscription samedi 14 avril 2007 Statut Membre Dernière intervention 22 octobre 2008 - 22 oct. 2008 à 08:56
mindseu Messages postés 3 Date d'inscription samedi 14 avril 2007 Statut Membre Dernière intervention 22 octobre 2008 - 22 oct. 2008 à 12:00
Bonjour,

Depuis plusieurs semaines, je scrute les sites afin de trouver solution à ma question mais sans résultat.

J'ai créé une application sous VBE 2008 qui permet de visionner des fichiers .doc ou Pdf en cliquant sur l'intitulé du fichier via un bouton. Tout fonctionne correctement.

Mais là, je coince. Je souhaite lancer l'impression de l'ensemble de mes fichiers en cliquant sur un bouton "Impression".
Grâce aux API, j'ai réussi à définir l'imprimante par défaut à utiliser et l'impression se lance correctement. Mais je veux imprimer des pages en couleurs et d'autres en noir et blanc.

J'ai vu qu'il fallait utiliser les fonctions OpenPrinter, ClosePrinter, SetPrinter avec les structures Devmode, Info_2, etc .... Mais je ne sais comment les utiliser et les morceaux de code que j'ai trouvé ne me permettent pas de le faire.

J'ai déjà posé ma question dans d'autres forums (MSDN, Developpez.com) mais aucune réponse à ce jour.
Aurais-je demandé quelque chose d'incompatible ou d'infaisable ?

Merci d'avance pour vos suggestions.

<!-- / message -->

2 réponses

lillith212 Messages postés 1229 Date d'inscription vendredi 16 novembre 2007 Statut Membre Dernière intervention 16 juin 2009
22 oct. 2008 à 10:54
Bonjour,

Avant de commencer je te previens de suite je ne programme pas en .net
Je suppose que tu ne veux pas voir apparaitre la boite de dialogue d'impression?
Pour l'impression en couleur pour les uns et en noir et blanc pour les autres...
Les documents sont dissociés comment?
Sinon tu peux le faire en 2 fois. D'abord les couleurs puis les noirs et blancs.

[javascript:alink_1.Click() GetLastError].

Remarks
The pDefault parameter enables you to specify the data type and device mode values that are used for printing documents submitted by the [mk:@MSITStore:C:\Program%20Files\Microsoft%20Visual%20Studio\MSDN98\98VSa\1036\GDI.chm::/devdoc/live/pdgrmm/prntspol_33n6.htm StartDocPrinter] function. However, you can override these values by using the [mk:@MSITStore:C:\Program%20Files\Microsoft%20Visual%20Studio\MSDN98\98VSa\1036\GDI.chm::/devdoc/live/pdgrmm/prntspol_109u.htm SetJob] function after a document has been started.

You can call the OpenPrinter function to open a handle to a print server or to determine the access rights that a client has to a print server. To do so, specify the name of the print server in the pPrinterName parameter, set the pDatatype and pDevMode members of the PRINTER_DEFAULTS structure to NULL, and set the DesiredAccess member to specify a server access mask value such as SERVER_ALL_ACCESS. When you are finished with the handle, pass it to the ClosePrinter function to close it.

Windows 95 and later: OpenPrinter ignores the DesiredAccess member of PRINTER_DEFAULTS.

Windows NT: Use the DesiredAccess member of the [mk:@MSITStore:C:\Program%20Files\Microsoft%20Visual%20Studio\MSDN98\98VSa\1036\GDI.chm::/devdoc/live/pdgrmm/prntspol_910y.htm PRINTER_DEFAULTS] structure to specify the access rights that you need to the printer. If you want to use the phPrinter handle to perform administrative tasks such as those provided by the [mk:@MSITStore:C:\Program%20Files\Microsoft%20Visual%20Studio\MSDN98\98VSa\1036\GDI.chm::/devdoc/live/pdgrmm/prntspol_13ua.htm SetPrinter] function, set DesiredAccess to PRINTER_ALL_ACCESS. If you just want to perform basic printing operations, PRINTER_ACCESS_USE is sufficient.

If a user does not have permission to open a specified printer or print server with the desired access, the OpenPrinter call will fail, and GetLastError will return the value ERROR_ACCESS_DENIED.

QuickInfo
  Windows NT: Requires version 3.1 or later.
  Windows: Requires Windows 95 or later.
  Windows CE: Unsupported.
  Header: Declared in winspool.h.
  Import Library: Use winspool.lib.
  Unicode: Implemented as Unicode and ANSI versions on Windows NT.

[javascript:alink_1.Click() GetLastError].

Remarks
When the ClosePrinter function returns, the handle hPrinter is invalid, regardless of whether the function has succeeded or failed.

QuickInfo
  Windows NT: Requires version 3.1 or later.
  Windows: Requires Windows 95 or later.
  Windows CE: Unsupported.
  Header: Declared in winspool.h.
  Import Library: Use winspool.lib.

[javascript:alink_1.Click() GetLastError].

Remarks
To modify the current printer settings, call the [mk:@MSITStore:C:\Program%20Files\Microsoft%20Visual%20Studio\MSDN98\98VSa\1036\GDI.chm::/devdoc/live/pdgrmm/prntspol_1gky.htm GetPrinter] function to retrieve the current settings into a [mk:@MSITStore:C:\Program%20Files\Microsoft%20Visual%20Studio\MSDN98\98VSa\1036\GDI.chm::/devdoc/live/pdgrmm/prntspol_9otu.htm PRINTER_INFO_2] structure, modify the members of that structure as necessary, and then call SetPrinter.

The SetPrinter function ignores the pServerName, AveragePPM, Status, and cJobs members of a PRINTER_INFO_2 structure.

Pausing a printer suspends scheduling of all print jobs for that printer, except for the one print job that may be currently printing. Print jobs can be submitted to a paused printer, but no jobs will be scheduled to print on that printer until printing is resumed. If a printer is cleared, all print jobs for that printer are deleted, except for the current print job.

Windows NT: For the [mk:@MSITStore:C:\Program%20Files\Microsoft%20Visual%20Studio\MSDN98\98VSa\1036\GDI.chm::/devdoc/live/pdgrmm/prntspol_9otu.htm PRINTER_INFO_2] and [mk:@MSITStore:C:\Program%20Files\Microsoft%20Visual%20Studio\MSDN98\98VSa\1036\GDI.chm::/devdoc/live/pdgrmm/prntspol_9a7m.htm PRINTER_INFO_3] structures that contain a pointer to a security descriptor, the function can set only those components of the security descriptor that the caller has permission to modify. To set particular security descriptor components, you must specify the necessary access rights when you call the [mk:@MSITStore:C:\Program%20Files\Microsoft%20Visual%20Studio\MSDN98\98VSa\1036\GDI.chm::/devdoc/live/pdgrmm/prntspol_9qnm.htm OpenPrinter] function to retrieve a handle to the printer. The following table shows the access rights required to modify the various security descriptor components.

Access right |Security Descriptor Component |----
WRITE_OWNER, Owner
Primary proup, ----
WRITE_DAC, Discretionary access-control list (DACL), ----
ACCESS_SYSTEM_SECURITY, System access-control list (SACL)

If the security descriptor contains a component that the caller does not have the access right to modify, SetPrinter fails. Those components of a security descriptor that you don't want to modify should be NULL or not be present, as appropriate. If you do not want to modify the security descriptor, and are calling SetPrinter with a PRINTER_INFO_2 structure, set the pSecurityDescriptor member of that structure to NULL.

Windows NT 5.0 and later: You can use level 7 with the [mk:@MSITStore:C:\Program%20Files\Microsoft%20Visual%20Studio\MSDN98\98VSa\1036\GDI.chm::/devdoc/live/pdgrmm/prntspol_7nqq.htm PRINTER_INFO_7] structure to publish, unpublish, or update directory service data for the printer. The directory service data for a printer includes all the data stored under the SPLDS_* keys by calls to the [mk:@MSITStore:C:\Program%20Files\Microsoft%20Visual%20Studio\MSDN98\98VSa\1036\GDI.chm::/devdoc/live/pdgrmm/prntspol_6o1k.htm SetPrinterDataEx] function for the printer. Before calling SetPrinter, set the pszObjectGUID member of PRINTER_INFO_7 to NULL and set the dwAction member to one of the following values.

Value |Description |----
DSPRINT_PUBLISH, Publish the directory service data., ----
DSPRINT_UNPUBLISH, Unpublish the directory service data., ----
DSPRINT_UPDATE, Update the directory service data. This is the same as DSPRINT_PUBLISH, except that SetPrinter fails with ERROR_FILE_NOT_FOUND if the printer is not already published.
Use DSPRINT_UPDATE to update published properties but not force publishing. Printer drivers should always use DSPRINT_UPDATE rather than DSPRINT_PUBLISH.

Windows 95:SetPrinter does not update the pShareName member in the PRINTER_INFO_2 structure.

You cannot call SetPrinter from a Windows 95 computer to set the data for a Windows NT printer using the printer's UNC name.

QuickInfo
  Windows NT: Requires version 3.1 or later.
  Windows: Requires Windows 95 or later.
  Windows CE: Unsupported.
  Header: Declared in winspool.h.
  Import Library: Use winspool.lib.
  Unicode: Implemented as Unicode and ANSI versions on Windows NT.

C'est les infos que j'ai trouvé.
Dans ton aide tu n'as pas d'exemple d'utilisation?
En tout cas, bon courage

S.L.B.
<hr />-- Le règlement tu liras -- Des recherches tu feras -- Le style SMS tu banniras --
-- De la validation pertinente tu feras -- Du respect tu auras -- <
0
mindseu Messages postés 3 Date d'inscription samedi 14 avril 2007 Statut Membre Dernière intervention 22 octobre 2008
22 oct. 2008 à 12:00
Merci pour ta réponse.

Mais mon souci réside dans l'utilisation de ces commandes. J'ai bien trouvé toutes ces fonctions mais je ne sait pas comment les utiliser.
Je sais que OpenPrinter doit lire une structure PRINTER_DEFAULT et que SetPrinter regarde la structure PRINTER_INFO_2. Mais c'est là que je bloque.

J'ai essayé bon nombre de morceau de codes présents ici mais sans réussite.
Je vais continuer à chercher en attendant d'autres coups de main.
0
Rejoignez-nous