Function Reference


_WinAPI_CallWindowProc

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

#include <WinAPISysWin.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 <GuiMenu.au3>
#include <WinAPIDlg.au3>
#include <WinAPISysWin.au3>
#include <WindowsNotifsConstants.au3>
#include <WindowsStylesConstants.au3>

Global $g_idContextMenu, $g_idMni_Common, $g_idMni_File, $g_idMni_Exit
Global $g_hGui, $g_idInput, $g_hProcOld

Example()

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

    $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

    $idDummy_Menu = GUICtrlCreateDummy()
    $g_idContextMenu = GUICtrlCreateContextMenu($idDummy_Menu)
    $g_idMni_Common = GUICtrlCreateMenuItem("Common", $g_idContextMenu)
    $g_idMni_File = GUICtrlCreateMenuItem("File", $g_idContextMenu)
    GUICtrlCreateMenuItem("", $g_idContextMenu)
    $g_idMni_Exit = 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_idMni_Common
            ConsoleWrite("Common" & @CRLF)
        Case $g_idMni_File
            ConsoleWrite("File" & @CRLF)
        Case $g_idMni_Exit
            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