Re: Win32Lib getPixel problem revised - and fixed

new topic     » topic index » view thread      » older message » newer message

Brian and colleagues - yes, a pixmap cures it completely.
I didn't realize the difference - in fact I hadn't "noticed" pixmaps at all.
I was sent a demo program which I can add on here which shows it working 
nicely with pixmaps - many thanks Derek! smile
In my proper program I shall have a bitmap which is visible on-screen 
and a pixmap duplicate.
This is, apparently, a common use for the pixmap.

------------------------------------------------------------------------
without warning
include win32lib.ew

constant Test = createEx( Window,
     "Left-Click samples 'Page' and right-click samples 'Copy' - see 
program details",
      0, Center, Center, 756, 526, 0, 0 )
constant Page = createEx( Pixmap, "", Test, 0, 0, 750, 500, 0, 0 )
constant Copy = createEx( Pixmap, "", Test, 0, 0, 750, 500, 0, 0 )

integer  Status        Status = 0
integer     Request    Request = 0
object      res

sequence Drawing    Drawing = {}
sequence Start, Stop

--    Two "identical" bitmaps set to either Red or Green
--    Page will have its mouse events monitored, Copy won't

setPenColor(Copy, Red)
drawRectangle(Copy, w32True, 0,0,750,500)

setPenColor(Page, Green)
drawRectangle(Page, w32True, 0,0,750,500)

--    Collect mouse events on 'Page' only (topmost control)
--   but get pixel relative position from Test - the program window

procedure Page_onMouse (integer self, integer event, sequence params)
       sequence pos
       sequence msg

    event = params[1]           -- Replace this with the mouse event
       pos = getPointerRelPos(Test)  -- Get coordinate on 'Page' - same 
on 'Copy'

    if event = RightDown then
       event = getPixel(Copy, pos[1], pos[2])    -- Sample bitmap NOT 
clicked on
       msg = "Copy bitmap"
       elsif event = LeftDown then
       event = getPixel(Page, pos[1], pos[2])    -- Sample bitmap clicked on
       msg = "Page bitmap"
       else
           return                                    -- Any other event
       end if
      
       res = message_box("getPixel returned " & sprintf("%6x", event),
msg,MB_ICONEXCLAMATION)

end procedure

-- Draw the Page bitmap onto the window when the window needs repainting
--    as Page & Copy are not visible (pixmaps aren't)

procedure Paint_Test (integer self, integer event, sequence params)
    copyBlt(Test, 0, 0, Page)
end procedure

setHandler( Screen, w32HMouse, routine_id("Page_onMouse"))
setHandler( Test, w32HPaint, routine_id("Paint_Test"))
WinMain( Test,Normal )
------------------------------------------------------------------------

new topic     » topic index » view thread      » older message » newer message

Search



Quick Links

User menu

Not signed in.

Misc Menu