I was playing around with this a bit and thought I'd ask: is following
code safe? I load a bitmap in PBMAIN and store the handle globally so
it can be used for stretching the bitmap in WM_ERASEBKGND. Somehow, I
get a feeling there's something missing here, like - the global handle,
shouldn't that one also be released? No leaks as far as I can tell, so
maybe this is the way to do it.
BTW, discovered that using BeginPaint in WM_PAINT doesn't work for this
purpose. Picture becomes a mess of different sizes after a few resizing
events and not even using FillRect on hDC helps. Think Semen found some
strange things with BeginPaint a while ago too, maybe that was it?
Following works though:
------------------
code safe? I load a bitmap in PBMAIN and store the handle globally so
it can be used for stretching the bitmap in WM_ERASEBKGND. Somehow, I
get a feeling there's something missing here, like - the global handle,
shouldn't that one also be released? No leaks as far as I can tell, so
maybe this is the way to do it.
BTW, discovered that using BeginPaint in WM_PAINT doesn't work for this
purpose. Picture becomes a mess of different sizes after a few resizing
events and not even using FillRect on hDC helps. Think Semen found some
strange things with BeginPaint a while ago too, maybe that was it?
Following works though:
Code:
'¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤ ' Declares '¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤ #COMPILE EXE #INCLUDE "WIN32API.INC" GLOBAL hBitMap AS LONG 'keep this one globally to enable rezising DECLARE CALLBACK FUNCTION DlgProc() AS LONG '¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤ ' Create dialog and controls, etc '¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤ FUNCTION PBMAIN () AS LONG LOCAL hDlg AS LONG, txt AS STRING DIALOG NEW 0, "AutoStretch test",,, 195, 50, %WS_CAPTION OR %WS_OVERLAPPEDWINDOW, 0 TO hDlg 'txt = "c:\pbdll60\samples\smtp\smtp.bmp" & CHR$(0) 'change to whatever picture you have.. 'txt = "c:\windows\suback.bin" & CHR$(0) 'found this one in Win98 - heaven background.. txt = "c:\windows\logow.sys" & CHR$(0) 'Windows shutdown screen.. hBitMap = LoadImage(0, BYVAL STRPTR(txt), %IMAGE_BITMAP, 0, 0, %LR_LOADFROMFILE) 'load with actual size DIALOG SHOW MODAL hDlg CALL DlgProc END FUNCTION '¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤ ' Main callback '¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤ CALLBACK FUNCTION DlgProc() AS LONG IF CBMSG = %WM_ERASEBKGND THEN LOCAL hDC AS LONG, memDC AS LONG, wRect AS RECT, bm AS BITMAP GetClientRect CBHNDL, wRect 'get control's size GetObject hBitmap, SIZEOF(bm), bm 'get bitmap properties hDC = GetDc(CBHNDL) 'get current DC memDC = CreateCompatibleDC(hDC) 'create temporary DC SelectObject memDC, hBitmap 'select bitmap in tmpDC StretchBlt hDC, 0, 0, wRect.nright, wRect.nbottom, _ memDC, 0, 0, bm.bmWidth, bm.bmHeight, %SRCCOPY DeleteObject SelectObject(memDC, hBitmap) 'delete bitmap object, but keep handle DeleteDC memDC 'delete temporary DC ReleaseDC CBHNDL, hDC FUNCTION = 1 END IF END FUNCTION
------------------
Comment