Page 1 of 1
Center bitmap
Posted: Wed Dec 12, 2007 4:29 am
by cdmmaui
Hello,
I have a blank area between menu and message and I need to place a bitmap (logo) in this area. Can someone send me code to place a bitmap centerd in maximized window based on length and width of bitmap and length and width of display?
Thank you,
Posted: Wed Dec 12, 2007 8:50 am
by James Bott
Darrell,
Try the example below.
James
Code: Select all
> #INCLUDE "C:\FW192\INCLUDE\FIVEWIN.CH"
> *
> STATIC oWnd,nWndWid,nWndHgt
> *
> FUNCTION Main()
> DEFINE WINDOW oWnd;
> FROM 1,2 TO MaxRow()-3,MaxCol()-2;
> TITLE "BMP Logo Centering"
> ACTIVATE WINDOW oWnd ON INIT (Calc_Wnd(),Disp_Bmp())
> RETURN nil
> *
> STATIC FUNCTION Disp_Bmp()
> LOCAL oBmp,nRow,nCol,nBmpWid,nBmpHgt,cFile:="TEST.BMP"
> IF File(cFile)
> DEFINE BITMAP oBmp FILE cFile OF oWnd
> nRow = nWndHgt/2 - oBmp:nHeight/2
> nCol = nWndWid/2 - oBmp:nWidth/2
> oBmp:End()
> @ nRow,nCol BITMAP oBmp FILE cFile PIXEL NOBORDER OF oWnd
> ENDIF
> RETURN nil
> *
> STATIC FUNCTION Calc_Wnd()
> LOCAL x1,y1,x2,y2,aWind:=oWnd:GetRect()
> x1 = aWind[1]
> y1 = aWind[2]
> x2 = aWind[3]
> y2 = aWind[4]
> nWndHgt = x2 - x1
> nWndWid = y2 - y1
> RETURN nil
> **************
>
> Hope this helps.
>
> Gary Beam
> Extensions Software Corp.
> http://www.ext.com
Posted: Wed Dec 12, 2007 8:58 am
by James Bott
Darrell,
I found some old code where I did it like this. This code will redraw the bitmap centered whenever the window is resized.
James
Code: Select all
ACTIVATE WINDOW ownd maximized ;
on paint (PalBmpDraw( oWnd:oWndClient:hDC, (oWnd:nHeight/2-oBmp:nHeight/2)-50,(oWnd:nWidth/2-oBmp:nWidth/2), oBmp:hBitmap, oBmp:hPalette )
Posted: Thu Dec 13, 2007 1:22 pm
by cdmmaui
Hi James,
Thank you very much!