Retro video games delivered to your door every month!
Click above to get retro games delivered to your door ever month!
X-Hacker.org- The Guide to Clip-4-Win version 3.0 - <b>addhandler()</b> http://www.X-Hacker.org [<<Previous Entry] [^^Up^^] [Next Entry>>] [Menu] [About The Guide]
AddHandler()
Add an event handler to the event processing array
------------------------------------------------------------------------------

Syntax
AddHandler( <hWindow>, <bAction> )   -->   nId

Arguments
<hWindow> is the handle of the window to which the handler
<bAction> applies.

<bAction> is a code block to be evaluated when an event
occurs.

Returns
The numeric ID of the newly created event handler.

Description
This function creates a new event handler for a given window
and adds it to the central event processing array.

The code block should be structured to accept a parameter,
which will be the Windows event.  It should then pass that
parameter to the appropriate event-handling function.  You
will generally also pass the window handle to this function,
and depending on the situation may pass additional information
as well.

The following example demonstrates by creating an event
handler that creates a new window and redraws it as necessary.

Example
// the following line is part of the menu creation function ...
AppendMenu( hPopupMenu, "logo", MF_ENABLED + MF_STRING,    ;
            "&Logo",  { | cID | DoLogo( cID ) } )

// elsewhere in the program . . .
static function DoLogo( cItem )
static hWnd
if CheckMenuItem( hMenu, cItem ) == MF_UNCHECKED
     CheckMenuItem( hMenu, cItem, MF_CHECKED )
     hWnd := WinNew( "Logo", 50, 50, 350, 250 )
     AddHandler( hWnd, { |nEvent| LogoEvent( nEvent, hWnd, cItem ) } )
else
     DestroyWindow( hWnd )
     CheckMenuItem( hMenu, cItem, MF_UNCHECKED )
endif
return nil

static function LogoEvent( nEvent, hWnd, nId, cItem )
static cDIB
local hDC
local aDIBRect, aClientRect
do case
case nEvent == EVENT_REDRAW
     hDC := GetDC( hWnd )
     if cDIB == NIL
          cDIB := ReadDIB( LOGO_FILE )
     endif
     aDIBRect := GetDIBRect( cDIB )
     aClientRect := GetClientRect( hWnd )
     ShowDIB( hDC, cDIB,                                           ;
                 ( aClientRect[W_RIGHT] - aDIBRect[W_RIGHT] ) / 2, ;
                 ( aClientRect[W_BOTTOM] - aDIBRect[W_BOTTOM] ) / 2)
     ReleaseDC( hWnd, hDC )
case nEvent == EVENT_CLOSE   // clean up, including toggling menu item
     DestroyWindow( hWnd )
     CheckMenuItem( hMenu, cItem, MF_UNCHECKED )
endcase
return nil


See Also: HandleEvent() DelHandler()

Online resources provided by: http://www.X-Hacker.org --- NG 2 HTML conversion by Dave Pearson