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>subclasswindow()</b> http://www.X-Hacker.org [<<Previous Entry] [^^Up^^] [Next Entry>>] [Menu] [About The Guide]
SubClassWindow()
Intercept messages on their way to a window procedure
------------------------------------------------------------------------------

Syntax
SubClassWindow( <hWnd>, <bAction>, <anWM> | -1 )   -->   nProc

Arguments
<hWnd> is the handle to the window to be subclassed.

<bAction> is the code block to be given the messages.

<anWM> is a single message or an array of messages (or -1,
meaning all messages) to be intercepted and sent to the code
block <bAction>.

Returns
A numeric value, identifying the previous window procedure.
You must use this value if you want to use CallWindowProc().

Description
This function arranges to intercept the specified messages on
their way to the window's window procedure.  You can then do
special processing, instead of or in addition to the
processing that would have occurred.

When you subclass a window and subsequently get sent messages,
they are sent to the <bAction> code block.  You can process
them and/or pass them along to the original window procedure,
using CallWindowProc().

Because you will probably use CallWindowProc(), which needs
access to the <nProc>, the code block should be as follows:

     { | hWnd, nMsg, nwParam, nlParam |      ;
        YourFunc( nProc, hWnd, nMsg, nwParam, nlParam ) }

nProc is the value returned previously by SubClassWindow(),
and the next 4 parameters are part of the message from
Windows:

  hWnd       is the handle to the window that was subclassed
  nMsg       is the message (one of the WM_* values defined in WINDOWS.CH)
  nwParam    depends on nMsg
  nlParam    depends on nMsg


If you have any previous knowledge of window subclassing, you
might be tempted to use SetWindowLong() with GWL_WNDPROC.
That's OK if you're using C, but not for Clipper (PRG) code.

Example
// This example is from source\od.prg (owner drawn button)

local     nProc

nProc = SubClassWindow(hWnd,                           ;
                 {|hWnd, nMsg, nwParam, nlParam|       ;
                  BtnWndProc(nProc, hWnd, nMsg, nwParam, nlParam)}, ;
                 WM_DRAWITEM)
// . . .

static function BtnWndProc(nProc, hWnd, nMsg, nwParam, nlParam)
static    cDIB
// nMsg == WM_DRAWITEM, so nlParam is LPDRAWITEMSTRUCT
local     aDIS := bin2a(c4w_peek(nlParam, 26), "uint[7],int[4],dword")
local     hDC

aDbg = aDIS

if cDIB == nil
     cDIB = ReadDIB("play.bmp")
endif

if aDIS[1] == ODT_BUTTON
     hDC = GetDC(hWnd)
     ShowDIB(hDC, cDIB)
     ReleaseDC(hWnd, hDC)
     return 1
endif

return CallWindowProc(nProc, hWnd, nMsg, nwParam, nlParam)

See Also: CallWindowProc()

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