Hola buenos dias, tardes o noches...
Queria saber si alguien me puede ayudar con un codigo para imprimir (con impresora) ya que he estado buscando pero no encuentro uno funcional para c++ :-(
Es para un proyecto final de programacion y solo me falta el que se pueda imprimir los datos, ayuda! ;)
Buenas Pieshna.
¿Podrías dar mas detalles? SO por ejemplo, marca de impresora, puerto al que está conectada...
Un Saludo.
Cita de: SrMcLister en 7 Junio 2018, 14:07 PM
Buenas Pieshna.
¿Podrías dar mas detalles? SO por ejemplo, marca de impresora, puerto al que está conectada...
Un Saludo.
Hola, saludos SrMcLister
Estoy usando Windows 10 y estoy programando con dev-c++, la impresora es canon (MP 280), puertos LPT1-3, USB002
C++ no tiene soporte nativo para la impresion de documentos (al menos que yo sepa), la impresión está condicionada por el sistema operativo que uses, en este caso windows tiene sus drivers y un sistema de spooling, etc. Aqui tienes alguna informacion
https://msdn.microsoft.com/en-us/library/windows/desktop/dd162861(v=vs.85).aspx
https://msdn.microsoft.com/en-us/library/windows/desktop/ff819270(v=vs.85).aspx
De cualquier forma necesitas usar las APIs que te brinda tu sistema operativo y hacer las llamadas desde tu codigo c++. He encontrado este codigo por ahi pero no se si funcionara del todo, igual te podria servir
#include <stdio.h>
#include <windows.h>
#include <string.h>
void printer(char text[])
{
// Bring up a dialog to choose the printer
PRINTDLG pd = {0};
pd.lStructSize = sizeof( pd );
pd.Flags = PD_RETURNDEFAULT | PD_RETURNDC;
pd.nCopies=1;
// Show the printer Dialog
PrintDlg( &pd );
// Zero and then initialize the members of a DOCINFO structure.
DOCINFO di = {0};
di.cbSize = sizeof(DOCINFO);
di.lpszDocName = "Scribble Printout";
di.lpszOutput = (LPTSTR) NULL;
di.lpszDatatype = (LPTSTR) NULL;
di.fwType = 0;
// Begin a print job by calling the StartDoc function.
StartDoc(pd.hDC, &di);
// Inform the driver that the application is about to begin sending data.
StartPage(pd.hDC);
//here we put images\text or other DC things;)
//send some text
TextOut(pd.hDC,800,800,text, strlen(text));
//Lets close the printer
// Inform the driver that the page is finished.
EndPage(pd.hDC);
// Inform the driver that document has ended.
EndDoc(pd.hDC);
}
int main ()
{
printer("Hello world");
return 0;
}
Igual puedes buscarte la vida con alguna libreria, estas por ejemplo:
https://www.gtkmm.org/es/index.html
https://developer.gnome.org/gtkmm-tutorial/unstable/sec-printing-example.html.en#sec-printing-example-simple
https://www.codeproject.com/Articles/89/Printing-Class-Library
Saludos y buena suerte
Cita de: ThunderCls en 8 Junio 2018, 20:09 PM
C++ no tiene soporte nativo para la impresion de documentos (al menos que yo sepa), la impresión está condicionada por el sistema operativo que uses, en este caso windows tiene sus drivers y un sistema de spooling, etc. Aqui tienes alguna informacion
https://msdn.microsoft.com/en-us/library/windows/desktop/dd162861(v=vs.85).aspx
https://msdn.microsoft.com/en-us/library/windows/desktop/ff819270(v=vs.85).aspx
De cualquier forma necesitas usar las APIs que te brinda tu sistema operativo y hacer las llamadas desde tu codigo c++. He encontrado este codigo por ahi pero no se si funcionara del todo, igual te podria servir
#include <stdio.h>
#include <windows.h>
#include <string.h>
void printer(char text[])
{
// Bring up a dialog to choose the printer
PRINTDLG pd = {0};
pd.lStructSize = sizeof( pd );
pd.Flags = PD_RETURNDEFAULT | PD_RETURNDC;
pd.nCopies=1;
// Show the printer Dialog
PrintDlg( &pd );
// Zero and then initialize the members of a DOCINFO structure.
DOCINFO di = {0};
di.cbSize = sizeof(DOCINFO);
di.lpszDocName = "Scribble Printout";
di.lpszOutput = (LPTSTR) NULL;
di.lpszDatatype = (LPTSTR) NULL;
di.fwType = 0;
// Begin a print job by calling the StartDoc function.
StartDoc(pd.hDC, &di);
// Inform the driver that the application is about to begin sending data.
StartPage(pd.hDC);
//here we put images\text or other DC things;)
//send some text
TextOut(pd.hDC,800,800,text, strlen(text));
//Lets close the printer
// Inform the driver that the page is finished.
EndPage(pd.hDC);
// Inform the driver that document has ended.
EndDoc(pd.hDC);
}
int main ()
{
printer("Hello world");
return 0;
}
Igual puedes buscarte la vida con alguna libreria, estas por ejemplo:
https://www.gtkmm.org/es/index.html
https://developer.gnome.org/gtkmm-tutorial/unstable/sec-printing-example.html.en#sec-printing-example-simple
https://www.codeproject.com/Articles/89/Printing-Class-Library
Saludos y buena suerte
Muchas gracias lo probare y gracias también por los links con la información ;) ;-)