Re: Stopping onClose Event in Win32Lib

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

Ray Smith wrote:

> I can use the "onClose" event to process a procedure when the
> user clicks on the "x" but I don't know how to cancel the even
> if the user wants to click on "Cancel" meaning I do not want to close.

Good point. I've been wondering how to implement the overriding of default
behaviors in Win32Lib.

When Win32Lib creates a control, it grabs the control's callback (a pointer
to Win32 code that handles events), and stores it in window_func. Then in
replaces the default Win32 callback with a Euphoria callback to my WndProc
routine. When a control gets an action, Win32 triggers the Euphoria callback
code instead of the default Win32 callback. That's how Win32Lib "hooks" into
events.

Since the Euphoria code gets run *instead* of the default window callback,
it's up to Win32Lib to call the callback when it's done, or Win32 can't do
the default action (like draw, resize, or click a control). So when the
Euphoria code is done running, Win32Lib calls the original Win32 callback of
the control:

    -- run behavior
    return c_func( xCallWindowProc, {   window_func[id],
                                        hWnd,
                                        iMsg,
                                        wParam,
                                        lParam } )

For windows, Win32Lib runs it's own code, and then calls DefWindowProc to
handle the default action:

    return c_func( xDefWindowProc, { myHwnd, iMsg, wParam, lParam } )

What (I think) you are asking is the ability to specify that the default
action (for example, closing the window) *not* be called in certain cases.
There is currently no way to do that, but it wouldn't be difficult to add.
For example, I could add a routine skipDefaultAction (or some better name)
that would flag the default callback from running. So you could write:

   function onClose_Window()
      -- is the flag preventing the window from closing?
      if not canClose then
         -- cancel the default action
         skipDefaultAction()
      end if
   end function

and if the canClose flag was false, the window would not close

Comments?

Thanks.

-- David Cuny

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

Search



Quick Links

User menu

Not signed in.

Misc Menu