Hello Uwe,
THX for your assistance.
I've made some more testing and here is the working sample for both SDI and MDI:
- Code: Select all Expand view
FUNCTION Main()
//
// Testing background pictures
//
LOCAL oWnd
LOCAL oFont
LOCAL cLogo := "C:\xHarbour\FiveWin\my_source\five.bmp"
LOCAL oImage
LOCAL oBrush
LOCAL hDC
//
// Background color is white
//
DEFINE BRUSH oBrush COLOR CLR_WHITE
DEFINE FONT oFont NAME "TAHOMA" SIZE 0, - 12
DEFINE WINDOW oWnd MDI TITLE "Testing background pictures" BRUSH oBrush
//DEFINE WINDOW oWnd TITLE "Testing background pictures" BRUSH oBrush
//
// Font
//
oWnd:setFont( oFont )
//
// Show file name in the Messagebar
//
SET MESSAGE OF oWnd TO cLogo
//
// Returns the current device context, if any or request a new one
//
hDC := oWnd:GetDC()
//
// Activate the window
//
ACTIVATE WINDOW oWnd MAXIMIZED ON PAINT WL_IMAGE( oWnd, hDC, cLogo )
//ACTIVATE WINDOW oWnd MAXIMIZED ON PAINT WL_IMAGE( oWnd, cLogo )
RETURN ( NIL )
STATIC FUNCTION WL_IMAGE( oWnd, hDC, cLogo )
//STATIC FUNCTION WL_IMAGE( oWnd, cLogo )
//
// Displays centerd background bitmap with scaling factor
//
//LOCAL hDC
LOCAL oImage
LOCAL nScaleFactor := 2
LOCAL nHeightBitmap
LOCAL nWidthBitmap
LOCAL nHeightBitmapNew
LOCAL nWidthBitmapNew
LOCAL oRect
LOCAL nRow
LOCAL nCol
//
//hDC := oWnd:GetDC()
//
IF File( cLogo )
//
// Doesn't work in MDI
//
//oImage := TBitmap():New(,,,,, cLogo, .T., oWnd,,, .F., .T.,,, .F.,, .F.,, .F. )
DEFINE IMAGE oImage FILENAME cLogo
//
// Original size of the bitmap
//
nHeightBitmap := nBmpHeight( oImage:hBitmap )
nWidthBitmap := nBmpWidth( oImage:hBitmap )
//
// Window size
//
oRect := oWnd:GetRect()
//
// Calculate new bitmap size in relation to the window height
//
nHeightBitmapNew := ( oRect:nBottom - oRect:nTop ) / nScaleFactor
nWidthBitmapNew := nWidthBitmap * nHeightBitmapNew / nHeightBitmap
//
// Control the new bitmap size in relation to the window width
//
IF nWidthBitmapNew > ( oRect:nRight - oRect:nLeft ) / nScaleFactor
//
// Calculate new bitmap size in relation to the window width
//
nWidthBitmapNew := ( oRect:nRight - oRect:nLeft ) / nScaleFactor
nHeightBitmapNew := nHeightBitmap * nWidthBitmapNew / nWidthBitmap
ENDIF
//
// Calculate the position for centered output
//
nRow := ( oRect:nBottom - oRect:nTop ) / 2 - nHeightBitmapNew / 2
nCol := ( oRect:nRight - oRect:nLeft ) / 2 - nWidthBitmapNew / 2
//
// Display bitmap
//
PalBmpDraw( hDC, nRow, nCol, oImage:hBitmap,, nWidthBitmapNew, nHeightBitmapNew,, .F., )
ELSE
MsgAlert( "Cannot load : " + CRLF + cLogo, "Error" )
ENDIF
RETURN NIL
You are right, SDI and MDI are working differently:
- In SDI the background color is white (Default?). In MDI a grey background color comes up, which can be avoided with 'DEFINE BRUSH oBrush COLOR CLR_WHITE'
- In MDI <hDC> must be passed from the calling function, in SDI <hDC> a local call of 'oWnd:GetDC()' is also working
- In SDI you can paint the bitmap by using TBitmap(). I think there is no need to use PalBmpDraw() anymore, but havn't done further tests because I want to use MDI
That's very strange, it seems to be not very consistantly
But the main thing is, that the task is solved and I have a working peace of source code