I need to resize a dialog that is displaying an image. If the user selects to stretch the current image or display another one with different size, then the dialog changes it size to the new one. Can this be done ? Thank you.
I need to resize a dialog that is displaying an image. If the user selects to stretch the current image or display another one with different size, then the dialog changes it size to the new one. Can this be done ? Thank you.
Gustavo,
oDlg:SetSize( nNewWidth, nNewHeight )
or simply:
oDlg:nWidth := ...
oDlg:nHeight := ...
With oDlg:SetSize() you do it in one single step.

// The Dialog-Button to Show a adjusted-Dialog
// -----------------------------------------------------------
REDEFINE BUTTONBMP oBtn12 ID 75 OF oDlg3 ;
ACTION ( ALPHA_IMG(oDlg3, cImage) ) ;
BITMAP "preview" PROMPT " &Alpha-Channel" TEXTRIGHT
oBtn12:cTooltip = { "Preview" + CRLF + ;
"Alpha-Channel","Preview", 1, CLR_BLACK, 14089979 }
// ------------ Image-Resource in Folder for normal Preview
// ------------on Record-change in xBrowse => oBMP10:Refresh() -----
REDEFINE BITMAP oBMP10 ID 210 ADJUST RESOURCE "Blanc" OF oFolder:aDialogs[1] UPDATE
oBMP10:bPainted := {|hDC| DRAW_IMG1( oBMP10, cIMAGE ) }
// ------------ IMAGE - Preview in Folder -----------------------------------
FUNCTION DRAW_IMG1( oBitmap, cBitmap)
DEFINE IMAGE oImage FILENAME "&c_Path\" + ALLTRIM(cSUBDIR) + cBitmap
// Image-Size adjusted to BMP-resource in Folder
// If the Image is bigger, it is reduced to the < TBitmap-Resource > size
// --------------------------------------------------------------------------------
aRect := GETCLIENTRECT( oBitmap:hWnd )
hDC := oBitmap:GETDC()
IF nWIDTH < aRect[4] .and. nHEIGHT < aRect[3]
PalBmpDraw( hDC, 0, 0, oImage:hBitmap, , nWIDTH, nHEIGHT )
ENDIF
IF nWIDTH > aRect[4] .and. nHEIGHT <= aRect[3]
nNewproz := ( aRect[4] / nWIDTH ) * 100
nNewHeight := ( nHEIGHT / 100 ) * nNewproz
PalBmpDraw( hDC, 0, 0, oImage:hBitmap, , aRect[4], nNewHeight )
ENDIF
IF nWIDTH <= aRect[4] .and. nHEIGHT > aRect[3]
nNewproz := ( aRect[4] / nHEIGHT ) * 100
nNewWidth := ( nWIDTH / 100 ) * nNewproz
PalBmpDraw( hDC, 0, 0, oImage:hBitmap, , nNewWidth, aRect[3] )
ENDIF
IF nWIDTH > aRect[4] .and. nHEIGHT > aRect[3]
nNewprozW := ( aRect[4] / nWIDTH ) * 100
nNewprozH := ( aRect[4] / nHEIGHT ) * 100
nNewWidth := ( nWIDTH / 100 ) * nNewprozW
nNewHeight := ( nHEIGHT / 100 ) * nNewprozW
PalBmpDraw( hDC, 0, 0, oImage:hBitmap, , nNewWidth, nNewHeight )
ENDIF
lRESIZE := .F.
ReleaseDC(hDC)
RETURN( NIL )
// ------------ ALPHA- IMAGE ( Dialog adjusted to Image ) ------------
//------------- give a little bit space around the Image ----------
// nHEIGHT + 50, nWIDTH + 40
// take care of the Dialog-border : ABPaint( hDC, 10, 10 ......
FUNCTION ALPHA_IMG(oDlg3, cBitmap)
Local oDlg, oBmp, oBrush, oBtn
// nHeight = Image-Height
// nWidth := Image-Width
DEFINE BRUSH oBrush STYLE "BORLAND"
DEFINE BITMAP oBmp FILENAME "&c_Path\" + ALLTRIM(cSUBDIR) + cBITMAP
DEFINE DIALOG oDlg FROM 35, 20 TO nHEIGHT + 50, nWIDTH + 40 ;
OF oDlg3 COLOR 0, "N/W" BRUSH oBrush ;
TITLE "BMP with Alpha-Channel" PIXEL
ACTIVATE DIALOG oDlg ;
ON PAINT ABPaint( hDC, 10, 10, oBmp:hBitmap, 220 )
oBrush:End()
oBmp:End()
RETURN( NIL )Antonio, Ukoenig:
Thank you very much for your help. Seems that both of your answers are what I'm looking for. I'll give it a try.
Hello HunterEC,
to define the dialog-size, You have to use the Image-size
with a bit space around, like shown in the sample.
The array < aRect > will give You the size you need :
nWIDTH = aRect[4], nHEIGHT = aRect[3]
// Image-Size in Dialog-resource
// ---------------------------------------
aRect := GETCLIENTRECT( oBitmap:hWnd )
hDC := oBitmap:GETDC()
Regards
Uwe ![]()