Jump to content

PostMessage dllcall sample.


Recommended Posts

Just a small sample to show how postmessage can be used in a AutoIt application.

You will find a more advanced sample in the help file under GuiRegisterMessage.

This sample will use a custom message and custom message ID and custom message handler to process the posted message.

#Region Compiler directives section
#compiler_compression = 4
#compiler_run_after=move /Y "%out%" "%TEMP%" ;TODO: Put it somwhere it is deleted from time to time.
#include <GUIConstants.au3>
Global Const $MY_MSGS = 0x0797 ;Pick a number. Not sure if the system has a API that will give you the next free one.
Global $gClicks, $gReceived
Global $gMe, $gCtlList, $gZeroMsgCall


Func Main()
    ;Setup a gui
    $gMe = GUICreate("Test PostMessage", 500, 300)
    $txt = "Just a simple application to show how we can post a message to our self and handle it in a special message handler"
    $nLabel = GUICtrlCreateLabel($txt, 10, 5, 480, 40)
    Local Const $TOP = 50
    $gCtlList = GUICtrlCreateList("", 90, $TOP, 380, 240)
    $nBtnPostMessage = GUICtrlCreateButton("Post message", 10, $TOP + 0 * 30, 70, 20)
    ; Message loop
    Local $msg
    While 1
        $msg = GUIGetMsg()
        If $msg = 0 Then
            $gZeroMsgCall += 1
            DllCall("user32.dll", "int", "WaitMessage") ; Will cut down unnecesarry calls by about 80%. Could influence the way AutoIt is working internally!
        ElseIf $msg = -3 Then
        ElseIf $msg = $nBtnPostMessage Then
            PostMessage($gMe, $MY_MSGS, $gClicks, $gReceived)
            $gClicks += 1
            ;;;ConsoleWrite(@SEC & " Hmm, " & $msg & @LF)
EndFunc   ;==>Main
Func MY_MSGS_HANDLER($hWnd, $nMsg, $wParam, $lParam)
    $gReceived += 1
    GUICtrlSetData($gCtlList, "$wParam:=" & $wParam & ", $lParam:=" & $lParam & ", $gZeroMsgCall:=" & $gZeroMsgCall & "|")
Func PostMessage($hWnd, $msg, $wParm, $lParm)
    Return DllCall("user32.dll", "int", "PostMessage", _
            "hwnd", $hWnd, _
            "int", $msg, _
            "int", $wParm, _
            "int", $lParm)
EndFunc   ;==>PostMessage
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Recently Browsing   0 members

    • No registered users viewing this page.
  • Create New...