Twitter iPhone pliant OnePlus 11 PS5 Disney+ Orange Livebox Windows 11

Imprimer sur une USB

4 réponses
Avatar
FoxLeREnard
J'ais un programme en "C" pur et dur ;-),

Il comprend un bouton "imprimer", dans ma toolbare,
Celmui-ci lance la boite de dialogue, qui propose le choix d'imprimante,
Puis le choix fait il lance l' impression du contenu d'une base de donnée.

J'ais toujours utilisé ce module, il marche chez moi, mais chez l'ami qui
l'utilise,
il ne marche que sur son imprimante port paraléle, et ne fait rien sur son
imprimante USB ??
Imprimante que j'ais testée .

Chez moi ça marche même sur une USB ???

Une idée ?
Merci d'avance
FoxLeRenard

4 réponses

Avatar
Christian ASTOR
On 25 mar, 12:51, "FoxLeREnard" wrote:
J'ais un programme en "C" pur et dur ;-),

Il comprend un bouton "imprimer", dans ma toolbare,
Celmui-ci lance la boite de dialogue, qui propose le choix d'imprimante,
Puis le choix fait il lance l' impression du contenu d'une base de donné e.

J'ais toujours utilisé ce module, il marche chez moi, mais chez l'ami qu i
l'utilise,
il ne marche que sur son imprimante port paraléle, et ne fait rien sur s on
imprimante USB ??



Comment se comporte chaque étape d'impression (récup printer DC,
StartDoc(), StartPage(), etc...) ?
Est-ce que ça imprime en contournant le driver (façon KB138594) ?
Avatar
FoxLeREnard
Pour te répondre ... en premier merci de ton intervention ...
Comme j'aias mis des modules dans une librairie a moi, j'ais tout regroupé
au mieux voila ce que ça donne
=============================================================================
// IMPRIME.C


extern HINSTANCE hInstx; // instance courante et UNIQUE
DWORD dwNeeded,i;
static char Temp[80],work[80],wrkcok[128],workx[128];
char nomImpr[128],nomDocument[128];
int dfr,xPage,yPage,xiPage,yiPage,xtPage,ytPage,Ptrai;
RECT rect;
HDC ImpHdc;
DOCINFO di;
DEVMODE dm;
PRINTDLG pd;
TEXTMETRIC tm;
LOGFONT lf ;
HFONT hFont;
SIZE size ;
DWORD NbrPrinter;
char LesPrinter[20][256],mesDrv[20][256];
int HtLig,nbr,Ledefaut,paspas;
char HtLigTXT[250];
unsigned int NbTbl,salig;
static char *MaFonte[10] = { "Courier New", "Arial","Brush","Script",
"Times New Roman","MS Sans Serif" } ;

//______________________________________________________
******* IMAGINES QUE DANS UNE PARTIE DE MON PROGRAMME J4 AIS
CECI************
int LaColImpx,lali;
LeNbrLig=1;
DebutdocPort(hWjpb);
ChoixFontT(1,20,700,0); // TnRoman 20 Gras
MonTxt(hWjpb,"Whaou Un TITRE ",16,1); // colone 100 ligne 1
LaColImpx=(LaColImp*xPage)/2276;
lali=(50*LaLigImp*yPage)/3282;
SetBkMode (ImpHdc, TRANSPARENT) ;
GetTextExtentPoint(ImpHdc,LeTxtImp, strlen (LeTxtImp), &size) ;
TextOut(ImpHdc,LaColImpx,lali,LeTxtImp,strlen(LeTxtImp));

***************************************************************************************
//______________________________________________________
void DebutdocPort(HWND hDlg)
{
DonneImpChoiDlg(hDlg);
if(ImpHdc)
{
if (StartDoc (ImpHdc, &di) > 0 )
{
dm.dmOrientation = DMORIENT_PORTRAIT; //##
ImpHdc = ResetDC( ImpHdc, &dm ); //##
StartPage (ImpHdc);
GetTextMetrics( ImpHdc, &tm );
xPage=GetDeviceCaps(ImpHdc,HORZRES); // parexemple 2276
yPage=GetDeviceCaps(ImpHdc,VERTRES); // parexemple 3282
if (xPage<100) xPage"76;
if (xPage<100) yPage282;
HtLig P;
Ptrai™;
xiPage=GetDeviceCaps(ImpHdc,LOGPIXELSX); // parexemple 300
yiPage=GetDeviceCaps(ImpHdc,LOGPIXELSY); // parexemple 300
xtPage=GetDeviceCaps(ImpHdc,ASPECTY); // parexemple 300
ytPage=GetDeviceCaps(ImpHdc,ASPECTY); // parexemple 300
dfr=0;
}
}
return;
}
//______________________________________________________
void DonneImpChoiDlg(HWND hDlg)
{
paspas=0;
DonneImpDlgJp(hDlg);
DialogBox(hInstx,"CHOIXMAIMP",hDlg,(DLGPROC)WndProcMaimp);
strcpy(nomDocument,"Impression en cours");
if(paspas!™) Onyva(hDlg,wrkcok);
paspas=0;
return;
}
//______________________________________________________
void DonneImpDlgJp(HWND hDlg)
{
LPPRINTER_INFO_5 pinfo5 ;
int enmoin,zz;
enmoin=0;
NbrPrinter=0;
Ledefaut=0;
EnumPrinters (PRINTER_ENUM_LOCAL,
NULL, 5, (LPBYTE) "", 0, &dwNeeded, &NbrPrinter) ;

if (pinfo5) HeapFree (GetProcessHeap (), 0, pinfo5) ;
pinfo5 = (LPPRINTER_INFO_5) HeapAlloc (GetProcessHeap (),
HEAP_NO_SERIALIZE, dwNeeded) ;

if (!pinfo5 || !EnumPrinters (PRINTER_ENUM_LOCAL,
NULL, 5, (LPBYTE) pinfo5, dwNeeded,
&dwNeeded, &NbrPrinter))
{
NbrPrinter=0;
return;
}
GetProfileString("windows","device", ",,,", work, sizeof(work));
for (i = 0;i<50; i++)
{
if(work[i]==',') work[i+1]=0;
if(work[i]==',') work[i]='';
}
for (i = 0;i< NbrPrinter; i++)
{
zz=i-enmoin;
strcpy(LesPrinter[zz],pinfo5->pPrinterName);
if (strcmp(LesPrinter[zz],work)==0) Ledefaut=zz;
GetProfileString("devices",LesPrinter[zz], ",,",Temp, sizeof(Temp));
strcpy(mesDrv[zz],LesPrinter[zz]);
strcat(mesDrv[zz],",");
strcat(mesDrv[zz],Temp);
pinfo5++ ;
}
NbrPrinter=NbrPrinter-enmoin;
return;
}

//______________________________________________________
BOOL APIENTRY WndProcMaimp(HWND hDlg,UINT msg,UINT wParam,LONG lParam)
{
DWORD idx,n;
switch (msg)
{
case WM_INITDIALOG:
ShowWindow (hDlg, SW_HIDE); //efface la Dlg pendant sa prepa
CenterWindow (hDlg, GetWindow (hDlg, GW_OWNER));
SetDlgItemText (hDlg,VOITXT_MAIMPRIMANTE,"Impression du
document sur");
n=NbrPrinter;
for (idx=0;idx<n;idx++)
SendDlgItemMessage(hDlg,MACB,CB_INSERTSTRING,
(WPARAM)(-1),(LPARAM)(LesPrinter[idx]));
SendDlgItemMessage(hDlg,MACB,CB_SELECTSTRING,
(WPARAM)(-1),(LPARAM)(LesPrinter[Ledefaut]));
ShowWindow (hDlg, SW_SHOW);
return (TRUE);
case WM_COMMAND:
if(LOWORD(wParam) == MONOK)
{
GetDlgItemText( hDlg,MACB,wrkcok,80);
GetDlgItemText( hDlg,MACB,nomImpr,80);
EndDialog(hDlg,TRUE);
return (TRUE);
}
if(LOWORD(wParam) == MONPASOK)
{
paspas™;
GetDlgItemText( hDlg,MACB,wrkcok,80);
GetDlgItemText( hDlg,MACB,nomImpr,80);
EndDialog(hDlg,TRUE);
return (TRUE);
}
break;
}
return (FALSE);
}

//______________________________________________________
void Onyva(HWND hDlg,char wrkcbon[128])
{
ImpHdc=CreateDC (NULL,wrkcbon, NULL, NULL) ;
if(ImpHdc!=0)
{
memset( &dm, 0, sizeof( dm ) );
dm.dmSpecVersion = DM_SPECVERSION;
dm.dmSize = sizeof( DEVMODE );
dm.dmFields = DM_ORIENTATION;

memset( &di, 0, sizeof( DOCINFO ) );
di.cbSize = sizeof( DOCINFO );
di.lpszDocName = "Edition Document";

EnableWindow( hDlg, FALSE );
}
return;
}
//______________________________________________________
void ImpTermine(HWND hDlg)
{
EndDoc( ImpHdc );
EnableWindow( hDlg, TRUE );
SetFocus( hDlg );
if(hFont) DeleteObject (SelectObject (ImpHdc, hFont)) ;
DeleteDC(ImpHdc);
if (pd.hDevMode) GlobalFree(pd.hDevMode);
if (pd.hDevNames) GlobalFree(pd.hDevNames);
return;
}
//______________________________________________________
void ChoixFontT(int CFont,int tail,int leBold,int leItal)
{
strcpy ((char *) lf.lfFaceName, MaFonte[CFont]) ;
lf.lfHeight=-MulDiv(tail,GetDeviceCaps(ImpHdc,LOGPIXELSY),72);
lf.lfWeight=leBold;
if(leItal==1) lf.lfItalic=TRUE;
else lf.lfItalicúLSE;
if(leItal==2) lf.lfUnderline=TRUE;
else lf.lfUnderlineúLSE;

hFont=(HFONT)SelectObject (ImpHdc,CreateFontIndirect (&lf)) ;
return;
}
//______________________________________________________

void PageFinEdit(HWND hDlg)
{
EndPage(ImpHdc);
ImpTermine(hDlg);
return;
}
//______________________________________________________

void MonRectangle(HWND hDlg,char LeTxtImp[250],int Hx,int Hy,int Bx,int By)
{
int Hxx,Hyx,Bxx,Byx;
if (Ptrai=™) //PORTRAIT
{
Hxx=(Hx*xPage)/2276;
Bxx=(Bx*xPage)/2276;
Hyx=(Hy*yPage)/3282;
Byx=(By*yPage)/3282;
}
if (Ptrai=ˆ) // LANDSCAPE
{
Hxx=(Hx*xPage)/3282;
Bxx=(Bx*xPage)/3282;
Hyx=(Hy*yPage)/2276;
Byx=(By*yPage)/2276;
}
SetBkMode (ImpHdc, TRANSPARENT) ;
SetRect(&rect,Hxx,Hyx,Bxx,Byx);
Rectangle(ImpHdc,rect.left,rect.top,rect.right,rect.bottom);

ExtTextOut(ImpHdc,Hxx+2,Hyx+2,ETO_CLIPPED,&rect,LeTxtImp,strlen(LeTxtImp),NULL);
return;
}
//______________________________________________________
Avatar
Alain
> Pour te répondre ... en premier merci de ton intervention ...
Comme j'aias mis des modules dans une librairie a moi, j'ais tout regroupé au
mieux voila ce que ça donne
============================================================================= >
// IMPRIME.C



tu devrais rajouter des message boxes ou traces dans un fichier à
chaque appel api critique pour savoir celui qui plante,
if appel_api() OK ... else messagebox d'erreur KO
car le code a l'air classique sinon
Avatar
FoxLeREnard
car le code a l'air classique sinon

Au moins tu me rassures !!

Tu as raisons je vais mettre un mouchard pour voir ou ça bute

Encore mille mercis