Impression avec ShellExecute

Résolu
Alambic Citizen Messages postés 8 Date d'inscription jeudi 15 février 2007 Statut Membre Dernière intervention 7 juin 2007 - 12 avril 2007 à 10:22
Alambic Citizen Messages postés 8 Date d'inscription jeudi 15 février 2007 Statut Membre Dernière intervention 7 juin 2007 - 12 avril 2007 à 12:40
Bonjour,

ShellExecute : super fonction pour ouvrir ou imprimer tout et n'importe quoi.
Gros problème : lorsque j'imprime un pdf (ou xls...), Acrobat (ou Excel...) s'ouvre (de façon visible j'entends). Y a t'il un moyen pour que les appli appelées restent en retrait (invisibles ou minimisées...).
Voici mon code :

Private Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" _
    (ByVal hwnd As Long, ByVal lpszOp As String, _
    ByVal lpszFile As String, ByVal lpszParams As String, _
    ByVal lpszDir As String, ByVal fsShowCmd As Long) As Long

r = ShellExecute(0, "print", fichier, "", "", 0)

avec fichier = "C:\doc.pdf" ou "C:\doc.xls" par exemple

Merci d'avance.

PS : il semble que le dernier parametre de la function n'ait aucune incidence pour les impressions (parametre "print")

4 réponses

Alambic Citizen Messages postés 8 Date d'inscription jeudi 15 février 2007 Statut Membre Dernière intervention 7 juin 2007
12 avril 2007 à 12:40
Y a pas de mal, d'autant que j'ai trouvé une ruse, avec SetWindowPos (trouvé ici, merci aux posteurs) utilisé juste aprés ShellExecute.

Donc dans le module :

DECLARATIONS

Private Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" _
    (ByVal hwnd As Long, ByVal lpszOp As String, _
    ByVal lpszFile As String, ByVal lpszParams As String, _
    ByVal lpszDir As String, ByVal fsShowCmd As Long) As Long

Declare Sub SetWindowPos Lib "User32" (ByVal hWnd As Long, ByVal hWndInsertAfter As Long, ByVal x As Long, ByVal Y As Long, ByVal cx As Long, ByVal cy As Long, ByVal wFlags As Long)

Global Const HWND_TOPMOST = -1
Global Const SWP_NOACTIVATE = &H10
Global Const SWP_SHOWWINDOW = &H40

LA PROCEDURE D'IMPRESSION

r = ShellExecute(0, "print", DocPath, "", "", 0)

SetWindowPos maFeuille.hWnd, HWND_TOPMOST, maFeuille.Left / 15, maFeuille.Top / 15, maFeuille.Width / 15, maFeuille.Height / 15, SWP_NOACTIVATE Or SWP_SHOWWINDOW

.. et maFeuille reste toujours visible !
3
cs_DARKSIDIOUS Messages postés 15814 Date d'inscription jeudi 8 août 2002 Statut Membre Dernière intervention 4 mars 2013 130
12 avril 2007 à 10:46
Si tu t'étais renseigné sur cette API, tu aurais vu que le dernier paramètre te permet de spécifier la visibilité du programme lancé :
W_HIDE, Hides the window and activates the executable file., ----
 , SW_MAXIMIZE, Maximizes the window., ----
 , SW_MINIMIZE, Minimizes the window. The next top-level window in the Z-order is activated., ----
 , SW_RESTORE, Activates the window even if it is hidden or minimized, ----
 , SW_SHOW, Activates the window and displays it in its original size and at its original position., ----
 , SW_SHOWMAXIMIZED, Activates the window. The window is displayed as maximized., ----
 , SW_SHOWMINIMIZED, Activates the window. The window is displayed as minimized., ----
 , SW_SHOWMINNOACTIVE, Activates the window as minimized. The active window retains the focus., ----
 , SW_SHOWNA, Activates the window in its current state but the active window retains the focus., ----
 , SW_SHOWNOACTIVATE, Displays the window in its most recent size and in its most recent position. The active window retains the focus., ----
 , SW_SHOWNORMAL, Displays the window in its original size and at its original position.
0
Alambic Citizen Messages postés 8 Date d'inscription jeudi 15 février 2007 Statut Membre Dernière intervention 7 juin 2007
12 avril 2007 à 11:34
Si tu avais lu mon mail, tu aurais lu :
"PS : il semble que le dernier parametre de la function n'ait aucune incidence pour les impressions (parametre "print") "
et donc vu que je m'étais renseigné un minimum  ...

En effet, ce parametre n'a d'incidence que dans le cas d'ouverture de programme ShellExecute(..."open", ..., SW_HIDE)
mais aucun effet lors d'une impression
ShellExecute(..."print", ..., SW_HIDE)
0
cs_DARKSIDIOUS Messages postés 15814 Date d'inscription jeudi 8 août 2002 Statut Membre Dernière intervention 4 mars 2013 130
12 avril 2007 à 11:54
Arf, autant pour moi j'étais pas aller jusqu'à la fin de ton message :o)

ben désolé alors, j'ai plus d'idées.
0
Rejoignez-nous