Center bitmap

Post Reply
User avatar
cdmmaui
Posts: 653
Joined: Fri Oct 28, 2005 9:53 am
Location: The Woodlands - Dallas - Scottsdale - London
Contact:

Center bitmap

Post 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,
*~*~*~*~*~*~*~*~*~*
Darrell Ortiz
CDM Software Solutions, Inc.
https://www.cdmsoft.com
User avatar
James Bott
Posts: 4654
Joined: Fri Nov 18, 2005 4:52 pm
Location: San Diego, California, USA
Contact:

Post 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
User avatar
James Bott
Posts: 4654
Joined: Fri Nov 18, 2005 4:52 pm
Location: San Diego, California, USA
Contact:

Post 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 )
User avatar
cdmmaui
Posts: 653
Joined: Fri Oct 28, 2005 9:53 am
Location: The Woodlands - Dallas - Scottsdale - London
Contact:

Post by cdmmaui »

Hi James,

Thank you very much!
*~*~*~*~*~*~*~*~*~*
Darrell Ortiz
CDM Software Solutions, Inc.
https://www.cdmsoft.com
Post Reply