Impression d'une image (Fichier JPG)
Bonjour,
j'ai des problèmes pour imprimer un fichier JPG sur les machines XP (SP3).
Sur toutes les machines Vista, ce code fonctionne sans problème.
J'utilise le code suivant
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44
| //---------------------------------------------------------------------------
//# Void TForm1::PrintFile(Filename)
// Print A File to default printer
//---------------------------------------------------------------------------
void __fastcall TVisdrawForm1::PrintFile(String FileName)
{
SHELLEXECUTEINFO execinfo; // Structure ShellExecute(Ex) info
//typedef struct _SHELLEXECUTEINFO {
// DWORD cbSize;
// ULONG fMask;
// HWND hwnd;
// LPCTSTR lpVerb;
// LPCTSTR lpFile;
// LPCTSTR lpParameters;
// LPCTSTR lpDirectory;
// int nShow;
// HINSTANCE hInstApp;
// LPVOID lpIDList;
// LPCTSTR lpClass;
// HKEY hkeyClass;
// DWORD dwHotKey;
// union {
// HANDLE hIcon;
// HANDLE hMonitor;
// } DUMMYUNIONNAME;
// HANDLE hProcess;
//} SHELLEXECUTEINFO, *LPSHELLEXECUTEINFO;
String action; // action to run
String params = "";
action = "print";
memset(&execinfo, 0, sizeof(execinfo));
execinfo.lpFile = FileName.c_str(); // programme
execinfo.cbSize = sizeof(execinfo);
execinfo.lpVerb = action.c_str(); // Action = Open
execinfo.fMask = SEE_MASK_NOCLOSEPROCESS;
execinfo.nShow = SW_SHOWDEFAULT;
execinfo.lpParameters = params.c_str(); // Parms
// Show Process or not
execinfo.nShow = SW_SHOW;
ShellExecuteEx(&execinfo); |
Sous Vista, ce code semble appeler WIA ou je peux alors m'occuper de de choisir l'imprimante, le format et puis confirmer. -> No problem
Sous XP, ce code appelle le "Windows Pictures and fax Viewer", ou je peux également choisir l'imprimante et le format. Quand je confirme le print, le Windows Pictures and fax viewer tourne indéfiniment, jsuqu'à ce que je le tue.
J'ai essayé en remplaçant
Code:
execinfo.fMask = SEE_MASK_NOCLOSEPROCESS;
par
Code:
execinfo.fMask = SEE_MASK_INVOKEIDLIST;
même résultat sous Vista.
Sous XP, nouvelle fenêtre "Welcome to Photo printing Wizard" où le sablier est permanent et il est impossible de continuer.
sans toucher à .fmask, c'est pareil à SEE_MASK_NOCLOSEPROCESS
j'ai fouillé partout.
J'ai trouvé cette technique dans la FAQ.
Code:
1 2 3 4 5 6 7
| Variant wzd, vct;
wzd = Variant::CreateObject("WIA.CommonDialog");
vct = Variant::CreateObject("WIA.Vector");
vct.OleProcedure("Add", FileName.c_str());
wzd.OleProcedure("ShowPhotoPrintingWizard", vct);
wzd = Unassigned;
vct = Unassigned; |
Cela fonctionne parfaitement sous Vista, mais sous XP, le bouton d'appel produit un bong et plus rien d'autre après.
Quelqu'un peut-il m'aider ?
NB ; j'ai également trouvé et lu le guide "Impression Avec C++ Builder" traduit par Jean-Pierre Blondelle mais j'y perd un peu mon latin.
En finalité, une autre technique que je voudrais essayer est celle ci-dessous trouvée sur le forum, mais mon fichier est un .jpg au lieu de .BMP et cela plante direct.
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
| Graphics::TBitmap* Bitmap = new Graphics::TBitmap();
Bitmap ->LoadFromFile("C:\\TestCCQ.bmp");
Printer()->BeginDoc();
int XPixelsParPouce = GetDeviceCaps(Printer()->Handle, LOGPIXELSX);
int YPixelsParPouce = GetDeviceCaps(Printer()->Handle, LOGPIXELSY);
int NomImprimableHorizPixels = GetDeviceCaps(Printer()->Handle, PHYSICALOFFSETX);
int NomImprimableVertiPixels = GetDeviceCaps(Printer()->Handle, PHYSICALOFFSETY);
int Marge_Gauche = 15;
int Marge_Haute = 85;
int Marge_Droite = 195;
int Marge_Basse = 280;
int Millimetres2PixelsGauche = Marge_Gauche / (25.4 / XPixelsParPouce);
int Millimetres2PixelsHaute = Marge_Haute / (25.4 / YPixelsParPouce);
int Millimetres2PixelsDroite = Marge_Droite / (25.4 / XPixelsParPouce);
int Millimetres2PixelsBasse = Marge_Basse / (25.4 / YPixelsParPouce);
TRect rect;
rect.Top = Millimetres2PixelsHaute - NomImprimableVertiPixels;
rect.Left = Millimetres2PixelsGauche - NomImprimableHorizPixels;
rect.Right = Millimetres2PixelsDroite - NomImprimableHorizPixels;
rect.Bottom = Millimetres2PixelsBasse - NomImprimableVertiPixels;
Printer()->Canvas->StretchDraw(rect, Bitmap);
Printer()->EndDoc(); |