FiveTech Support Forums

FiveWin / Harbour / xBase community
Board index FiveWin para Harbour/xHarbour *** Curso de C para programadores Harbour.
Posts: 6983
Joined: Fri Oct 07, 2005 07:07 PM
Re: *** Curso de C para programadores Harbour.
Posted: Sun Jul 11, 2021 05:59 AM

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=3t=40526p=242221hilit=landscapesid=ca5535308805b297ab04c27df561e23b#p242221

https://www.amyuni.com/forum/viewtopic.php?t=1224

Best regards,

Otto

&&&&

Posts: 817
Joined: Sun Jun 15, 2008 07:47 PM
Re: *** Curso de C para programadores Harbour.
Posted: Sun Jul 11, 2021 10:09 AM

Claro que sí Juan...
Y serás muy bienvenido!!! :D

______________________________________________________________________________

Sevilla - Andalucía
Posts: 817
Joined: Sun Jun 15, 2008 07:47 PM
Re: *** Curso de C para programadores Harbour.
Posted: Sun Jul 11, 2021 12:07 PM

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...

______________________________________________________________________________

Sevilla - Andalucía
Posts: 817
Joined: Sun Jun 15, 2008 07:47 PM
Re: *** Curso de C para programadores Harbour.
Posted: Sun Jul 11, 2021 01:34 PM
Hola Otto prueba esto:

Code (fw): Select all Collapse
// 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.
______________________________________________________________________________

Sevilla - Andalucía
Posts: 6983
Joined: Fri Oct 07, 2005 07:07 PM
Re: *** Curso de C para programadores Harbour.
Posted: Sun Jul 11, 2021 06:08 PM
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 (fw): Select all Collapse
#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



*/
Posts: 817
Joined: Sun Jun 15, 2008 07:47 PM
Re: *** Curso de C para programadores Harbour.
Posted: Mon Jul 12, 2021 07:19 AM

Hola Otto la tienes que añadir al archivo printdc.c de FWH

______________________________________________________________________________

Sevilla - Andalucía
Posts: 6983
Joined: Fri Oct 07, 2005 07:07 PM
Re: *** Curso de C para programadores Harbour.
Posted: Mon Jul 12, 2021 08:09 AM
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
Posts: 817
Joined: Sun Jun 15, 2008 07:47 PM
Re: *** Curso de C para programadores Harbour.
Posted: Mon Jul 12, 2021 08:19 AM

Posiblemente Windows mantenga una configuración para una aplicación y otro para el sistema...
Tendría que investigar. :roll:

______________________________________________________________________________

Sevilla - Andalucía
Posts: 6983
Joined: Fri Oct 07, 2005 07:07 PM
Re: *** Curso de C para programadores Harbour.
Posted: Mon Jul 12, 2021 08:30 AM

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 );

Posts: 817
Joined: Sun Jun 15, 2008 07:47 PM
Re: *** Curso de C para programadores Harbour.
Posted: Tue Jul 13, 2021 09:10 PM

Intentaré mirarlo lo antes posible a ver si se consigue algo...

______________________________________________________________________________

Sevilla - Andalucía
Posts: 817
Joined: Sun Jun 15, 2008 07:47 PM
Re: *** Curso de C para programadores Harbour.
Posted: Tue Jul 13, 2021 09:44 PM
Querido Otto, he traducido tu código y lo he aplicado al codigo enviado anteriormente:
Code (fw): Select all Collapse
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
______________________________________________________________________________

Sevilla - Andalucía
Posts: 6983
Joined: Fri Oct 07, 2005 07:07 PM
Re: *** Curso de C para programadores Harbour.
Posted: Tue Jul 13, 2021 11:08 PM

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

Posts: 817
Joined: Sun Jun 15, 2008 07:47 PM
Re: *** Curso de C para programadores Harbour.
Posted: Wed Jul 14, 2021 10:22 AM
Ya he visto el problema:

Code (fw): Select all Collapse
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...
______________________________________________________________________________

Sevilla - Andalucía
Posts: 6983
Joined: Fri Oct 07, 2005 07:07 PM
Re: *** Curso de C para programadores Harbour.
Posted: Wed Jul 14, 2021 12:53 PM

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

Posts: 817
Joined: Sun Jun 15, 2008 07:47 PM
Re: *** Curso de C para programadores Harbour.
Posted: Thu Jul 15, 2021 01:11 PM

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.

______________________________________________________________________________

Sevilla - Andalucía