1. Derek: function subClassBitmap
Derek, I looked at the function subClassControl, and used it to create the
function subClassBitmap. This function takes a bitmap-handle and wraps it into a
Win32Lib Pixmap.
--/topic Events
--/func subClassBitmap(atom bitmap)
--/desc Used to access Windows created bitmaps as if they were win32lib pixmaps.
--/return INTEGER: A win32lib control id. ZERO if it fails.
-- /i bitmap is the Windows Handle to the bitmap.
--
--Example
--/code
-- newid = subClassBitmap( bitmap_handle )
--/endcode
global function subClassBitmap(atom bitmap)
integer lNewId
if bitmap = 0 then
return 0
end if
lNewId = NewControl(Pixmap, 0)
-- Set up data for child control
window_handle[lNewId] = bitmap
window_handle_type[lNewId] = kht_Bitmap
return lNewId
end function
You could put it just after the function subClassControl in win32lib.ew.
To wrap a Win32Dib-bitmap into a Win32Lib-pixmap (with the purpose of drawing
directly to it):
object myDib
atom myPixmap
myDib = newDib(300, 200) -- create a 300x200 bitmap
if atom(myDib) then abort(0) end if
myPixmap = subClassBitmap(myDib[DibHandle])
-- start drawing:
clearDib(myDib, {255, 255, 255}) -- clear the bitmap
setFont(myPixmap, "Verdana", 8, Bold)
setTextColor(myPixmap, Black)
wPuts({myPixmap, 0, 0}, "Testing Pixmap-wrapper...")
If you wrap a bitmap in a Pixmap with this method, everything you draw on the
Pixmap using the Win32Lib-routines will be drawn on the bitmap: you don't have to
create a separate Pixmap, and you don't have to blit from the new Pixmap to the
Win32Dib-bitmap.
--
tommy online: http://users.pandora.be/tommycarlier
2. Re: Derek: function subClassBitmap
Tommy Carlier wrote:
>
>
> Derek, I looked at the function subClassControl, and used it to create the
> function
> subClassBitmap. This function takes a bitmap-handle and wraps it into a
> Win32Lib Pixmap.
LOL. I just finished updating that routine to work with bitmaps, then
I came here to announce it and found your 'answer'!
Anyhow, all I did was update the existing subClassControl routine. I
changed the line ...
phWnd = getHandle(lParent) or -- is its own parent
to read ...
(lParent !=0 and phWnd = getHandle(lParent)) or -- is its own parent
and changed ...
window_handle_type[lNewId] = kht_Window
to ...
if window_type[lNewId] = Pixmap then
window_handle_type[lNewId] = kht_Bitmap
else
window_handle_type[lNewId] = kht_Window
end if
And here is the demo program for it ...
without warning
include win32lib.ew
integer MainWin
integer myPixMap
atom bmh
MainWin = create(Window, "Subclassed bitmap", 0, 0, 0, 500, 400, 0)
bmh = loadBitmapFromFile("..\\demoresources\\java.bmp")
myPixMap = subClassControl({Pixmap, 0}, bmh)
setPenColor(myPixMap, Cyan)
drawRectangle(myPixMap, 1, 0, 0, 40, 40)
procedure Painter(integer self, integer event, sequence parms)
copyBlt(self, 0, 0, myPixMap)
end procedure
setHandler(MainWin, w32HPaint, routine_id("Painter"))
WinMain(MainWin, Normal)
--
Derek Parnell
Melbourne, Australia
3. Re: Derek: function subClassBitmap
Derek Parnell wrote:
> LOL. I just finished updating that routine to work with bitmaps, then
> I came here to announce it and found your 'answer'!
Thanks, Derek. You're right: it's better to implement it in the same function,
instead of creating a new function.
--
tommy online: http://users.pandora.be/tommycarlier