Uten Posted September 18, 2006 Share Posted September 18, 2006 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. expandcollapse popup#Region Compiler directives section #compiler_compression = 4 #compiler_OutFile_Type=exe #compiler_run_after=move /Y "%out%" "%TEMP%" ;TODO: Put it somwhere it is deleted from time to time. #compiler_run_after="%TEMP%\%scriptfile%.exe" #endregion #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 GUIRegisterMsg($MY_MSGS, "MY_MSGS_HANDLER") Main() Exit 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) GUISetState() ; 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 Exit ElseIf $msg = $nBtnPostMessage Then PostMessage($gMe, $MY_MSGS, $gClicks, $gReceived) $gClicks += 1 Else ;;;ConsoleWrite(@SEC & " Hmm, " & $msg & @LF) EndIf WEnd EndFunc ;==>Main ; Func MY_MSGS_HANDLER($hWnd, $nMsg, $wParam, $lParam) $gReceived += 1 GUICtrlSetData($gCtlList, "$wParam:=" & $wParam & ", $lParam:=" & $lParam & ", $gZeroMsgCall:=" & $gZeroMsgCall & "|") Return $GUI_RUNDEFMSG EndFunc ;==>MY_MSGS_HANDLER ; Func PostMessage($hWnd, $msg, $wParm, $lParm) Return DllCall("user32.dll", "int", "PostMessage", _ "hwnd", $hWnd, _ "int", $msg, _ "int", $wParm, _ "int", $lParm) EndFunc ;==>PostMessage Please keep your sig. small! Use the help file. Search the forum. Then ask unresolved questions :) Script plugin demo, Simple Trace udf, TrayMenuEx udf, IOChatter demo, freebasic multithreaded dll sample, PostMessage, Aspell, Code profiling Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now