 |
Club Builder Foro de C++Builder en español
|
| Ver tema anterior :: Ver tema siguiente |
| Autor |
Mensaje |
laremi400 Master

Registrado: 12 May 2004Mensajes: 179
|
Publicado: Jue 11 May, 2006 2:32 pm Asunto: PrinterIndex |
|
|
Hola!!
Estoy intentando imprimir en dos impresoras distintas. Por una parte un documento y por otra una etiqueta.
Gracias a los códigos que ya hay por el foro he conseguidocambiar de impresora mediante:
| Código: | Printer()->PrinterIndex = Printer()->Printers->IndexOf(Printer()->Printers->Strings[la_que_yo_quiero]); |
El problema es que cambia de impresora pero las características que se han definido para cada una de ellas no cambian. He probado con Refresh() y nada.
La impresora en la que intento imprimir el documento es con la hoja en vertical y la etiqueta la imprimo en apaisado.
Esto ya lo consigo cambiando mediante Inicio->configuración->etc la impresora predeterminada, pero cuando lo hago por código no se entera de ese cambio de propiedades.
No sólo pierde el "apaisamiento"; también pierde el tamaño de la hoja, etc...
He probado GetDriver, pero no me permite recoger los parámetros de una impresora que no sea la predeterminada. Y si cojo los de la predeterminada con GetPrinter y luego cambio de impresora me pasa lo mismo.
¿Que estoy haciendo mal?. |
|
| Volver arriba |
|
 |
Miguel Angel Torres Master


Registrado: 23 Abr 2006Mensajes: 282Ubicación: Siegen, Alemania
|
Publicado: Vie 12 May, 2006 2:54 am Asunto: |
|
|
quería consultarte una cosa acerca de la impresion. ¿vos sabes como cuadrarle las márgenes de impresion desde código?, ya que yo he visto ejemplo aqui en el foro q imprimir por ejemplo la información contenida en un TMemo, pero lo único que he logrado cambiar es el espaciamiento, y la impresión me sale spr pegada a los bordes izquierdos de la hoja. Si sabes algo pues te recomiendo y si quieres ver lo que yo hice, en trucos esta un post mio donde dice lo que hago:
https://cppbuilder.es/viewtopic.php?t=11331
Suerte........ _________________ Entre más sé, sé que nada sé
----------------------------------
Miguel Angel Torres Arredondo
Siegen - Deutschland |
|
| Volver arriba |
|
 |
laremi400 Master

Registrado: 12 May 2004Mensajes: 179
|
Publicado: Vie 12 May, 2006 9:15 am Asunto: |
|
|
Hola.
No termino de entender que quieres decir con lo de los margenes.
Hay dos propiedades en el Printer():
Printer()->PageHeight; //alto en pixels
Printer()->PageWidth; //ancho en pixels
El problema es que son solo lectura y no las puedes cambiar. Para hacerlo debes usar el API. Aquí te va un ejemplo que he sacado de un link de un post del foro (no recuerdo cual)
| Código: |
void GetPrinters(TStrings *Drivers, TStrings *Devices, TStrings *Ports)
{
TStringList *PrinterList = new TStringList();
TIniFile *IniFile = new TIniFile("win.ini");
IniFile->ReadSectionValues("Devices", PrinterList);
for (int index = 0; index < PrinterList->Count; index++)
{
AnsiString Abuffer = PrinterList->Strings[index];
// parse the buffer to extract individual properties
Devices->Add(Abuffer.SubString(1, Abuffer.Pos("=") - 1));
Abuffer = Abuffer.SubString(Abuffer.Pos("=") + 1,
Abuffer.Length() - Abuffer.Pos("="));
Drivers->Add(Abuffer.SubString(1, Abuffer.Pos(",") - 1));
Ports->Add(Abuffer.SubString(Abuffer.Pos(",") + 1,
Abuffer.Length() - Abuffer.Pos(",")));
}
delete IniFile;
delete PrinterList;
}
//---------------------------------------------------------------------------
// This is the EnumPrinters method:
void Enum9xPrinters(TStrings *Drivers, TStrings *Devices, TStrings *Ports)
{
DWORD dwNeeded, dwNumPrinters;
EnumPrinters(PRINTER_ENUM_LOCAL, NULL, 2, NULL,
0, &dwNeeded, &dwNumPrinters);
unsigned char *buffer = new unsigned char[dwNeeded];
EnumPrinters(PRINTER_ENUM_LOCAL, NULL, 2, buffer,
dwNeeded, &dwNeeded, &dwNumPrinters);
LPPRINTER_INFO_2 lppi2;
for (int index = 0; index < (int)dwNumPrinters; index++)
{
lppi2 = (LPPRINTER_INFO_2)(buffer + index *
sizeof(PRINTER_INFO_2));
Devices->Add(lppi2->pPrinterName);
Ports->Add(lppi2->pPortName);
}
delete [] buffer;
EnumPrinterDrivers(NULL, NULL, 2, NULL, 0,
&dwNeeded, &dwNumPrinters);
buffer = new unsigned char[dwNeeded];
EnumPrinterDrivers(NULL, NULL, 2, buffer, dwNeeded,
&dwNeeded, &dwNumPrinters);
LPDRIVER_INFO_2 lpdi2;
for (int index = 0; index < (int)dwNumPrinters; index++)
{
lpdi2 = (LPDRIVER_INFO_2)(buffer + index *
sizeof(DRIVER_INFO_2));
AnsiString File = lpdi2->pDataFile;
File = ExtractFileName(File);
File = File.SubString(1, File.Length() -
ExtractFileExt(File).Length());
Drivers->Add(File);
}
delete [] buffer;
}
//---------------------------------------------------------------------------
// Here's how you use the above functions...
void __fastcall TForm1::EnumPrintersClick(TObject *Sender)
{
TStringList *Drivers = new TStringList();
TStringList *Devices = new TStringList();
TStringList *Ports = new TStringList();
Enum9xPrinters(Drivers, Devices, Ports);
// or use: GetPrinters(Drivers, Devices, Ports);
for (int index = 0; index < Drivers->Count; index++)
{
ListBox1->Items->Add(Drivers->Strings[index]);
ListBox1->Items->Add(Devices->Strings[index]);
ListBox1->Items->Add(Ports->Strings[index]);
ListBox1->Items->Add("------------------------");
}
delete Drivers;
delete Devices;
delete Ports;
}
//---------------------------------------------------------------------------
// You can either read the win.ini file to extract
// the default printer name, or use the PrintDlg()
// API function with the PD_RETURNDEFAULT flag...
// Method 1: GetProfileString()
void GetDefaultPrinter(char *printer_name)
{
char *def_string = "no printer";
char buffer[MAX_PATH];
GetProfileString("windows", "device", def_string,
buffer, MAX_PATH);
AnsiString Abuffer(buffer);
int first_comma = Abuffer.Pos(",");
strcpy(printer_name, Abuffer.SubString(1, first_comma - 1).c_str());
}
// Method 2: PrintDlg()
void GetDefaultPrinter2(char *printer_name)
{
PRINTDLG pd;
ZeroMemory(&pd, sizeof(PRINTDLG));
pd.lStructSize = sizeof(PRINTDLG);
pd.Flags = PD_RETURNDEFAULT;
if (PrintDlg(&pd))
{
LPDEVNAMES lpdn = (LPDEVNAMES)GlobalLock(pd.hDevNames);
CopyMemory((LPBYTE)printer_name,
((LPBYTE)lpdn + lpdn->wDeviceOffset),
lpdn->wOutputOffset - lpdn->wDeviceOffset);
GlobalUnlock(pd.hDevNames);
GlobalFree(pd.hDevNames);
GlobalFree(pd.hDevMode);
}
}
//---------------------------------------------------------------------------
// Here's how you use the above functions...
void __fastcall TForm1::Button1Click(TObject *Sender)
{
char printer_name[MAX_PATH];
GetDefaultPrinter(printer_name);
ShowMessage(printer_name);
GetDefaultPrinter2(printer_name);
ShowMessage(printer_name);
} |
Con esto se llama a una ventana que permite modificar las propiedades de la página.
Estas propiedades además (creo, no lo tengo claro) las puedes obtener de la funcion GetPrinter: (de la ayuda)
| Cita: |
void __fastcall GetPrinter(char * ADevice, char * ADriver, char * APort, int &ADeviceMode);
Description
Call GetPrinter to obtain information about the current printer.
ADevice is a buffer that receives the device name of the current printer. This is the name that appears in the Print Manager (for example, "Epson FX-80"). It is not the printer model name.
ADriver is a buffer that receives the driver name for the current printer. Some versions of Windows do not use printer driver names, in which case this buffer is unused. On versions of Windows that support printer driver names, this is the name of a printer driver (usually ‘WINSPOOL’).
APort is a buffer that receives the port used by the current printer. It is not used on 32-bit versions of Windows, but is included for backward compatibility.
DeviceMode returns the handle to a memory buffer containing a DEVMODE structure, which contains device-specific initialization data for the device driver. Use the GlobalLock function to convert this handle into a pointer to the structure. |
El problema es que yo no sé manejar esto. Además yo quiero hacer algo distinto. Quiero que el usuario modifique las propiedades de una impresora que no es la predeterminada, y usar esta nueva configuración para imprimir sin cambiar de impresora predeterminada.
A ver si esto sirve. |
|
| Volver arriba |
|
 |
Miguel Angel Torres Master


Registrado: 23 Abr 2006Mensajes: 282Ubicación: Siegen, Alemania
|
Publicado: Vie 12 May, 2006 2:19 pm Asunto: ok... |
|
|
con lo que me refiero a márgenes es a las MARGENES DE IMPRESIÓN, como quien dice a las superiores, inferiores, izquierda, derecha, "el espaciamiento entre el borde del papel y en donde comienza la impresión", lo que uno cuadra normalmente en word u otros programas, eso es lo que quiero saber cómo poder modificarlo, pq como te comentaba, al imprimir usando mi código, la impresión me sale spr pegada al borde del papel y no he podido dar con como cuadrar eso. si sabes algo respecto a eso te agradecería, suerte.... _________________ Entre más sé, sé que nada sé
----------------------------------
Miguel Angel Torres Arredondo
Siegen - Deutschland |
|
| Volver arriba |
|
 |
|
|
No puedes publicar temas nuevos en este foro No puedes responder a temas en este foro No puedes editar tus mensajes en este foro No puedes borrar tus mensajes en este foro No puedes votar en las encuestas de este foro
|
© 2002–2026 Club Builder · Funciona con phpBB.
|