*** Curso de C para programadores Harbour.

Re: *** Curso de C para programadores Harbour.

Postby Otto » Sun Jul 11, 2021 5: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=3&t=40526&p=242221&hilit=landscape&sid=ca5535308805b297ab04c27df561e23b#p242221


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


Best regards,

Otto
********************************************************************
mod harbour - Vamos a la conquista de la Web
modharbour.org
https://www.facebook.com/groups/modharbour.club
********************************************************************
User avatar
Otto
 
Posts: 6005
Joined: Fri Oct 07, 2005 7:07 pm

Re: *** Curso de C para programadores Harbour.

Postby xmanuel » Sun Jul 11, 2021 10:09 am

Claro que sí Juan...
Y serás muy bienvenido!!! :D
______________________________________________________________________________
Sevilla - Andalucía
xmanuel
 
Posts: 756
Joined: Sun Jun 15, 2008 7:47 pm
Location: Sevilla

Re: *** Curso de C para programadores Harbour.

Postby xmanuel » 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
xmanuel
 
Posts: 756
Joined: Sun Jun 15, 2008 7:47 pm
Location: Sevilla

Re: *** Curso de C para programadores Harbour.

Postby xmanuel » Sun Jul 11, 2021 1:34 pm

Hola Otto prueba esto:

Code: Select all  Expand view

// 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
xmanuel
 
Posts: 756
Joined: Sun Jun 15, 2008 7:47 pm
Location: Sevilla

Re: *** Curso de C para programadores Harbour.

Postby Otto » Sun Jul 11, 2021 6: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: Select all  Expand view


#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



*/


 
********************************************************************
mod harbour - Vamos a la conquista de la Web
modharbour.org
https://www.facebook.com/groups/modharbour.club
********************************************************************
User avatar
Otto
 
Posts: 6005
Joined: Fri Oct 07, 2005 7:07 pm

Re: *** Curso de C para programadores Harbour.

Postby xmanuel » Mon Jul 12, 2021 7:19 am

Hola Otto la tienes que añadir al archivo printdc.c de FWH
______________________________________________________________________________
Sevilla - Andalucía
xmanuel
 
Posts: 756
Joined: Sun Jun 15, 2008 7:47 pm
Location: Sevilla

Re: *** Curso de C para programadores Harbour.

Postby Otto » Mon Jul 12, 2021 8: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:

Image

Best regards,
Otto
********************************************************************
mod harbour - Vamos a la conquista de la Web
modharbour.org
https://www.facebook.com/groups/modharbour.club
********************************************************************
User avatar
Otto
 
Posts: 6005
Joined: Fri Oct 07, 2005 7:07 pm

Re: *** Curso de C para programadores Harbour.

Postby xmanuel » Mon Jul 12, 2021 8: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
xmanuel
 
Posts: 756
Joined: Sun Jun 15, 2008 7:47 pm
Location: Sevilla

Re: *** Curso de C para programadores Harbour.

Postby Otto » Mon Jul 12, 2021 8: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 );
********************************************************************
mod harbour - Vamos a la conquista de la Web
modharbour.org
https://www.facebook.com/groups/modharbour.club
********************************************************************
User avatar
Otto
 
Posts: 6005
Joined: Fri Oct 07, 2005 7:07 pm

Re: *** Curso de C para programadores Harbour.

Postby xmanuel » Tue Jul 13, 2021 9:10 pm

Intentaré mirarlo lo antes posible a ver si se consigue algo...
______________________________________________________________________________
Sevilla - Andalucía
xmanuel
 
Posts: 756
Joined: Sun Jun 15, 2008 7:47 pm
Location: Sevilla

Re: *** Curso de C para programadores Harbour.

Postby xmanuel » Tue Jul 13, 2021 9:44 pm

Querido Otto, he traducido tu código y lo he aplicado al codigo enviado anteriormente:
Code: Select all  Expand view


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
xmanuel
 
Posts: 756
Joined: Sun Jun 15, 2008 7:47 pm
Location: Sevilla

Re: *** Curso de C para programadores Harbour.

Postby Otto » 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
********************************************************************
mod harbour - Vamos a la conquista de la Web
modharbour.org
https://www.facebook.com/groups/modharbour.club
********************************************************************
User avatar
Otto
 
Posts: 6005
Joined: Fri Oct 07, 2005 7:07 pm

Re: *** Curso de C para programadores Harbour.

Postby xmanuel » Wed Jul 14, 2021 10:22 am

Ya he visto el problema:

Code: Select all  Expand view



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
xmanuel
 
Posts: 756
Joined: Sun Jun 15, 2008 7:47 pm
Location: Sevilla

Re: *** Curso de C para programadores Harbour.

Postby Otto » 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
********************************************************************
mod harbour - Vamos a la conquista de la Web
modharbour.org
https://www.facebook.com/groups/modharbour.club
********************************************************************
User avatar
Otto
 
Posts: 6005
Joined: Fri Oct 07, 2005 7:07 pm

Re: *** Curso de C para programadores Harbour.

Postby xmanuel » Thu Jul 15, 2021 1: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
xmanuel
 
Posts: 756
Joined: Sun Jun 15, 2008 7:47 pm
Location: Sevilla

PreviousNext

Return to FiveWin para Harbour/xHarbour

Who is online

Users browsing this forum: No registered users and 76 guests