Kleyber wrote:Se puede seleccionar cualquier impressora? Tienes una pantalla que puedas poner aqui?
Kleiber y Armando,
Os reseño el mensaje antiguo, con todos los comentarios que se hicieron y las otras alternativas profesionales que se proponian:
http://fivetechsoft.com/forums/viewtopi ... ht=voil%E9Desconozco si las pequeñas modificaciones que realice (líneas donde figura Valdenebro), permite imprimir en todas las impresoras. A mi me funciona perfectamente, sobretodo, cuando quiero imprimir un documento como pdf, para adjuntarlo como justificante en un email. El único cambio "visual" en la pantalla, es que en la barra superior, aparece un combo para elegir una de las impresoras que tengamos instalada.
Aquí os pongo la clase completa modificada:
////////////////////////////////////////////////////
// clase RPREVIEW
// reformada por mcn Valdenebro para select printer
///////////////////////////////////////////////////
#include "FiveWin.ch"
#define DEVICE oWnd:cargo
#define GO_POS 0
#define GO_UP 1
#define GO_DOWN 2
#define GO_LEFT 1
#define GO_RIGHT 2
#define GO_PAGE .T.
#define VSCROLL_RANGE 20*nZFactor
#define HSCROLL_RANGE 20*nZFactor
#define TXT_FIRST LoadString( GetResources(), 07 )
#define TXT_PREVIOUS LoadString( GetResources(), 08 )
#define TXT_NEXT LoadString( GetResources(), 09 )
#define TXT_LAST LoadString( GetResources(), 10 )
#define TXT_ZOOM LoadString( GetResources(), 11 )
#define TXT_UNZOOM LoadString( GetResources(), 12 )
#define TXT_TWOPAGES LoadString( GetResources(), 13 )
#define TXT_ONEPAGE LoadString( GetResources(), 14 )
#define TXT_PRINT LoadString( GetResources(), 15 )
#define TXT_EXIT LoadString( GetResources(), 16 )
#define TXT_FILE LoadString( GetResources(), 17 )
#define TXT_PAGE LoadString( GetResources(), 18 )
#define TXT_PREVIEW LoadString( GetResources(), 03 )
#define TXT_PAGENUM LoadString( GetResources(), 19 )
#define TXT_A_WINDOW_PREVIEW_IS_ALLREADY_RUNNING ;
LoadString( GetResources(), 20 )
#define TXT_GOTO_FIRST_PAGE ;
LoadString( GetResources(), 21 )
#define TXT_GOTO_PREVIOUS_PAGE ;
LoadString( GetResources(), 22 )
#define TXT_GOTO_NEXT_PAGE ;
LoadString( GetResources(), 23 )
#define TXT_GOTO_LAST_PAGE ;
LoadString( GetResources(), 24 )
#define TXT_ZOOM_THE_PREVIEW ;
LoadString( GetResources(), 25 )
#define TXT_UNZOOM_THE_PREVIEW ;
LoadString( GetResources(), 26 )
#define TXT_PREVIEW_ON_TWO_PAGES ;
LoadString( GetResources(), 27 )
#define TXT_PREVIEW_ON_ONE_PAGE ;
LoadString( GetResources(), 28 )
#define TXT_PRINT_CURRENT_PAGE ;
LoadString( GetResources(), 29 )
#define TXT_EXIT_PREVIEW ;
LoadString( GetResources(), 30 )
#define TXT_FACTOR ;
LoadString( GetResources(), 31 )
#define TXT_ZOOM_FACTOR ;
LoadString( GetResources(), 32 )
#define MK_MBUTTON 16
static oWnd, oBar, oMeta1, oMeta2,;
oPage, oTwoPages, oZoom, oMenuZoom, oMenuTwoPages,;
oMenuUnZoom, oMenuOnePage, oFactor, cResFile
static aFactor
static nPage, nZFactor
static lTwoPages, lZoom
//----------------------------------------------------------------------------//
function RPreview( oDevice )
local aFiles := oDevice:aMeta
local hOldRes := GetResources()
local oSay
local nFor
local oWndMain := WndMain(), oIcon, oCursor, oMenu, oBrush, oFont
local l97Look := oWndMain != nil .and. oWndMain:oBar != nil .and. ;
Len( oWndMain:oBar:aControls ) > 0 .and. ;
oWndMain:oBar:aControls[ 1 ]:l97Look
local lExit := .F.
local oHand, oImageList, oReBar // , cPageNum
local aImpre := aGetPrinters(), oCbx, cCbx:=PrnGetName(), ;
cImpre := cCbx // mcn valdenebro
#ifdef __CLIPPER__
cResFile := "Preview.dll"
#else
if ! IsWin64()
cResFile := "Prev32.dll"
else
cResFile = "Prev64.dll"
endif
#endif
if SetResources(cResFile) < 32
MsgStop(cResFile + " no encontrado, imposible continuar",;
"FiveWin Error Impresión")
RETU nil
endif
if oWnd != nil
MsgStop(TXT_A_WINDOW_PREVIEW_IS_ALLREADY_RUNNING)
SetResources(hOldRes)
RETU nil
endif
if oWndMain != nil
oIcon = oWndMain:oIcon
else
DEFINE ICON oIcon RESOURCE "Print"
endif
if oDevice:lPrvModal .and. oWndMain != nil
oWndMain:Hide()
else
lExit := .T.
endif
DEFINE FONT oFont NAME GetSysFont() SIZE 0,-12
DEFINE CURSOR oCursor RESOURCE "Lupa"
DEFINE WINDOW oWnd FROM 0, 0 TO 24, 80 ;
TITLE oDevice:cDocument ;
COLOR CLR_BLACK,CLR_LIGHTGRAY ;
ICON oIcon ;
VSCROLL HSCROLL
// So IsAppThemed() is properly detected as the window is already built
oWnd:SetMenu( BuildMenu() )
oWnd:SetFont(oFont)
oWnd:oVScroll:SetRange(0,0)
oWnd:oHScroll:SetRange(0,0)
DEFINE CURSOR oHand HAND
if IsAppThemed()
DEFINE IMAGELIST oImageList SIZE 16, 16
oImageList:AddMasked( TBitmap():Define( "top2",, oWnd ), nRGB( 192, 192, 192 ) )
oImageList:AddMasked( TBitmap():Define( "previous2",, oWnd ), nRGB( 192, 192, 192 ) )
oImageList:AddMasked( TBitmap():Define( "next2",, oWnd ), nRGB( 192, 192, 192 ) )
oImageList:AddMasked( TBitmap():Define( "bottom2",, oWnd ), nRGB( 192, 192, 192 ) )
oImageList:AddMasked( TBitmap():Define( "zoom2",, oWnd ), nRGB( 192, 192, 192 ) )
oImageList:AddMasked( TBitmap():Define( "two_pages2",, oWnd ), nRGB( 192, 192, 192 ) )
oImageList:AddMasked( TBitmap():Define( "printer2",, oWnd ), nRGB( 255, 0, 255 ) )
oImageList:AddMasked( TBitmap():Define( "exit2",, oWnd ), nRGB( 192, 192, 192 ) )
oImageList:AddMasked( TBitmap():Define( "unzoom2",, oWnd ), nRGB( 192, 192, 192 ) )
oImageList:AddMasked( TBitmap():Define( "one_page2",, oWnd ), nRGB( 192, 192, 192 ) )
oReBar = TReBar():New( oWnd )
DEFINE TOOLBAR oBar OF oReBar SIZE 25, 25 IMAGELIST oImageList
oReBar:InsertBand( oBar )
oBar:nHeight -= 2
DEFINE TBBUTTON OF oBar ;
ACTION TopPage() ;
TOOLTIP Strtran(TXT_FIRST,"&","") ;
MESSAGE TXT_GOTO_FIRST_PAGE
DEFINE TBBUTTON OF oBar ;
ACTION PrevPage() ;
TOOLTIP Strtran(TXT_PREVIOUS,"&","") ;
MESSAGE TXT_GOTO_PREVIOUS_PAGE
DEFINE TBBUTTON OF oBar ;
ACTION NextPage() ;
TOOLTIP Strtran(TXT_NEXT,"&","") ;
MESSAGE TXT_GOTO_NEXT_PAGE
DEFINE TBBUTTON OF oBar ;
ACTION BottomPage() ;
TOOLTIP Strtran(TXT_LAST,"&","") ;
MESSAGE TXT_GOTO_LAST_PAGE
DEFINE TBSEPARATOR OF oBar
DEFINE TBBUTTON OF oBar ;
ACTION Zoom() ;
TOOLTIP Strtran(TXT_ZOOM,"&","") ;
MESSAGE TXT_ZOOM_THE_PREVIEW
DEFINE TBBUTTON OF oBar ;
ACTION TwoPages() ;
TOOLTIP StrTran( Strtran(TXT_TWOPAGES,"&",""), "á", "a" ) ;
MESSAGE TXT_PREVIEW_ON_TWO_PAGES
DEFINE TBSEPARATOR OF oBar
DEFINE TBBUTTON OF oBar ;
ACTION PrintPage() ;
TOOLTIP Strtran(TXT_PRINT,"&","") ;
MESSAGE TXT_PRINT_CURRENT_PAGE
DEFINE TBSEPARATOR OF oBar
DEFINE TBBUTTON OF oBar ;
ACTION oWnd:End() ;
TOOLTIP Strtran(TXT_EXIT,"&","") ;
MESSAGE TXT_EXIT_PREVIEW
else
DEFINE BUTTONBAR oBar _3D SIZE 26, If( LargeFonts(), 30, 26 ) OF oWnd
oBar:bRClicked := {|| nil }
if l97Look
DEFINE BUTTON RESOURCE "Top" OF oBar ;
MESSAGE TXT_GOTO_FIRST_PAGE ;
ACTION TopPage() ;
TOOLTIP Strtran(TXT_FIRST,"&","") NOBORDER
DEFINE BUTTON RESOURCE "Previous" OF oBar ;
MESSAGE TXT_GOTO_PREVIOUS_PAGE ;
ACTION PrevPage() ;
TOOLTIP Strtran(TXT_PREVIOUS,"&","") NOBORDER
DEFINE BUTTON RESOURCE "Next" OF oBar ;
MESSAGE TXT_GOTO_NEXT_PAGE ;
ACTION NextPage() ;
TOOLTIP Strtran(TXT_NEXT,"&","") NOBORDER
DEFINE BUTTON RESOURCE "Bottom" OF oBar ;
MESSAGE TXT_GOTO_LAST_PAGE ;
ACTION BottomPage() ;
TOOLTIP Strtran(TXT_LAST,"&","") NOBORDER
DEFINE BUTTON oZoom RESOURCE "Zoom" OF oBar GROUP ;
MESSAGE TXT_ZOOM_THE_PREVIEW ;
ACTION Zoom() ;
TOOLTIP Strtran(TXT_ZOOM,"&","") NOBORDER
DEFINE BUTTON oTwoPages RESOURCE "Two_Pages" OF oBar ;
MESSAGE TXT_PREVIEW_ON_TWO_PAGES ;
ACTION TwoPages() ;
TOOLTIP Strtran(TXT_TWOPAGES,"&","") NOBORDER
DEFINE BUTTON RESOURCE "Printer" OF oBar GROUP ;
MESSAGE TXT_PRINT_CURRENT_PAGE ;
ACTION PrintPage() ;
TOOLTIP Strtran(TXT_PRINT,"&","") NOBORDER
DEFINE BUTTON RESOURCE "Exit" OF oBar GROUP ;
MESSAGE TXT_EXIT_PREVIEW ;
ACTION oWnd:End() ;
TOOLTIP Strtran(TXT_EXIT,"&","") NOBORDER
else
DEFINE BUTTON RESOURCE "Top" OF oBar ;
MESSAGE TXT_GOTO_FIRST_PAGE ;
ACTION TopPage() ;
TOOLTIP Strtran(TXT_FIRST,"&","")
DEFINE BUTTON RESOURCE "Previous" OF oBar ;
MESSAGE TXT_GOTO_PREVIOUS_PAGE ;
ACTION PrevPage() ;
TOOLTIP Strtran(TXT_PREVIOUS,"&","")
DEFINE BUTTON RESOURCE "Next" OF oBar ;
MESSAGE TXT_GOTO_NEXT_PAGE ;
ACTION NextPage() ;
TOOLTIP Strtran(TXT_NEXT,"&","")
DEFINE BUTTON RESOURCE "Bottom" OF oBar ;
MESSAGE TXT_GOTO_LAST_PAGE ;
ACTION BottomPage() ;
TOOLTIP Strtran(TXT_LAST,"&","")
DEFINE BUTTON oZoom RESOURCE "Zoom" OF oBar GROUP ;
MESSAGE TXT_ZOOM_THE_PREVIEW ;
ACTION Zoom() ;
TOOLTIP Strtran(TXT_ZOOM,"&","")
DEFINE BUTTON oTwoPages RESOURCE "Two_Pages" OF oBar ;
MESSAGE TXT_PREVIEW_ON_TWO_PAGES ;
ACTION TwoPages() ;
TOOLTIP Strtran(TXT_TWOPAGES,"&","")
DEFINE BUTTON RESOURCE "Printer" OF oBar GROUP ;
MESSAGE TXT_PRINT_CURRENT_PAGE ;
ACTION PrintPage() ;
TOOLTIP Strtran(TXT_PRINT,"&","")
DEFINE BUTTON RESOURCE "Exit" OF oBar GROUP ;
MESSAGE TXT_EXIT_PREVIEW ;
ACTION oWnd:End() ;
TOOLTIP Strtran(TXT_EXIT,"&","")
endif
AEval( oBar:aControls, { | o | o:oCursor := oHand } )
endif
#ifdef __CLIPPER__
SET MESSAGE OF oWnd TO TXT_PREVIEW CENTERED ;
NOINSET CLOCK DATE KEYBOARD
#else
DEFINE STATUSBAR OF oWnd PROMPT " " + TXT_PREVIEW // CLOCK
#endif
oMeta1 := TMetaFile():New( 0, 0, 0, 0,;
aFiles[ 1 ],;
oWnd,;
CLR_BLACK,;
CLR_WHITE,;
oDevice:nHorzRes(),;
oDevice:nVertRes() )
oMeta1:oCursor := oCursor
oMeta1:blDblClick := { |nRow, nCol, nKeyFlags| ;
SetOrg1( nCol, nRow, nKeyFlags ) }
oMeta1:bKeyDown := {|nKey,nFlags| CheckKey(nKey,nFlags)}
oMeta1:bMouseWheel := { | nKeys, nDelta, nXPos, nYPos | ;
CheckMouseWheel( nKeys, nDelta, nXPos, nYPos ) }
#ifndef __XPP__ // XBPP bug. Warning: don't change this into #ifdef __CLIPPER__
oMeta2 := TMetaFile():New( 0,0,0,0,"",;
oWnd,CLR_BLACK,CLR_WHITE,oDevice:nHorzRes(),;
oDevice:nVertRes() )
#else
oMeta2 := TMetaFile():New():_New( 0,0,0,0,"",;
oWnd,CLR_BLACK,CLR_WHITE,oDevice:nHorzRes(),;
oDevice:nVertRes() )
#endif
oMeta2:oCursor := oCursor
oMeta2:blDblClick := {|nRow, nCol, nKeyFlags| ;
SetOrg2(nCol, nRow, nKeyFlags)}
oMeta2:hide()
nPage := 1
nZFactor := 1
lTwoPages := .F.
lZoom := .F.
@ 7, 275 SAY oSay PROMPT "Aumento: " ;
SIZE 60, 15 PIXEL OF oBar FONT oFont
// ha dado error
if IsAppThemed()
oSay:SetBrush( TBrush():New( "NULL" ) )
endif
@ 3, 325 COMBOBOX oFactor VAR nZFactor ;
ITEMS {"1","2","3","4","5","6","7","8","9"} ;
OF oBar FONT oFont PIXEL SIZE 35,200 ;
ON CHANGE SetFactor( nZFactor )
// modi Sebastian Almiron rectificar número de páginas en preview
@ 7, 410 SAY oPAGE PROMPT "Número de página: " + ltrim(str(nPage,4,0));
+" / "+ltrim(str(len(aFiles))) SIZE 180, 15 PIXEL OF oBar FONT oFont
// mcn Valdenebro para seleccionar impresora desde el preview
@ 3, 580 COMBOBOX oCbx VAR cCbx ;
PROMPTS aImpre ;
OF oBar FONT oFont PIXEL SIZE 150,200 ;
ON CHANGE F_CamImpre(oDevice,cCbx)
if IsAppThemed()
FixSays( oBar:hWnd )
endif
#ifndef __XPP__
oFactor:Set3dLook()
#endif
oWnd:cargo := oDevice
WndCenter( oWnd:hWnd )
SysRefresh()
SetResources(hOldRes)
oWnd:oHScroll:bPos := {|nPos| hScroll(GO_POS, .f., nPos)}
oWnd:oVScroll:bPos := {|nPos| vScroll(GO_POS, .f., nPos)}
// mcn valdenebro para salir con escape
oWnd:bKeyDown := {|nK| if( nK != VK_ESCAPE, , oWnd:End() ) }
SetFactor()
ACTIVATE WINDOW oWnd ;
MAXIMIZED ;
ON RESIZE PaintMeta() ;
ON UP vScroll(GO_UP) ;
ON DOWN vScroll(GO_DOWN) ;
ON PAGEUP vScroll(GO_UP,GO_PAGE) ;
ON PAGEDOWN vScroll(GO_DOWN,GO_PAGE) ;
ON LEFT hScroll(GO_LEFT) ;
ON RIGHT hScroll(GO_RIGHT) ;
ON PAGELEFT hScroll(GO_LEFT,GO_PAGE) ;
ON PAGERIGHT hScroll(GO_RIGHT,GO_PAGE) ;
VALID (oWnd:oIcon := nil ,;
oFont:End() ,;
oMeta1:End() ,;
oMeta2:End() ,;
F_CamImpre(oDevice, cImpre),;
oDevice:End() ,;
oHand:End() ,;
oWnd := nil ,;
If( IsAppThemed(), oImageList:End(),),;
lExit := .T. ,;
.T.)
StopUntil( {|| lExit} )
if oDevice:lPrvModal .and. oWndMain != nil
oWndMain:Show()
endif
return (nil)
//----------------------------------------------------------------------------//
static function BuildMenu()
local nFor, oMenu
local lThemed := IsAppThemed()
local cPrinter := If( lThemed, "Printer2", "Printer" )
local cTop := If( lThemed, "Top2", "Top" )
local cPrevious := If( lThemed, "Previous2", "Previous" )
local cNext := If( lThemed, "Next2", "Next" )
local cBottom := If( lThemed, "Bottom2", "Bottom" )
local cZoom := If( lThemed, "Zoom2", "Zoom" )
local cUnZoom := If( lThemed, "UnZoom2", "UnZoom" )
local cOne_Page := If( lThemed, "One_page2", "One_page" )
local cTwo_Pages := If( lThemed, "Two_pages2", "Two_pages" )
local cExit := If( lThemed, "Exit2", "Exit" )
aFactor := Array(9)
MENU oMenu
MENUITEM TXT_FILE
MENU
MENUITEM TXT_PRINT ACTION PrintPage() ;
MESSAGE TXT_PRINT_CURRENT_PAGE RESOURCE cPrinter
SEPARATOR
MENUITEM TXT_EXIT ACTION oWnd:End() ;
MESSAGE TXT_EXIT_PREVIEW RESOURCE cExit
ENDMENU
MENUITEM TXT_PAGE
MENU
MENUITEM TXT_FIRST ACTION TopPage() ;
MESSAGE TXT_GOTO_FIRST_PAGE RESOURCE cTop
MENUITEM TXT_PREVIOUS ACTION PrevPage() ;
MESSAGE TXT_GOTO_PREVIOUS_PAGE RESOURCE cPrevious
MENUITEM TXT_NEXT ACTION NextPage() ;
MESSAGE TXT_GOTO_NEXT_PAGE RESOURCE cNext
MENUITEM TXT_LAST ACTION BottomPage() ;
MESSAGE TXT_GOTO_LAST_PAGE RESOURCE cBottom
SEPARATOR
MENUITEM oMenuZoom PROMPT TXT_ZOOM ACTION Zoom(.T.) ;
ENABLED ;
MESSAGE TXT_ZOOM_THE_PREVIEW RESOURCE cZoom
MENUITEM oMenuUnZoom PROMPT TXT_UNZOOM ACTION Zoom(.T.) ;
MESSAGE TXT_UNZOOM_THE_PREVIEW RESOURCE cUnZoom
MENUITEM "&Factor" MESSAGE TXT_ZOOM_FACTOR
MENU
FOR nFor := 1 TO len(aFactor)
MENUITEM aFactor[nFor] ;
PROMPT "&"+ltrim(str(nFor)) ;
MESSAGE "Factor " + LTrim( Str( nFor ) ) ;
ACTION ( oFactor:Set( oMenuItem:nHelpId ),;
Eval( oFactor:bChange ) )
NEXT
ENDMENU
SEPARATOR
MENUITEM oMenuTwoPages PROMPT TXT_TWOPAGES ACTION TwoPages(.T.) ;
ENABLED ;
MESSAGE TXT_PREVIEW_ON_TWO_PAGES RESOURCE cTwo_Pages
MENUITEM oMenuOnePage PROMPT TXT_ONEPAGE ACTION TwoPages(.T.) ;
MESSAGE TXT_PREVIEW_ON_ONE_PAGE RESOURCE cOne_Page
ENDMENU
ENDMENU
oMenuUnZoom:Disable()
oMenuOnePage:Disable()
return oMenu
//----------------------------------------------------------------------------//
static function PaintMeta()
local oCoors1, oCoors2
local aFiles := DEVICE:aMeta
local nWidth, nHeight, nFactor, nMetaWidth
if IsIconic(oWnd:hWnd)
RETU nil
endif
DO case
case ! lTwoPages
if ! lZoom
if DEVICE:nHorzSize() >= ; // landscape (apaisado)
DEVICE:nVertSize()
nFactor := .8 // .4
else
nFactor := .40 // .25
endif
else
nFactor := .47
endif
nWidth = oWnd:nWidth() - If( lZoom, 20, 0 )
nHeight = oWnd:nHeight() - If( lZoom .and. nZFactor > 1, 20, 0 ) - 10 - ;
If( LargeFonts(), 100, 80 )
if ! lZoom
nMetaWidth = ( nHeight - 40 ) * nFactor
else
nMetaWidth = nWidth * nFactor
endif
oCoors1 := TRect():New( 40,;
Max( ( nWidth / 2 ) - nMetaWidth, 10 ),;
nHeight,;
Min( ( nWidth / 2 ) + nMetaWidth, nWidth - 20 ) )
oMeta2:Hide()
oMeta1:SetCoors( oCoors1 )
oMeta1:Refresh()
case lTwoPages
nFactor := .4
aFiles := DEVICE:aMeta
nWidth := oWnd:nWidth()
nHeight := oWnd:nHeight() - 10 - If( LargeFonts(), 100, 80 )
nMetaWidth = Min( ( nHeight - 40 ) * nFactor, ( nWidth - 60 ) / 4 )
oCoors1 := TRect():New(40,;
( nWidth / 4 ) - nMetaWidth,;
nHeight,;
( nWidth / 4 ) + nMetaWidth )
oCoors2 := TRect():New(40,;
( nWidth / 4 ) - nMetaWidth + ( nWidth / 2 ),;
nHeight,;
( nWidth / 4 ) + nMetaWidth + ( nWidth / 2 ) )
if nPage == Len(aFiles)
oMeta2:SetFile("")
else
oMeta2:SetFile(aFiles[nPage+1])
endif
oMeta1:SetCoors(oCoors1)
oMeta2:SetCoors(oCoors2)
oMeta1:Refresh()
oMeta2:Show()
endcase
oMeta1:SetFocus()
return nil
//----------------------------------------------------------------------------//
static function NextPage()
local hOldRes := GetResources()
local aFiles := DEVICE:aMeta
if nPage >= len(aFiles)
MessageBeep()
RETU nil
endif
nPage++
SET RESOURCES TO cResFile
oMeta1:SetFile( aFiles[ nPage ] )
oPage:SetText( TXT_PAGENUM + LTrim( Str( nPage, 4, 0 ) ) + " / " + ;
LTrim( Str( Len( aFiles ) ) ) )
oBar:Refresh()
oMeta1:Refresh()
if lTwoPages
if Len( aFiles ) >= nPage + 1
oMeta2:SetFile( aFiles[ nPage + 1 ] )
else
oMeta2:SetFile( "" )
endif
oMeta2:Refresh()
endif
oMeta1:SetFocus()
SetResources(hOldRes)
return nil
//----------------------------------------------------------------------------//
static function PrevPage()
local hOldRes := GetResources()
local aFiles := DEVICE:aMeta
if nPage == 1
MessageBeep()
RETU nil
endif
nPage--
SET RESOURCES TO cResFile
oMeta1:SetFile( aFiles[ nPage ] )
oPage:SetText( TXT_PAGENUM + LTrim( Str( nPage, 4, 0 ) ) + " / " + ;
LTrim( Str( Len( aFiles ) ) ) )
oBar:Refresh()
oMeta1:Refresh()
if lTwoPages
if Len( aFiles ) >= nPage + 1
oMeta2:SetFile( aFiles[ nPage + 1 ] )
else
oMeta2:SetFile( "" )
endif
oMeta2:Refresh()
endif
oMeta1:SetFocus()
SetResources(hOldRes)
return nil
//----------------------------------------------------------------------------//
static function TopPage()
local hOldRes := GetResources()
local aFiles := DEVICE:aMeta
if nPage == 1
MessageBeep()
return nil
endif
nPage = 1
SET RESOURCES TO cResFile
oMeta1:SetFile( aFiles[ nPage ] )
oPage:SetText( TXT_PAGENUM + LTrim( Str( nPage, 4, 0 ) ) + " / " + ;
LTrim( Str( Len( aFiles ) ) ) )
oBar:Refresh()
oMeta1:Refresh()
if lTwoPages
if Len( aFiles ) >= nPage + 1
oMeta2:SetFile( aFiles[ nPage + 1 ] )
else
oMeta2:SetFile( "" )
endif
oMeta2:Refresh()
endif
oMeta1:SetFocus()
SetResources(hOldRes)
return nil
//----------------------------------------------------------------------------//
static function BottomPage()
local hOldRes := GetResources()
local aFiles := DEVICE:aMeta
if nPage == Len( aFiles )
MessageBeep()
return nil
endif
nPage = Len( aFiles )
SET RESOURCES TO cResFile
oMeta1:SetFile( aFiles[ nPage ] )
oPage:SetText( TXT_PAGENUM + LTrim( Str( nPage, 4, 0 ) ) + " / " + ;
LTrim( Str( Len( aFiles ) ) ) )
oBar:Refresh()
oMeta1:Refresh()
if lTwoPages
oMeta2:SetFile( "" )
oMeta2:Refresh()
endif
oMeta1:SetFocus()
SetResources(hOldRes)
return nil
//----------------------------------------------------------------------------//
static function TwoPages(lMenu)
local hOldRes := GetResources()
SET RESOURCES TO cResFile
DEFAULT lMenu := .F.
lTwoPages := !lTwoPages
if lTwoPages
if len(DEVICE:aMeta) == 1 // solo hay una pagina
lTwoPages := !lTwoPages
MessageBeep()
SetResources(hOldRes)
RETU nil
endif
if DEVICE:nHorzSize() >= ; // Apaisado
DEVICE:nVertSize()
lTwoPages := !lTwoPages
MessageBeep()
SetResources(hOldRes)
RETU nil
endif
if lZoom
Zoom(.T.)
endif
if ! IsAppThemed()
oTwoPages:FreeBitmaps()
oTwoPages:LoadBitmaps("One_Page")
oTwoPages:cMsg := TXT_PREVIEW_ON_ONE_PAGE
oTwoPages:cTooltip := StrTran(TXT_ONEPAGE,"&","")
else
oBar:ChangeBitmap( 6, 10 )
oBar:SetTooltip( 6, StrTran(TXT_ONEPAGE,"&","") )
oBar:SetMessage( 6, TXT_PREVIEW_ON_ONE_PAGE )
endif
oMenuTwoPages:disable()
oMenuOnePage:enable()
else
if ! IsAppThemed()
oTwoPages:FreeBitmaps()
oTwoPages:LoadBitmaps("Two_Pages")
oTwoPages:cMsg := TXT_PREVIEW_ON_TWO_PAGES
oTwoPages:cTooltip := StrTran(TXT_TWOPAGES,"&","")
else
oBar:ChangeBitmap( 6, 6 )
oBar:SetTooltip( 6, StrTran(TXT_TWOPAGES,"&","") )
oBar:SetMessage( 6, TXT_PREVIEW_ON_TWO_PAGES )
endif
oMenuTwoPages:enable()
oMenuOnePage:disable()
endif
if lMenu .and. ! IsAppThemed()
oTwoPages:Refresh()
endif
oWnd:Refresh()
PaintMeta()
SetResources(hOldRes)
return nil
//----------------------------------------------------------------------------//
static function Zoom(lMenu)
local hOldRes := GetResources()
SET RESOURCES TO cResFile
DEFAULT lMenu := .F.
lZoom := !lZoom
if lZoom
if lTwoPages
TwoPages(.T.)
endif
if ! IsAppThemed()
oZoom:FreeBitmaps()
oZoom:LoadBitmaps("Unzoom")
oZoom:cMsg := TXT_UNZOOM_THE_PREVIEW
oZoom:cTooltip := StrTran(TXT_UNZOOM,"&","")
else
oBar:ChangeBitmap( 5, 9 )
oBar:SetTooltip( 5, StrTran(TXT_UNZOOM,"&","") )
oBar:SetMessage( 5, TXT_UNZOOM_THE_PREVIEW )
endif
oMenuZoom:disable()
oMenuUnZoom:enable()
oWnd:oVScroll:SetRange(1,VSCROLL_RANGE)
if nZFactor > 1
oWnd:oHScroll:SetRange(1,HSCROLL_RANGE)
endif
oMeta1:ZoomIn()
else
if ! IsAppThemed()
oZoom:FreeBitmaps()
oZoom:LoadBitmaps("Zoom")
oZoom:cMsg := TXT_ZOOM_THE_PREVIEW
oZoom:cTooltip := StrTran(TXT_ZOOM,"&","")
else
oBar:ChangeBitmap( 5, 5 )
oBar:SetTooltip( 5, StrTran(TXT_ZOOM,"&","") )
oBar:SetMessage( 5, TXT_ZOOM_THE_PREVIEW )
endif
oMenuZoom:enable()
oMenuUnZoom:disable()
oWnd:oVScroll:SetRange(0,0)
oWnd:oHScroll:SetRange(0,0)
oMeta1:ZoomOut()
nZFactor = 1
AEval( aFactor, {|val,elem| val:SetCheck( ( elem == 1 ) ) })
oFactor:Set( 1 )
endif
if lMenu .and. ! IsAppThemed()
oZoom:Refresh()
endif
PaintMeta()
SetResources( hOldRes )
return nil
//----------------------------------------------------------------------------//
static function VScroll(nType,lPage, nSteps)
local nYfactor, nYorig, nStep
DEFAULT lPage := .F.
if nType == GO_UP
if oWnd:oVScroll:GetPos() <= oWnd:oVScroll:nMin
return nil
endif
else
if oWnd:oVScroll:GetPos() > oWnd:oVScroll:nMax
return nil
endif
endif
nYfactor := Int(DEVICE:nVertRes()/oWnd:oVScroll:nMax)
if nSteps != nil
nStep := nSteps
elseif lPage
nStep := oWnd:oVScroll:nMax/10
else
nStep := 1
endif
if nType == GO_UP
nStep := -(nStep)
elseif nType == GO_POS
oWnd:oVscroll:SetPos(nSteps)
nStep := 0
endif
nYorig := nYfactor * (oWnd:oVScroll:GetPos() + nStep - 1)
if nYorig > DEVICE:nVertRes()
nYorig := DEVICE:nVertRes()
endif
if nYorig < 0
nYorig := 0
endif
#ifdef __CLIPPER__
oMeta1:SetOrg( nil, nYorig )
#else
oMeta1:SetOrg( nil, nYorig / DEVICE:nVertRes() * 10 )
#endif
oMeta1:Refresh()
return nil
//----------------------------------------------------------------------------//
static function HScroll(nType,lPage, nSteps)
local nXfactor, nXorig, nStep
DEFAULT lPage := .F.
if nType == GO_UP
if oWnd:oHScroll:GetPos() <= oWnd:oHScroll:nMin
return nil
endif
else
if oWnd:oHScroll:GetPos() > oWnd:oHScroll:nMax
return nil
endif
endif
nXfactor := Int(DEVICE:nHorzRes()/oWnd:oHScroll:nMax)
if nSteps != nil
nStep := nSteps
elseif lPage
nStep := oWnd:oHScroll:nMax/10
else
nStep := 1
endif
if nType == GO_LEFT
nStep := -(nStep)
elseif nType == GO_POS
oWnd:oHscroll:SetPos(nSteps)
nStep := 0
endif
nXorig := nXfactor * (oWnd:oHScroll:GetPos() + nStep - 1)
if nXorig > DEVICE:nHorzRes()
nXorig := DEVICE:nHorzRes()
endif
if nXorig < 0
nXorig := 0
endif
#ifdef __CLIPPER__
oMeta1:SetOrg(nXorig, nil )
#else
oMeta1:SetOrg( nXorig / DEVICE:nHorzRes() * 10, nil )
#endif
oMeta1:Refresh()
return nil
//----------------------------------------------------------------------------//
static function SetOrg1(nX, nY)
local oCoors
local nXStep, nYStep, nXFactor, nYFactor,;
nWidth, nHeight, nXOrg
if lZoom
Zoom(.T.)
RETU nil
endif
oCoors := oMeta1:GetRect()
nWidth := oCoors:nRight - oCoors:nLeft + 1
nHeight := oCoors:nBottom - oCoors:nTop + 1
if .f.
nXStep := Max(Int(nX/nWidth*HSCROLL_RANGE) - 9, 0)
nXFactor := Int(DEVICE:nHorzRes()/HSCROLL_RANGE)
endif
if .f.
nYStep := Max(Int(nY/nHeight*VSCROLL_RANGE) - 9, 0)
nYFactor := Int(DEVICE:nVertRes()/VSCROLL_RANGE)
endif
Zoom(.T.)
if !empty(nXStep)
HScroll(2,,nxStep)
oWnd:oHScroll:SetPos(nxStep)
endif
if !empty(nYStep)
VScroll(2,,nyStep)
oWnd:oVScroll:SetPos(nyStep)
endif
return nil
//----------------------------------------------------------------------------//
static function SetOrg2(nX, nY)
local oCoors
local aFiles
local nXStep, nYStep, nXFactor, nYFactor,;
nWidth, nHeight, nXOrg
if oMeta2:cCaption == ""
RETU nil
endif
if lZoom
Zoom(.T.)
RETU nil
endif
oCoors := oMeta2:GetRect()
nWidth := oCoors:nRight - oCoors:nLeft + 1
nHeight := oCoors:nBottom - oCoors:nTop + 1
if .f.
nXStep := Max(Int(nX/nWidth*HSCROLL_RANGE) - 9, 0)
nXFactor := Int(DEVICE:nHorzRes()/HSCROLL_RANGE)
endif
if .f.
nYStep := Max(Int(nY/nHeight*VSCROLL_RANGE) - 9, 0)
nYFactor := Int(DEVICE:nVertRes()/VSCROLL_RANGE)
endif
oMeta1:SetFile( oMeta2:cCaption )
aFiles := DEVICE:aMeta
if nPage = Len( aFiles )
oMeta2:SetFile( "" )
else
oMeta2:SetFile( aFiles[ ++nPage ] )
endif
oPage:Refresh()
Zoom( .T. )
if ! Empty( nXStep )
HScroll( 2,, nxStep )
oWnd:oHScroll:SetPos( nxStep )
endif
if ! Empty( nYStep )
VScroll( 2,, nyStep )
oWnd:oVScroll:SetPos( nyStep )
endif
return nil
//----------------------------------------------------------------------------//
static function CheckKey (nKey,nFlags) // Thanks to Joerg K.
if !lZoom
DO case
case nKey == VK_HOME
TopPage()
case nKey == VK_END
BottomPage()
case nKey == VK_PRIOR
PrevPage()
case nKey == VK_NEXT
NextPage()
endcase
else
DO case
case nKey == VK_UP
oWnd:oVScroll:GoUp()
case nKey == VK_PRIOR
oWnd:oVScroll:PageUp()
case nKey == VK_DOWN
oWnd:oVScroll:GoDown()
case nKey == VK_NEXT
oWnd:oVScroll:PageDown()
case nKey == VK_LEFT
oWnd:oHScroll:GoUp()
case nKey == VK_RIGHT
if oWnd:oHScroll != nil .and. oWnd:oHScroll:nMax > 0
oWnd:oHScroll:GoDown()
endif
case nKey == VK_HOME
oWnd:oVScroll:
GoTop()
oWnd:oHScroll:
GoTop()
oMeta1:SetOrg(0,0)
oMeta1:Refresh()
case nKey == VK_END
oWnd:oVScroll:GoBottom()
oWnd:oHScroll:GoBottom()
oMeta1:SetOrg(.8*DEVICE:nHorzRes(),.8*DEVICE:nVertRes())
oMeta1:Refresh()
endcase
endif
return nil
//----------------------------------------------------------------------------//
static function CheckMouseWheel( nKeys, nDelta, nXPos, nYPos )
if !lZoom
if lAnd( nKeys, MK_MBUTTON )
if nDelta > 0
TopPage()
else
BottomPage()
endif
else
if nDelta > 0
PrevPage()
else
NextPage()
endif
endif
else
if lAnd( nKeys, MK_MBUTTON )
if nDelta > 0
if oWnd:oVScroll:GetPos() > oWnd:oVScroll:nMin
oWnd:oVScroll:PageUp()
endif
else
if oWnd:oVScroll:GetPos() < oWnd:oVScroll:nMax
oWnd:oVScroll:PageDown()
endif
endif
else
if nDelta > 0
if oWnd:oVScroll:GetPos() > oWnd:oVScroll:nMin
oWnd:oVScroll:GoUp()
endif
else
if oWnd:oVScroll:GetPos() < oWnd:oVScroll:nMax
oWnd:oVScroll:GoDown()
endif
endif
endif
endif
return nil
//----------------------------------------------------------------------------//
static function SetFactor( nValue )
local lInit := .F.
if nValue == nil
Aeval(aFactor, {|v,e| v:nHelpId := e})
nValue := nZFactor
lInit := .T.
endif
Aeval(aFactor, {|val,elem| val:SetCheck( (elem == nValue) ) })
oMeta1:SetZoomFactor(nZFactor, nZFactor*2)
if !lZoom .AND. !lInit
Zoom(.T.)
endif
if lZoom
oWnd:oVScroll:SetRange( 1, VSCROLL_RANGE )
if nZFactor > 1
oWnd:oHScroll:SetRange( 1, HSCROLL_RANGE )
else
oWnd:oHScroll:SetRange( 0, 0 )
endif
endif
oMeta1:SetFocus()
return nil
//----------------------------------------------------------------------------//
static function PrintPage()
local hOldRes := GetResources()
local hMeta := oMeta1:hMeta
local oDlg, oRad, oPageIni, oPageFin
local nOption := 1 ,;
nFirst := 1 ,;
nLast := len(DEVICE:aMeta)
if nLast == 1
PrintPrv(nil, nOption, nFirst, nLast)
RETU nil
endif
SET RESOURCES TO cResFile
DEFINE DIALOG oDlg RESOURCE "PRINT"
REDEFINE BUTTON ID 101 OF oDlg ;
ACTION PrintPrv(oDlg, nOption, nFirst, nLast)
REDEFINE BUTTON ID 102 OF oDlg ACTION oDlg:End()
REDEFINE RADIO oRad VAR nOption ID 103,104,105 OF oDlg ;
ON CHANGE iif(nOption==3 ,;
(oPageIni:Enable(),oPageFin:Enable()) ,;
(oPageIni:Disable(),oPageFin:Disable()) )
REDEFINE GET oPageIni ;
VAR nFirst ;
ID 106 ;
PICTURE "@K 99999" ;
VALID iif(nFirst<1 .OR. nFirst>nLast,(MessageBeep(),.F.),.T.) ;
OF oDlg
REDEFINE GET oPageFin ;
VAR nLast ;
ID 107 ;
PICTURE "@K 99999" ;
VALID iif(nLast<nFirst .OR. nLast>len(DEVICE:aMeta), ;
(MessageBeep(),.F.),.T.) ;
OF oDlg
oPageIni:Disable()
oPageFin:Disable()
SetResources(hOldRes )
ACTIVATE DIALOG oDlg
return nil
//----------------------------------------------------------------------------//
static function PrintPrv(oDlg, nOption, nPageIni, nPageEnd)
local oDevice := DEVICE
local aFiles := oDevice:aMeta
local hMeta := oMeta1:hMeta
local nFor
CursorWait()
StartDoc(oDevice:hDC, oDevice:cDocument )
DO case
case nOption == 1 // All
FOR nFor := 1 TO len(aFiles)
#ifdef __CLIPPER__
StartPage(oDevice:hDC)
hMeta := GetMetaFile(aFiles[nFor])
PlayMetaFile( oDevice:hDC, hMeta )
DeleteMetafile(hMeta)
EndPage(oDevice:hDC)
#else
StartPage(oDevice:hDC)
hMeta := GetEnhMetaFile(aFiles[nFor])
PlayEnhMetaFile( oDevice:hDC, hMeta,, .t. )
DeleteEnhMetafile(hMeta)
EndPage(oDevice:hDC)
#endif
NEXT
case nOption == 2 // Current page
StartPage(oDevice:hDC)
hMeta := oMeta1:hMeta
#ifdef __CLIPPER__
PlayMetaFile( oDevice:hDC, hMeta )
#else
PlayEnhMetaFile( oDevice:hDC, hMeta,, .t. )
#endif
EndPage(oDevice:hDC)
case nOption == 3 // Range
FOR nFor := nPageIni TO nPageEnd
StartPage(oDevice:hDC)
#ifdef __CLIPPER__
hMeta := GetMetaFile(aFiles[nFor])
PlayMetaFile( oDevice:hDC, hMeta )
DeleteMetafile(hMeta)
#else
hMeta := GetEnhMetaFile(aFiles[nFor])
PlayEnhMetaFile( oDevice:hDC, hMeta,, .t. )
DeleteEnhMetafile(hMeta)
#endif
EndPage(oDevice:hDC)
NEXT
endcase
EndDoc(oDevice:hDC)
CursorArrow()
if oDlg != nil
oDlg:End()
endif
return nil
//----------------------------------------------------------------------------//
#ifdef __CLIPPER__
static function IsAppThemed()
return .f.
static function TToolBar()
return nil
static function TRebar()
return nil
#endif
//------------------------------------------------------------------------
// función para cambiar la impresora desde previo mcn valdenebro
//------------------------------------------------------------------------
func f_CamImpre (oDevice, cCbx )
local cPrinter
cPrinter := GetProfString( "windows", "device" , "" )
WriteProfString( "windows", "device", cCbx )
SysRefresh()
PrinterInit()
DeleteDC( oDevice:hDC ) // Sugestion by Enrico M. Giordano
// Insert here the function to create the report
// oWnd:End() // George - To close current preview
oDevice:hDC := GetPrintDefault( GetActiveWindow() )
SysRefresh()
WriteProfString( "windows", "device", cPrinter )
RETURN nil