Win32Lib getPixel problem revised
- Posted by Andy Drummond <andy at kestreltele.com> Dec 16, 2005
- 543 views
I posted a query about getPixel() in Win32Lib recently. But when I tried the test here at work I couldn't replicate the problem. Now I have. The problem is this. I have two bitmaps. They overlay one another. I click on the top, visible, one with the mouse. I can then read the value of the top bitmap, which picked up the mouse events, fine. But using the same coordinates for the other bitmap I get -1 returned. I attach a sample program which shows the problem - left clicks use getPixel on one bitmap, right clicks on the other. So ...... now, does anyone have the answer to this? What have I missed? Why are you saying "What a dork!"? --------------------------------------------------------------- include Win32Lib.ew without warning with trace 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( Bitmap, "", Test, 0, 0, 750, 500, 0, 0 ) constant Copy = createEx( Bitmap, "", 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) procedure Page_onMouse (integer self, integer event, sequence params) sequence pos event = params[1] -- Replace this with the mouse event pos = getPointerRelPos(Page) -- Get coordinate on 'Page' - same on 'Copy' if event = RightDown then event = getPixel(Copy, pos[1], pos[2]) -- Sample bitmap NOT clicked on elsif event = LeftDown then event = getPixel(Page, pos[1], pos[2]) -- Sample bitmap clicked on else return -- Any other event end if res = message_box("getPixel returned "&sprint(event), "getPixel()", MB_ICONEXCLAMATION) end procedure setHandler( Page, w32HMouse, routine_id("Page_onMouse")) WinMain( Test,Normal ) ---------------------------------------------------------------