Page 2 of 3
Re: Rectangle as bitmap
Posted: Thu Oct 07, 2021 10:58 am
by nageswaragunupudi
Natter wrote:Hi.
There is a dialog box with brush. I need to select a certain rectangle on this window and save it to a file as a bitmap. How to do it ?
If it is a large dialog with a brush I can provide solution.
But I doubt if it is an Activex control
Re: Rectangle as bitmap
Posted: Thu Oct 07, 2021 11:05 am
by Natter
Sorry, I didn't understand

Re: Rectangle as bitmap
Posted: Thu Oct 07, 2021 11:08 am
by Antonio Linares
Is the activex showing the same image all the time or does it change like a map ?
Re: Rectangle as bitmap
Posted: Thu Oct 07, 2021 11:15 am
by Natter
This is a map. I want to print large formats A1, A0
Re: Rectangle as bitmap
Posted: Thu Oct 07, 2021 11:23 am
by Antonio Linares
I think that you can only get an image of what it is shown on the screen, unless the activex provides a method to do it.
What activex is it ?
Please build and run c:\FWH\samples\olebrow.prg and look for the activex and inspect the methods that it provides or
check the documentation about it
Re: Rectangle as bitmap
Posted: Thu Oct 07, 2021 11:28 am
by Natter
This is IE. I work through it with the Maps API. There is no means for printing or output to a file in this API
Re: Rectangle as bitmap
Posted: Thu Oct 07, 2021 12:27 pm
by Antonio Linares
Could you provide us a small and self contained Prg to test here ?
Enviado desde mi SM-M325FV mediante Tapatalk
Re: Rectangle as bitmap
Posted: Thu Oct 07, 2021 12:48 pm
by Natter
I'll try to make an example, but it's difficult. Can use IE features ? This browser has both Print and Save As, however, I do not know how to address them
Re: Rectangle as bitmap
Posted: Thu Oct 07, 2021 5:07 pm
by nageswaragunupudi
I tried using "Shell.Explorer.2" Activex.
For me oActivex:Print() is working. I do not have large printer, but it printed the google map on my A4 size paper.
You may try with Large paper printer and with a few trials and errors you may be able to print.
Re: Rectangle as bitmap
Posted: Fri Oct 08, 2021 6:40 am
by Natter
I checked o Activex:Print(). Anyway, only the screen is printed.
Please give your example with oActivex:Print() and google map. Based on it, I will make a small example showing my problem
Re: Rectangle as bitmap
Posted: Sun Oct 10, 2021 12:32 pm
by Natter
Could you provide us a small and self contained Prg to test here ?
In this example, I increase the size of the ActiveX according to the selected print format.
1. Download the Google Map
2. Select the format (size)
3. Print (to file)
Code: Select all | Expand
#include "FiveWin.ch"
#DEFINE SM_CYBORDER 6
#DEFINE SM_CYMENU 15
#DEFINE SM_CYCAPTION 4
function Main()
private a_win:=ScrResolution()
private oWnd, oDk, oMen
SET _3DLOOK ON
set path to pth
DEFINE DIALOG oWnd FROM 0,0 TO 0,0 COLOR CLR_BLACK, CLR_HGRAY ;
TITLE "AactiveX larger then the screen" PIXEL ;
STYLE nOR(WS_CAPTION, WS_SYSMENU )
ACTIVATE DIALOG oWnd ON INIT Win_Ini()
return nil
procedure Win_Ini()
MENU oMen OF oWnd
MENUITEM "Google map" ACTION Map_Viw()
MENUITEM "Formats"
MENU
MENUITEM "A2" ACTION Big_Fmt(1)
SEPARATOR
MENUITEM "A1" ACTION Big_Fmt(2)
SEPARATOR
MENUITEM "A0" ACTION Big_Fmt(3)
ENDMENU
MENUITEM "Print Map" ACTION Prt_Map()
ENDMENU
oWnd:Move(0,0, a_win[1], GetSysMetrics(17)+ ;
GetSysMetrics(SM_CYCAPTION)+GetSysMetrics(SM_CYBORDER)*2)
oCl:=TActiveX():New(oWnd, "Shell.Explorer", ;
2, 2, oWnd:nWidth-4, GetSysMetrics(17)-4)
oCl:Silent:=.T.
return
procedure Map_Viw
local oObj:="oWnd:aControls[1]"
&oObj:Do("Navigate2", "https://www.google.com/maps/@42.8674796,74.5708881,16z?hl=ru-KG")
do while .T.
oDk:=&oObj:GetProp("Document")
if valtype(oDk)="U".or.oDk:ReadyState!="complete"
WaitMessage()
SysRefresh()
else
exit
endif
enddo
return
procedure Big_Fmt(fmt) && print to bitmap-file
local fl
local oObj:="oWnd:aControls[1]"
local dim:={}
local mas:={{594,420}, {841,594}, {1189,841}}
local siz:={}
** fmt - format 1-A2, 2-A1, 3-A0
siz:={getdevicecaps(getDC(&oObj), 4), ; && horzsize
getdevicecaps(getDC(&oObj), 6)} && vertsize
fl:=a_win[1]/siz[1] && number pix in 1 mm
mas[fmt,1]*=fl && width ActiveX in pix
mas[fmt,2]*=fl && height Activex in pix
siz:={mas[fmt,1]-&oObj:nWidth, ; && the % of increase in width
mas[fmt,2]-&oObj:nHeight} && the % of increase in height
*********** new size ActiveX ***********
dim:={&oObj:nTop-(siz[2]/2), &oObj:nLeft-(siz[1]/2), ;
&oObj:nWidth+siz[1], &oObj:nHeight+siz[2]}
***** change size ActiveX *****
&oObj:Move(dim[1], dim[2], dim[3], dim[4])
return
procedure Prt_Map
local oObj:="oWnd:aControls[1]"
? oWnd:nWidth, oWnd:nHeight, &oObj:nWidth, &oObj:nHeight
&oObj:Do( "ExecWB", 6, 1) &&OLECMDID_PRINT, OLECMDEXECOPT_DONTPROMPTUSER )
* &oObj:Print()
return
Re: Rectangle as bitmap
Posted: Sun Oct 10, 2021 3:15 pm
by nageswaragunupudi
Good. Is it working for you now?
Re: Rectangle as bitmap
Posted: Sun Oct 10, 2021 4:03 pm
by karinha
Great! Thank you very much.
Code: Select all | Expand
#include "FiveWin.ch"
#define SM_CYBORDER 6
#define SM_CYMENU 15
#define SM_CYCAPTION 4
MEMVAR oDlg, a_win, oClActive, oDk, oMen, lImpMap
FUNCTION Main()
LOCAL Path, aGrad, cTitle, oSkinB
SET PATH TO Path := StrCapFirst( cFilePath( GetModuleFileName( GetInstance() ) ) + "C:\COPIA" )
SET _3DLOOK ON
oSkinB = TSkinButton():New()
oSkinB:nClrBorder0_N := RGB( 249, 194, 179 )
oSkinB:nClrBorder1_N := RGB( 181, 61, 29 )
oSkinB:aClrNormal := { { 0.2, RGB( 000, 128, 000 ), RGB( 000, 128, 000 ) }, ;
{ 0.8, RGB( 109, 135, 100 ), RGB( 109, 135, 100 ) } }
SkinButtons( oSkinB )
IF .NOT. lIsDir( "C:\COPIA" )
lMkDir( "C:\COPIA" )
ENDIF
a_win := ScrResolution()
lImpMap := .F.
cTitle := "ActiveX larger then the screen"
aGrad := { { 0.30, CLR_WHITE, CLR_WHITE },{ 0.50, CLR_WHITE, CLR_WHITE } }
DEFINE DIALOG oDlg FROM 0, 0 TO 0, 0 GRADIENT aGrad TITLE cTitle PIXEL ;
STYLE nOR( WS_CAPTION, WS_SYSMENU )
oDlg:lHelpIcon := .F.
ACTIVATE DIALOG oDlg ON INIT( Win_Ini() )
RETURN NIL
FUNCTION Win_Ini()
LOCAL oMenu
MENU oMenu 2007 OF oDlg
MENUITEM "Google map" ACTION( Map_View() )
MENUITEM "Formats"
MENU
MENUITEM "A2" ACTION( Big_Fmt( 1 ) )
SEPARATOR
MENUITEM "A1" ACTION( Big_Fmt( 2 ) )
SEPARATOR
MENUITEM "A0" ACTION( Big_Fmt( 3 ) )
ENDMENU
MENUITEM "Print Map" ACTION( Prt_Map() ) WHEN( lImpMap ) // New
MENUITEM "Exit" ACTION( oDlg:End(), CLOSE_PROGRAM() )
ENDMENU
oDlg:Move( 0, 0, a_win[ 1 ], GetSysMetrics( 17 ) + ;
GetSysMetrics( SM_CYCAPTION ) + GetSysMetrics( SM_CYBORDER ) * 2 )
oClActive := TActiveX():New( oDlg, "Shell.Explorer", ;
2, 2, oDlg:nWidth - 4, GetSysMetrics( 17 ) - 4 )
oClActive:Silent := .T.
RETURN( oMenu )
FUNCTION Map_View()
LOCAL oObj := "oDlg:aControls[1]"
&oObj:Do( "Navigate2", "https://www.google.com/maps/@42.8674796,74.5708881,16z?hl=ru-KG" )
WHILE( .T. )
SYSREFRESH() ; CURSORWAIT()
oDk := &oObj:GetProp( "Document" )
IF ValType( oDk ) = "U" .OR. oDk:ReadyState != "complete"
// WaitMessage()
SysWait( 1 )
ELSE
IF ValType( oDk ) != "U"
lImpMap := .T.
ELSE // no errors.
lImpMap := .F.
ENDIF
EXIT
ENDIF
ENDDO
CURSORARROW()
RETURN NIL
FUNCTION Big_Fmt( fmt ) // print to bitmap-file
LOCAL fl
LOCAL oObj := "oDlg:aControls[1]"
LOCAL dim := {}
LOCAL mas := { { 594, 420 }, { 841, 594 }, { 1189, 841 } }
LOCAL siz := {}
// * fmt - format 1-A2, 2-A1, 3-A0
siz := { getdevicecaps( getDC( &oObj ), 4 ), ; // horzsize
getdevicecaps( getDC( &oObj ), 6 ) } // vertsize
fl := a_win[ 1 ] / siz[ 1 ] // number pix in 1 mm
mas[ fmt, 1 ] *= fl // width ActiveX in pix
mas[ fmt, 2 ] *= fl // height Activex in pix
siz := { mas[ fmt, 1 ] - &oObj:nWidth, ; // the % of increase in width
mas[ fmt, 2 ] - &oObj:nHeight } // the % of increase in height
// ********** new size ActiveX ***********
dim := { &oObj:nTop - ( siz[ 2 ] / 2 ), &oObj:nLeft - ( siz[ 1 ] / 2 ), ;
&oObj:nWidth + siz[ 1 ], &oObj:nHeight + siz[ 2 ] }
// **** change size ActiveX *****
&oObj:Move( dim[ 1 ], dim[ 2 ], dim[ 3 ], dim[ 4 ] )
RETURN NIL
FUNCTION Prt_Map()
LOCAL oObj := "oDlg:aControls[1]"
? oDlg:nWidth, oDlg:nHeight, &oObj:nWidth, &oObj:nHeight
&oObj:Do( "ExecWB", 6, 1 ) // OLECMDID_PRINT, OLECMDEXECOPT_DONTPROMPTUSER )
// &oObj:Print()
RETURN NIL
// CLOSE ALL
FUNCTION CLOSE_PROGRAM()
lImpMap := .F.
HB_GCALL( .T. )
CLEAR MEMORY
PostQuitMessage( 0 )
RETURN NIL
// END / FIN
Regards, saludos.
Re: Rectangle as bitmap
Posted: Mon Oct 11, 2021 6:08 am
by Natter
In this version, we can print the map or save it as a pdf file. Is it possible to save the map as a bitmap file ?
Re: Rectangle as bitmap
Posted: Mon Oct 11, 2021 10:57 am
by Antonio Linares
oDlg:aControls[ 1 ]:SaveToBmp( "test.bmp" )