Function Reference


_WinAPI_CallWindowProc

Passes the hook information to the next hook procedure in the current hook chain

#include <WinAPI.au3>
_WinAPI_CallWindowProc ( $pPrevWndFunc, $hWnd, $iMsg, $wParam, $lParam )

Parameters

$pPrevWndFunc Pointer to the previous window procedure.
If this value is obtained by calling the _WinAPI_GetWindowLong() function with the $iIndex parameter set to $GWL_WNDPROC or $DWL_DLGPROC, it is actually either the address of a window or dialog box procedure, or a special internal value meaningful only to _WinAPI_CallWindowProc().
$hWnd Handle to the window procedure to receive the message
$iMsg Specifies the message
$wParam Specifies additional message-specific information. The contents of this parameter depend on the value of the Msg parameter
$lParam Specifies additional message-specific information. The contents of this parameter depend on the value of the Msg parameter

Return Value

Returns the return value specifies the result of the message processing and depends on the message sent

Remarks

Use the _WinAPI_CallWindowProc() function for window subclassing. Usually, all windows with the same class share one window procedure.
A subclass is a window or set of windows with the same class whose messages are intercepted and processed by another window procedure (or procedures) before being passed to the window procedure of the class.

The _WinAPI_SetWindowLong() function creates the subclass by changing the window procedure associated with a particular window, causing the system to call the new window procedure instead of the previous one.
An application must pass any messages not processed by the new window procedure to the previous window procedure by calling _WinAPI_CallWindowProc().
This allows the application to create a chain of window procedures.

Related

_WinAPI_SetWindowLong

See Also

Search CallWindowProc in MSDN Library.

Example

#include <GUIConstantsEx.au3>
#include <GuiEdit.au3>
#include <GuiMenu.au3>
#include <WinAPI.au3>
#include <WindowsConstants.au3>

Global $g_idContextMenu, $g_idCommonMenuItem, $g_idFileMenuItem, $g_idExitMenuItem
Global $g_hGui, $g_idInput, $g_hProcOld

Example()

Func Example()
    Local $idInput2, $hProcNew, $idDummyMenu

    $g_hGui = GUICreate("Type or paste some stuff", 400, 200, -1, -1, $WS_THICKFRAME, -1)
    $g_idInput = GUICtrlCreateInput("", 20, 20, 360, 20)
    $idInput2 = GUICtrlCreateInput("", 20, 50, 360, 20)

    GUICtrlCreateLabel("abcd", 1, 1, 30, 18)
    GUICtrlSetCursor(-1, 9)

    $hProcNew = DllCallbackRegister("_MyWindowProc", "ptr", "hwnd;uint;long;ptr")
    $g_hProcOld = _WinAPI_SetWindowLong(GUICtrlGetHandle($g_idInput), $GWL_WNDPROC, DllCallbackGetPtr($hProcNew))
    _WinAPI_SetWindowLong(GUICtrlGetHandle($idInput2), $GWL_WNDPROC, DllCallbackGetPtr($hProcNew))
    ;_WinAPI_SetWindowLong(GUICtrlGetHandle($g_idInput3), $GWL_WNDPROC, DllCallbackGetPtr($hProcNew)) and so on

    $idDummyMenu = GUICtrlCreateDummy()
    $g_idContextMenu = GUICtrlCreateContextMenu($idDummyMenu)
    $g_idCommonMenuItem = GUICtrlCreateMenuItem("Common", $g_idContextMenu)
    $g_idFileMenuItem = GUICtrlCreateMenuItem("File", $g_idContextMenu)
    GUICtrlCreateMenuItem("", $g_idContextMenu)
    $g_idExitMenuItem = GUICtrlCreateMenuItem("Exit", $g_idContextMenu)

    GUISetState(@SW_SHOW)
    While 1
        Switch GUIGetMsg()
            Case $GUI_EVENT_CLOSE
                ExitLoop
        EndSwitch
    WEnd
EndFunc   ;==>Example

Func do_clever_stuff_with_clipboard($hWnd)
    Local $sData
    $sData = ClipGet()
    If @error Then Return 0;clip data is not text or clip empty
    ;do whatever
    $sData = StringUpper($sData)
    ;set text
    GUICtrlSetData(_WinAPI_GetDlgCtrlID($hWnd), $sData);or _GUICtrlEdit_SetText($hWnd, $sData)
    Return 1
EndFunc   ;==>do_clever_stuff_with_clipboard

; Show a menu in a given GUI window which belongs to a given GUI ctrl
Func ShowMenu($hWnd, $idContext)
    Local $iSelected = _GUICtrlMenu_TrackPopupMenu(GUICtrlGetHandle($idContext), $hWnd, -1, -1, -1, -1, 2)
    Switch $iSelected
        Case $g_idCommonMenuItem
            ConsoleWrite("Common" & @CRLF)
        Case $g_idFileMenuItem
            ConsoleWrite("File" & @CRLF)
        Case $g_idExitMenuItem
            ConsoleWrite("Exit" & @CRLF)
    EndSwitch
EndFunc   ;==>ShowMenu

Func _MyWindowProc($hWnd, $iMsg, $wParam, $lParam)
    Switch $iMsg
        Case $WM_PASTE
            Return do_clever_stuff_with_clipboard($hWnd)
        Case $WM_CONTEXTMENU
            If $hWnd = GUICtrlGetHandle($g_idInput) Then
                ShowMenu($g_hGui, $g_idContextMenu)
                Return 0
            EndIf
        Case $WM_SETCURSOR
            GUICtrlSetCursor(_WinAPI_GetDlgCtrlID($hWnd), 5);;set Ibeam cursor
            Return 1;;and don't let default windowproc mess things up
    EndSwitch

    ;pass the unhandled messages to default WindowProc
    Return _WinAPI_CallWindowProc($g_hProcOld, $hWnd, $iMsg, $wParam, $lParam)
EndFunc   ;==>_MyWindowProc