Page 9 of 10
Re: *** Curso de C para programadores Harbour.
Posted: Sun Jul 11, 2021 5:59 am
by Otto
Hello friends,
To finish HTML report generator, I would need to change printer default from landscape to portrait and vice versa.
I found some C++ code. Maybe you could work on that in your course?
viewtopic.php?f=3&t=40526&p=242221&hilit=landscape&sid=ca5535308805b297ab04c27df561e23b#p242221https://www.amyuni.com/forum/viewtopic.php?t=1224Best regards,
Otto
Re: *** Curso de C para programadores Harbour.
Posted: Sun Jul 11, 2021 10:09 am
by xmanuel
Claro que sí Juan...
Y serás muy bienvenido!!!

Re: *** Curso de C para programadores Harbour.
Posted: Sun Jul 11, 2021 12:07 pm
by xmanuel
Hola Otto.
Para el curso haremos interfaces con una DLL.
Esa DLL será una de SQLite ya que quiero desarrollar una clase básica para acceder a SQLite.
De cualquier modo dame más información por si puedo ayudar...
Re: *** Curso de C para programadores Harbour.
Posted: Sun Jul 11, 2021 1:34 pm
by xmanuel
Hola Otto prueba esto:
Code: Select all | Expand
// Asigna orientacion desde C
short prnSetOrientation( short dmOrientationNew )
{
LPDEVMODE lpDevMode = ( LPDEVMODE ) GlobalLock( pd.hDevMode );
short dmOrientationOld = lpDevMode->dmOrientation;
lpDevMode->dmOrientation = dmOrientationNew;
ResetDC( pd.hDC, lpDevMode ) ); // Creo que te faltaba esto para que la parte hardware de la impresora se entere
GlobalUnlock( pd.hDevMode );
return dmOrientationOld;
}
// Asigna orientacion desde PRG
HB_FUNC( PRNSETORIENTATION )
{
short dmOrientationNew = hb_parnidef( 1, 0 );
hb_retni( prnSetOrientation( dmOrientationNew ) );
}
Mételo en donde tengas tu programa en C ya que veo que usas variables estaticas.
Re: *** Curso de C para programadores Harbour.
Posted: Sun Jul 11, 2021 6:08 pm
by Otto
Hello Manuel,
Thank you for your help.
At the moment I call up DAT files saved with RUNDLL32.EXE PRINTUI.DLL, PrintUIEntry to change the orientation.
I wanted to call the new function PRNSETORIENTATION (1), but I get errors when compiling and linking.
Can you please show me how I can insert the function in FW.
Best regards,
Otto
Code: Select all | Expand
#include "FiveWin.Ch"
function Main()
Setdefault()
hochformat()
landscape()
return NIL
//----------------------------------------------------------------------------//
function hochformat()
winexec('RUNDLL32.EXE PRINTUI.DLL,PrintUIEntry /Sr /n "Seminar" /a "c:\setprnter\Seminarhoch.dat"')
return nil
function landscape()
winexec('RUNDLL32.EXE PRINTUI.DLL,PrintUIEntry /Sr /n "Seminar" /a "c:\setprnter\Seminar.dat"')
return nil
function Setdefault()
winexec('RUNDLL32.EXE PRINTUI.DLL,PrintUIEntry /y /n "Seminar"')
return nil
/*
#pragma BEGINDUMP
// Asigna orientacion desde C
short prnSetOrientation( short dmOrientationNew )
{
LPDEVMODE lpDevMode = ( LPDEVMODE ) GlobalLock( pd.hDevMode );
short dmOrientationOld = lpDevMode->dmOrientation;
lpDevMode->dmOrientation = dmOrientationNew;
ResetDC( pd.hDC, lpDevMode ) ); // Creo que te faltaba esto para que la parte hardware de la impresora se entere
GlobalUnlock( pd.hDevMode );
return dmOrientationOld;
}
// Asigna orientacion desde PRG
HB_FUNC( PRNSETORIENTATION )
{
short dmOrientationNew = hb_parnidef( 1, 0 );
hb_retni( prnSetOrientation( dmOrientationNew ) );
}
#pragma ENDDUMP
*/
Re: *** Curso de C para programadores Harbour.
Posted: Mon Jul 12, 2021 7:19 am
by xmanuel
Hola Otto la tienes que añadir al archivo printdc.c de FWH
Re: *** Curso de C para programadores Harbour.
Posted: Mon Jul 12, 2021 8:09 am
by Otto
Hello Manuel,
My problem is that I need to print from TActiveX.
It seems that Fivewin creates a printer device context and not makes the default for this printer for all applications.
Printing from the web browser control I think is a different application.
Therefore, I would need the changes for all applications.
I have to see the changes here:

Best regards,
Otto
Re: *** Curso de C para programadores Harbour.
Posted: Mon Jul 12, 2021 8:19 am
by xmanuel
Posiblemente Windows mantenga una configuración para una aplicación y otro para el sistema...
Tendría que investigar.

Re: *** Curso de C para programadores Harbour.
Posted: Mon Jul 12, 2021 8:30 am
by Otto
Hello Manuel,
I found this code but do not know how to use.
Best regards,
Otto
Once the DEVMODE structure has been modified to suit our configuration, we can either create a
printer device context using the CreateDC API call:
Code: Select all
HDC hDC = CreateDC( _T( "winspool" ), szPrinter, NULL, lpDevMode );
Or make this configuration as the default for this printer and for all applications using this printer.
DWORD dw;
PRINTER_INFO_2 *pi2;
// get default printer info structure which contains the DEVMODE
GetPrinter( m_hPrinter, 2, NULL, 0, &dw );
pi2 = (PRINTER_INFO_2 *)GlobalAllocPtr( GHND, dw );
GetPrinter( m_hPrinter, 2, (LPBYTE)pi2, dw, &dw );
// set the new printer info structure
pi2->pDevMode = lpDevMode;
SetPrinter( m_hPrinter, 2, (LPBYTE)pi2, 0 );
GlobalFreePtr( pi2 );
// notify applications that the default DEVMODE has changed
SendMessageTimeout( HWND_BROADCAST, WM_DEVMODECHANGE, 0, (LPARAM)szPrinter,
SMTO_NORMAL, 1000, NULL );
Re: *** Curso de C para programadores Harbour.
Posted: Tue Jul 13, 2021 9:10 pm
by xmanuel
Intentaré mirarlo lo antes posible a ver si se consigue algo...
Re: *** Curso de C para programadores Harbour.
Posted: Tue Jul 13, 2021 9:44 pm
by xmanuel
Querido Otto, he traducido tu código y lo he aplicado al codigo enviado anteriormente:
Code: Select all | Expand
void SetStatusDefault( LPDEVMODE lpDevMode )
{
DWORD dw;
HANDLE m_hPrinter = NULL;
PRINTER_INFO_2 *pi2;
// get default printer info structure which contains the DEVMODE
GetPrinter( m_hPrinter, 2, NULL, 0, &dw );
pi2 = ( PRINTER_INFO_2 * ) GlobalAllocPtr( GHND, dw );
GetPrinter( m_hPrinter, 2, ( LPBYTE ) pi2, dw, &dw );
// set the new printer info structure
pi2->pDevMode = lpDevMode;
SetPrinter( m_hPrinter, 2, ( LPBYTE ) pi2, 0 );
GlobalFreePtr( pi2 );
// notify applications that the default DEVMODE has changed
SendMessageTimeout( HWND_BROADCAST, WM_DEVMODECHANGE, 0, ( LPARAM ) NULL, SMTO_NORMAL, 1000, NULL );
}
prnSetOrientation( short dmOrientationNew )
{
LPDEVMODE lpDevMode = ( LPDEVMODE ) GlobalLock( pd.hDevMode );
short dmOrientationOld = lpDevMode->dmOrientation;
lpDevMode->dmOrientation = dmOrientationNew;
SetStatusDefault( lpDevMode );
GlobalUnlock( pd.hDevMode );
return dmOrientationOld;
}
HB_FUNC( PRNSETORIENTATION )
{
short dmOrientationNew = hb_parnidef( 1, 0 );
hb_retni( prnSetOrientation( short dmOrientationNew ) );
}
Te recuerdo que lo tienes que añadir a printdc.c de FWH
No lo compilo por lo que si hay errores y no lo sabes resolver dimelos
Re: *** Curso de C para programadores Harbour.
Posted: Tue Jul 13, 2021 11:08 pm
by Otto
Hello Manuel,
Thank you for your help.
Unfortunately, I am not familiar with C functions.
I have inserted your code into printdc.c and integrated this file into my project.
I get the following error message:
Error E2188 C: \ FWH \ source \ winapi \ printdc.c 1228: Expression syntax in function HB_FUN_PRNSETORIENTATION
Warning W8004 C: \ FWH \ source \ winapi \ printdc.c 1229: 'dmOrientationNew' is assigned a value that is never used in function HB_FUN_PRNSETORIENTATION
*** 1 errors in compile ***
Best regards,
Otto
Re: *** Curso de C para programadores Harbour.
Posted: Wed Jul 14, 2021 10:22 am
by xmanuel
Ya he visto el problema:
Code: Select all | Expand
void SetStatusDefault( LPDEVMODE lpDevMode )
{
DWORD dw;
HANDLE m_hPrinter = NULL;
PRINTER_INFO_2 *pi2;
// get default printer info structure which contains the DEVMODE
GetPrinter( m_hPrinter, 2, NULL, 0, &dw );
pi2 = ( PRINTER_INFO_2 * ) GlobalAllocPtr( GHND, dw );
GetPrinter( m_hPrinter, 2, ( LPBYTE ) pi2, dw, &dw );
// set the new printer info structure
pi2->pDevMode = lpDevMode;
SetPrinter( m_hPrinter, 2, ( LPBYTE ) pi2, 0 );
GlobalFreePtr( pi2 );
// notify applications that the default DEVMODE has changed
SendMessageTimeout( HWND_BROADCAST, WM_DEVMODECHANGE, 0, ( LPARAM ) NULL, SMTO_NORMAL, 1000, NULL );
}
prnSetOrientation( short dmOrientationNew )
{
LPDEVMODE lpDevMode = ( LPDEVMODE ) GlobalLock( pd.hDevMode );
short dmOrientationOld = lpDevMode->dmOrientation;
lpDevMode->dmOrientation = dmOrientationNew;
SetStatusDefault( lpDevMode );
GlobalUnlock( pd.hDevMode );
return dmOrientationOld;
}
HB_FUNC( PRNSETORIENTATION )
{
short dmOrientationNew = hb_parnidef( 1, 0 );
hb_retni( prnSetOrientation( dmOrientationNew ) );
}
Prueba ahora...
Re: *** Curso de C para programadores Harbour.
Posted: Wed Jul 14, 2021 12:53 pm
by Otto
Hello Manuel,
now I get:
Error: Unresolved external '_GlobalAllocPtr' referenced from C:\WINHOTEL_ENTWICKLUNG_2021\XREPORT\RELEASE\PRINTDC.OBJ
Error: Unresolved external '_GlobalFreePtr' referenced from C:\WINHOTEL_ENTWICKLUNG_2021\XREPORT\RELEASE\PRINTDC.OBJ
Is it a problem, but I use xHarbour?
Can you also show me how to call this new function from FWH?
Best regards,
Otto
Re: *** Curso de C para programadores Harbour.
Posted: Thu Jul 15, 2021 1:11 pm
by xmanuel
Hola Otto modifica esto:
GlobalAllocPtr -> GlobalAlloc
GlobalFreePtr -> GlobalFree
Por otro lado he investigado un poco el tema y creo que he visto algo en el propio Harbour.