Sign in to follow this  
Followers 0
JScript

_GUIRegisterMsgEx (UDF) - Like native, but for controls.

15 posts in this topic

#1 ·  Posted (edited)

Function Reference


_GUIRegisterMsgEx.au3

Register a user defined function for a known Windows Message ID (WM_MSG) to an individual ctrl using Call Back!

Sintax:

_GUICtrlMsg_Register( controlID, MsgID, "Function" )
_GUICtrlMsg_UnRegister( hWnd [, MsgID ])

Supports:

; AutoIt GUI controls to register message!

Downloads:

Version: 0.9b

_GUIRegisterMsgEx_(RedirectLink).html

Note: The functions have new parameters!, see fixes below!

You can use this UDF in controls that consume internally specific Windows Message ID that we could not register with the GUIRegisterMsg function, eg: WM_CHAR, WM_KEYDOWN, WM_KEYUP are consumed by an edit control.

Usage example is included!

Sample:

Posted Image

Fixes:

  • 0.9.1412.2600b
  • 14/09/2012 -> _GUICtrlMsg_Register() and __GRM_CallBack() by @SmOke_N - - Thank you!

    0.9.1112.2600b

  • 11/09/2012 -> New parameter added: iMsgID!

    Remarks:

    EXACTLY 4 function parameters, otherwise the function won't be called!

    To make the user function workable you have to define it with

    Up to 256 user functions can be registered for message IDs.

    By default after finishing the user function the UDF pass the unhandled messages to default WindowProc, same as if you use the variable $GUI_RUNDEFMSG (in GUIConstantsEx.au3) in return keyword.

    Note: You can blocking of running user functions which executes window messages with commands such as "Msgbox()".

    You can use in controls that consume internally specific Windows Message ID eg: WM_CHAR, WM_KEYDOWN, WM_KEYUP!

    I.e:

    Func _MyRegisterFunc( $hCtrlID, $iMsgID, $WParam, $LParam )
    ;...
    EndFunc

    The 4 parameters have the following values:

  • hCtrlID, The control handle in which the message is registered.
  • iMsg, The Windows message ID.
  • wParam, The first message parameter as hex value.
  • lParam, The second message parameter as hex value.

    (Position. Parameter, Meaning)

  • 0.9.0812.2600b
  • 09/09/2012 -> First release!

I like to use UDFs, although I think this will not be very useful, I hope someone will find useful!

Regards,

João Carlos.

Edited by JScript
1 person likes this

http://forum.autoitbrasil.com/ (AutoIt v3 Brazil!!!)

Somewhere Out ThereJames Ingram

somewh10.png

dropbo10.pngDownload Dropbox - Simplify your life!
Your virtual HD wherever you go, anywhere!

Share this post


Link to post
Share on other sites



Thanks for Sharing


My code:

PredictText: Predict Text of an Edit Control Like Scite. Remote Gmail: Execute your Scripts through Gmail. StringRegExp:Share and learn RegExp.

Run As System: A command line wrapper around PSEXEC.exe to execute your apps scripts as System (LSA). Database: An easier approach for _SQ_LITE beginners.

MathsEx: A UDF for Fractions and LCM, GCF/HCF. FloatingText: An UDF for make your text floating. Clipboard Extendor: A clipboard monitoring tool. 

Custom ScrollBar: Scroll Bar made with GDI+, user can use bitmaps instead. RestrictEdit_SRE: Restrict text in an Edit Control through a Regular Expression.

Share this post


Link to post
Share on other sites

Looks good JScript, but what happened to the $iMsgID parameter in _GUICtrlMsg_Register?


Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

Hi @martin and @PhoenixXL, I'm glad you liked it!

Still in the implementation phase, because I thought nobody would be interested in the UDF, so I let this parameter to later.

Wait for new changes!

Regards,

João Carlos.

Edited by JScript

http://forum.autoitbrasil.com/ (AutoIt v3 Brazil!!!)

Somewhere Out ThereJames Ingram

somewh10.png

dropbo10.pngDownload Dropbox - Simplify your life!
Your virtual HD wherever you go, anywhere!

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

  • 0.9.1112.2600b
  • 11/09/2012 -> New parameter added: iMsgID!

    Remarks:

    To make the user function workable you have to define it with

    EXACTLY 4 function parameters, otherwise the function won't be called!

    I.e:

    Func _MyRegisterFunc( $hCtrlID, $iMsgID, $WParam, $LParam )
    ;...
    EndFunc

    The 4 parameters have the following values:

  • hCtrlID, The control handle in which the message is registered.
  • iMsg, The Windows message ID.
  • wParam, The first message parameter as hex value.
  • lParam, The second message parameter as hex value.

    (Position. Parameter, Meaning)

    Up to 256 user functions can be registered for message IDs.

By default after finishing the user function the UDF pass the unhandled messages to default WindowProc, same as if you use the variable $GUI_RUNDEFMSG (in GUIConstantsEx.au3) in return keyword.

Note: You can blocking of running user functions which executes window messages with commands such as "Msgbox()".

You can use in controls that consume internally specific Windows Message ID eg: WM_CHAR, WM_KEYDOWN, WM_KEYUP!

Regards,

João Carlos.

Edited by JScript

http://forum.autoitbrasil.com/ (AutoIt v3 Brazil!!!)

Somewhere Out ThereJames Ingram

somewh10.png

dropbo10.pngDownload Dropbox - Simplify your life!
Your virtual HD wherever you go, anywhere!

Share this post


Link to post
Share on other sites

#6 ·  Posted (edited)

A suggestion, change the name to GUICtrlRegisterMsg.

Ignore my post, I saw function's name are different from thread's title.

Edited by D4RKON3

Share this post


Link to post
Share on other sites

#8 ·  Posted (edited)

No problem, tell me what name would look better and I'll change!

JS

Maybe GUICtrlRegisterMsg and GUICtrlUnRegisterMsg. To be more handly, make the last paramter optinal, if it was an empty string, unregiter it, just like GUIRegisterMsg (Of course it needs more works, just a suggestion).

A question:

How can I monitor EN_CHANGE message for an Edit control? Maybe I missunderstood the whole usage of this function.

What king of messages can be registered to a control using this UDF? :sweating:

Edited by D4RKON3

Share this post


Link to post
Share on other sites

#9 ·  Posted (edited)

Maybe GUICtrlRegisterMsg and GUICtrlUnRegisterMsg. To be more handly, make the last paramter optinal, if it was an empty string, unregiter it, just like GUIRegisterMsg (Of course it needs more works, just a suggestion).

OK, I'll see what I can do about it!

A question:

How can I monitor EN_CHANGE message for an Edit control? Maybe I missunderstood the whole usage of this function.

According to the following link http://msdn.microsoft.com/en-us/library/windows/desktop/bb761676%28v=vs.85%29.aspx :

"Sent when the user has taken an action that may have altered text in an edit control. This notification code is sent after the system updates the screen. The parent window of the edit control receives this notification code through a WM_COMMAND message."

So you should use the native function to the window, not to control!

What king of messages can be registered to a control using this UDF? :sweating:

I'm still discovering too!

This UDF is only for messages, as well as native: not for notifications

EN_CHANGE is not a message, this is an notification!

Regards,

João Carlos.

Edited by JScript

http://forum.autoitbrasil.com/ (AutoIt v3 Brazil!!!)

Somewhere Out ThereJames Ingram

somewh10.png

dropbo10.pngDownload Dropbox - Simplify your life!
Your virtual HD wherever you go, anywhere!

Share this post


Link to post
Share on other sites

#10 ·  Posted (edited)

Thank you so much for the explaintion, great job tho.

Edited by D4RKON3

Share this post


Link to post
Share on other sites

I had an idea like this a couple of years ago, I opted to just use GUIRegisterMsg() and make functions and stick them inside the the regular WM command functions I created.

However, looking over your code, I noticed a few things ( I didn't look to much, and probably went on a tangent with it ).

Where you have the below:

; Get window handle...
$hWndForm = _WinAPI_GetParent($hCtrlID)
If Not $hWndForm Then Return SetError(5, 0, 0)

(This is just a thought, off the top of my head right this second, I haven't thought of total consequences, but I'd think you might want to do something like:

; Get window handle...
$hWndForm = _WinAPI_GetParent($hCtrlID)
If Not $hWndForm Then
$hwndForm = _WinAPI_GetAncestor($hCtrlID)
Return SetError(5, 0, 0)
EndIf

I also noticed this in your callback function

; line 267 - __GRM_CallBack
; IsString() is called before @error, therefore you won't get a the @error

Case (IsString($vRet) And $vRet = 'GUI_RUNDEFMSG') Or @error = 0xDEAD

; I'd expect something more like:
Case (@error = 0xDEAD) Or (IsString($vRet) And $vRet = 'GUI_RUNDEFMSG')

Example of why it wouldn't work:

; Demonstration to show that Test # 2 will be the only one catching the error
; because the call to IsString() reset the error
; and if it's not a string, then the @error will
; never equal 0xDEAD because it has no error number

Global $gi_testerr = _TestFunc()
If IsString($gi_testerr) Or @error Then
MsgBox(64, "Test #1", "@error caught with test # 1")
EndIf

$gi_testerr = _TestFunc()
If @error Or IsString($gi_testerr) Then
MsgBox(64, "Test #2", "@error caught with test # 2")
EndIf

Func _TestFunc()
Return SetError(1, 0, 0)
EndFunc

However, I'd probably re-write the function more like:

Func __GRM_CallBack($hWnd, $iMsg, $wParam, $lParam)
#forceref $hWnd, $iMsg, $wParam, $lParam

Local $iIndex = __GRM_GetHWndIndex($hWnd)
Local $iIndex2 = __GRM_GetMsgIndex($iMsg, $iIndex)
If Not $iIndex Or Not $iIndex2 Then
Return _WinAPI_CallWindowProc($avGRM_MSGIDS[$iIndex][2], _
$hWnd, $iMsg, $wParam, $lParam)
EndIf

Local $asSubArray = $avGRM_MSGIDS[$iIndex][3]
Local $vRet = Call($asSubArray[$iIndex2][1], $hWnd, $iMsg, $wParam, $lParam)
If @error = 0xDEAD Or (IsString($vRet) And $vRet = 'GUI_RUNDEFMSG') Then
; Pass the unhandled messages to default WindowProc
Return _WinAPI_CallWindowProc($avGRM_MSGIDS[$iIndex][2], $hWnd, $iMsg, $wParam, $lParam)
EndIf

Return $vRet
EndFunc

I'd also look at maybe putting another global or 2, 1 to know the total number of indexes currently for your $avGRM_MSGIDS, and 1 for the max number of indexes to start with for sure so maybe you can get rid of that ReDim

Example:

Global $giGRM_MSGIDSMaxIndex = 100
Global $giGRM_MSGIDSMaxIndex2 = 2
Global $avGRM_MSGIDS[$giGRM_MSGIDSMaxIndex + 1][$giGRM_MSGIDSMaxIndex2 + 1]
Global $giGRM_MSGIDSLastIndex = 0

; $giGRM_MSGIDSLastIndex would be like your $avGRM_MSGIDS[0][0]

Then somewhere where you'd have your Redims, create a function or insert code.

Maybe something like:

If Mod($giGRM_MSGIDSLastIndex + 1, $giGRM_MSGIDSMaxIndex) = 0 Then
$giGRM_MSGIDSMaxIndex += $giGRM_MSGIDSLastIndex
Redim $avGRM_MSGIDS[$giGRM_MSGIDSMaxIndex + 1][$giGRM_MSGIDSMaxIndex2 + 1]
EndIf
$giGRM_MSGIDSLastIndex += 1
$avGRM_MSGIDS[$giGRM_MSGIDSLastIndex][number] = whatever

Having a higher index count to start and with fewer ReDims, you'll see a faster creation process.

1 person likes this

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Share this post


Link to post
Share on other sites
Thanks!!

Share this post


Link to post
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
Sign in to follow this  
Followers 0

  • Similar Content

    • Skysnake
      By Skysnake
      I have read the Tutorial. Used the Help File and used an example script by @Melba23.  I am still struggling.
      To use GUIRegisterMsg one needs the following
      a control in the GUI a GUIRegisterMsg instruction in the GUI to link the control to the WM_COMMAND function a Case statement in the Switch loop to run it a WM_COMMAND function and a processor function... Mine looks like this
      ;~ ; QuickSearch combo box $g_cbQwkSrch = GUICtrlCreateCombo("", 8, 26, 180, 17) ; start blank GUICtrlSetTip($g_cbQwkSrch, "Type to search", "QuickSearch") GUIRegisterMsg($WM_COMMAND, "__WM_COMMAND_QWKSEARCH_CMB") ;------------------------------------ ; use in Switch Loop ;~ ; QuickSearch Case $g_cbQwkSrch ConsoleWrite("221 Case $g_cbQwkSrch" & @CRLF) ;-------------------------------------- Func _QwkSrch_Edit_Changed() ConsoleWrite("41 _QwkSrch_Edit_Changed" & @CRLF) ; Autocomplete the edit _GUICtrlComboBox_AutoComplete($g_cbQwkSrch) ; Change the label to match the autocompleted edit entry EndFunc ;==>_QwkSrch_Edit_Changed Func __WM_COMMAND_QWKSEARCH_CMB($hWnd, $iMsg, $wParam, $lParam) ; GUIRegisterMsg($WM_COMMAND, "__WM_COMMAND_QWKSEARCH_CMB") ConsoleWrite("50 _WM_COMMAND_QWKSEARCH_CMB fired " & @CRLF) Local $Found = '' #forceref $hWnd, $iMsg If $lParam = GUICtrlGetHandle($g_cbQwkSrch) And BitShift($wParam, 16) = $CBN_EDITCHANGE Then ; Our combo edit content has changed ; get data from source ---------------------------- Local $datafromsource = fFindFilesForQuickSearch($stringtofind) ; datafromsource convert to Combo friendly format ; Add data to combo _GUICtrlComboBox_BeginUpdate($g_cbQwkSrch) GUICtrlSetData($g_cbQwkSrch, $Found) _GUICtrlComboBox_EndUpdate($g_cbQwkSrch) EndIf _QwkSrch_Edit_Changed() ; Action this function EndIf EndFunc ;==>_WM_COMMAND_QWKSEARCH_CMB Func fFindFilesForQuickSearch($stringtofind) ; helper function for QuickSearch ; get data here Return $aResult EndFunc ;==>fFindFilesForQuickSearch Now the following:
      Can I declare the variable $g_cbQwkSrch in Global, then use in multiple functions - reassigning different combo's to it as I go along? Should GUIRegisterMsg be expressly de-registered, or does that happen automatically at GuiDelete()? Where is the best/correct place to call GUIRegisterMsg? With the creation of its control, before the GUISetState, or before the start of the loop? The Help File contains this entry, what is the intent?  Must this always be called with four args, or a max of four...   !!! To make the user function workable you have to define it with maximum 4 function parameters otherwise the function won't be called !!!
    • Skysnake
      By Skysnake
      Hi
      Best example I could find is here
      ::/html/libfunctions/_GUICtrlTreeView_ClickItem.htm
      The way I understand this, the standard Windows messages, such as Left/Right Click etc are covered by AutoIt macros, but the real power is locked up inside this WM_NOTIFY .  I have tried, but I am not even sure I understand what I am looking at.
      I need help understanding this.  What I am looking for is Help file or Tutorial explaining how this works?  
      Perhaps if there is a script showing both the working of an AutoIt macro and the WM_NOTIFY  in action, it would help.
      Right now I am so lost, I do not even know what are the right questions to ask.  One issue I have is on ListViews, how to combine the "Click" of a line with a standard Switch loop?  Like users clicks a line, then get the loop to detect the click and ;do something ...
      Any ideas?
      Skysnake
    • junkew
      By junkew
      Since W8.1 (actually IE 11 with W7 will work also) microsoft has a Javascript runtime that can be called from scripting languages
      As shown in this example from C++: https://iobservable.net/blog/2013/11/12/introduction-to-jsrt/
      By loading either JSCRIPT9.DLL or CHAKRA.DLL you can embed ECMA JavaScript in your application
      And implemented here in AutoHotKey https://autohotkey.com/boards/viewtopic.php?f=6&t=5739
      Triggered by other threads: 
      https://www.autoitscript.com/forum/topic/185883-accessing-autoit-variables/ https://iobservable.net/blog/2013/11/12/introduction-to-jsrt/ https://www.autoitscript.com/forum/topic/184824-chakracore-udf-executing-javascript-in-autoit/ http://eclipsesource.com/blogs/2016/04/06/getting-started-with-microsoft-chakracore/
        This code is almost working but unfortunately not with the expected output. Someone seeing what is wrong? 
      It runs completely after fixes of DanyFirex 
       
      ;~ https://iobservable.net/blog/2013/11/ ;~ Should work on all windows versions with IE11 #AutoIt3Wrapper_UseX64=N #Region enum JsErrorCode : unsigned int Enum $JsNoError = 0, _ $JsErrorCategoryUsage = 0x10000, _ $JsErrorInvalidArgument, _ $JsErrorNullArgument, _ $JsErrorNoCurrentContext, _ $JsErrorInExceptionState, _ $JsErrorNotImplemented, _ $JsErrorWrongThread, _ $JsErrorRuntimeInUse, _ $JsErrorBadSerializedScript, _ $JsErrorInDisabledState, _ $JsErrorCannotDisableExecution, _ $JsErrorHeapEnumInProgress, _ $JsErrorArgumentNotObject, _ $JsErrorInProfileCallback, _ $JsErrorInThreadServiceCallback, _ $JsErrorCannotSerializeDebugScript, _ $JsErrorAlreadyDebuggingContext, _ $JsErrorAlreadyProfilingContext, _ $JsErrorIdleNotEnabled, _ $JsErrorCategoryEngine = 0x20000, _ $JsErrorOutOfMemory, _ $JsErrorCategoryScript = 0x30000, _ $JsErrorScriptException, _ $JsErrorScriptCompile, _ $JsErrorScriptTerminated, _ $JsErrorScriptEvalDisabled, _ $JsErrorCategoryFatal = 0x40000, _ $JsErrorFatal ;~ }JsErrorCode; #EndRegion enum JsErrorCode : unsigned int #Region typedef enum JsRuntimeVersion Enum $JsRuntimeVersion10 = 0, $JsRuntimeVersion11 = 1 #EndRegion typedef enum JsRuntimeVersion ; Create callback function. Local $hPrintf = DllCallbackRegister("_printf", "long", "ptr;bool;ptr;ushort;ptr") Local $hJSRuntime = DllOpen("c:\windows\system32\jscript9.dll") $JsRuntimeAttributeNone = 0x00000000 ;~ #RequireAdmin Example() Func Example() Local $script = "native.printf('hello world')" ;~ Local $script = "native.printf('number=%#x string=%s\n', 255, 'test')" ;~ Local $script = "(()=>{return 'Hello world!';})()" ;~ Local $script = "var x='helloworld'; return x;" ;~ Local $script = "var x=10;" & @CRLF & "var y=11;" ;~ Local $script = "(42);" ;~ Local $script = "(" & @CRLF ;~ $script=$script & "host.echo(JSON.stringify({foo:'bar'}));)" & @CRLF ;~ $script=$script & "42 // The script's result :) "& @CRLF ;~ $script=$script & ")"& @CRLF ;~ $script=$script & "class Host {"& @CRLF ;~ $script=$script & " echo(s) {"& @CRLF ;~ $script=$script & " MsgBox %s%"& @CRLF ;~ $script=$script & " }"& @CRLF ;~ $script=$script & "}"& @CRLF Local $aResult Local $runtime Local $context ;~ // Create a runtime ;~ JsCreateRuntime(JsRuntimeAttributeNone, nullptr, &runtime); $runtime = _JsCreateRuntime($JsRuntimeAttributeNone, 0, $runtime) ; ;~ // Create an execution context. ;~ JsCreateContext(runtime, &context); $context = _JsCreateContext($runtime, $context) ;~ // Now set the current execution context. ;~ JsSetCurrentContext(context); _JsSetCurrentContext($context) ; ; Get the Global object for adding stuff ;~ JsGetGlobalObject(&global); Local $global $global = _JsGetGlobalObject($global) ;~ JsPropertyIdRef nativeProp; ;~ JsGetPropertyIdFromName(L"native", &nativeProp); Local $nativeProp $nativeProp = _JsGetPropertyIdFromName("native", $nativeProp) ;~ JsValueRef nativeObj; ;~ JsCreateObject(&nativeObj); Local $nativeObj $nativeObj = _JsCreateObject($nativeObj) ;~ JsPropertyIdRef printfProp; ;~ JsGetPropertyIdFromName(L"printf", &printfProp); Local $printfProp $printfProp = _JsGetPropertyIdFromName("printf", $printfProp) ;~ JsValueRef printfFunc; ;~ JsCreateFunction(PrintFormat, nullptr, &printfFunc); Local $printfFunc $printfFunc = _JsCreateFunction(DllCallbackGetPtr($hPrintf), 0, $printfFunc) ;~ JsSetProperty(nativeObj, printfProp, printfFunc, true); _JsSetProperty($nativeObj, $printfProp, $printfFunc, True) ;~ JsSetProperty(global, nativeProp, nativeObj, true); _JsSetProperty($global, $nativeProp, $nativeObj, True) ;~ STDAPI_(JsErrorCode) JsCreateFunction( ;~ _In_ JsNativeFunction nativeFunction, ;~ _In_opt_ void *callbackState, ;~ _Out_ JsValueRef *function ;~ ); ; Get a JsValueRef for our Host object ;~ hostRef := ToJsValue(Host) ;~ $aResult=DllCall($hJSRuntime, "int","JsVariantToValue", "ptr", &variant, "ptr*", valref) ; Pass our Host object to the script engine ;~ DllCall("jscript9\JsSetProperty", "ptr", globalObject, "ptr", hostPropertyId, "ptr", hostRef, "int", true) ;~ // Run the script. ;~ STDAPI_(JsErrorCode) JsRunScript( ;~ _In_z_ const wchar_t *script, ;~ _In_ JsSourceContext sourceContext, ;~ _In_z_ const wchar_t *sourceUrl, ;~ _Out_ JsValueRef *result ;~ ); Local $currentSourceContext = 1 ;~ JsRunScript(script.c_str(), currentSourceContext++, L"", &result); Local $result = "" Local $sourceURL = "" $aResult = DllCall($hJSRuntime, "int", "JsRunScript", "WSTR", $script, "UINT*", $currentSourceContext, "wstr", "dummysource.js", "WSTR*", $result) ConsoleWrite("Error 11: " & @error & @CRLF) If @error = 0 Then ConsoleWrite($aResult[0] & ";" & $aResult[1] & ";" & $aResult[2] & ";" & $aResult[3] & ";" & $aResult[4] & @CRLF) EndIf ;~ // Convert your script result to String in JavaScript redundant if your script returns a String ;~ JsValueRef resultJSString; ;~ STDAPI_(JsErrorCode) JsConvertValueToString( ;~ _In_ JsValueRef value, ;~ _Out_ JsValueRef *stringValue ;~ ); ;~ JsConvertValueToString(result, &resultJSString); ;~ $aResult=DllCall($hJSRuntime, "int", "JsConvertValueToString", "WSTR", $script, "long", 1, "WSTR*",0, "WSTR*", $result) ;~ consolewrite("Error 4: " & @error & @CRLF) ;~ if @error=0 Then ;~ consolewrite($aResult[0] & ";" & $aResult[1] & ";" & $aResult[2] & ";" & $aResult[3] & ";" & $aResult[4] & @CRLF) ;~ EndIf ;~ ;~ // Project script result back to C++. ;~ const wchar_t *resultWC; ;~ size_t stringLength; ;~ JsStringToPointer(resultJSString, &resultWC, &stringLength); ;~ wstring resultW(resultWC); ;~ cout << string(resultW.begin(), resultW.end()) << endl; ;~ system("pause"); ;~ // Dispose runtime ;~ JsSetCurrentContext(JS_INVALID_REFERENCE); ;~ JsDisposeRuntime(runtime); Return 0 ; EndFunc ;==>Example ; Create callback function. ;~ JsValueRef CALLBACK PrintFormat(JsValueRef callee, bool isConstructCall, JsValueRef *arguments, unsigned short argumentCount, void *callbackState) ;~ { ;~ const wchar_t *format; ;~ size_t length; ;~ JsStringToPointer(arguments[1], &format, &length); ;~ VARIANT variant; ;~ JsValueToVariant(arguments[2], &variant); ;~ const wchar_t *str; ;~ JsStringToPointer(arguments[3], &str, &length); ;~ wprintf(format, variant.intVal, str); ;~ return JS_INVALID_REFERENCE; ;~ } ;~ typedef _Ret_maybenull_ JsValueRef (CALLBACK * JsNativeFunction)( ;~ _In_ JsValueRef callee, ;~ _In_ bool isConstructCall, ;~ _In_ JsValueRef *arguments, ;~ _In_ unsigned short argumentCount ;~ ); Func _printf($callee, $isConstructCall, $arguments, $argumentCount, $callbackState) ConsoleWrite("there we are with " & $argumentCount & " arguments" & @CRLF) Local $tArgs = DllStructCreate("ptr JsValues[" & $argumentCount & "]", $arguments) ;~ STDAPI_(JsErrorCode) JsConvertValueToString( ;~ _In_ JsValueRef value, ;~ _Out_ JsValueRef *stringValue ;~ ); ;~ JsConvertValueToString(result, &resultJSString); local $tresult $aResult=DllCall($hJSRuntime, "int", "JsConvertValueToString", "ptr", DllStructGetData($tArgs,1,2), "ptr*", $tresult) consolewrite("Error 4: " & @error & @CRLF) if @error=0 Then consolewrite( $aResult[0] & ";" & $aResult[1] & ";" & $aResult[2] & @CRLF) $tresult=$aresult[2] EndIf ;~ STDAPI_(JsErrorCode) JsValueToVariant( ;~ _In_ JsValueRef object, ;~ _Out_ VARIANT *variant ;~ ); ;~ Local $aResult = DllCall($hJSRuntime, "dword", "JsValueToVariant", "ptr", $arguments[0], "ptr*", 0) ;~ If @error Then Return SetError(3, 0, @error) ;~ If $aResult[0] <> 0 Then Return SetError(4, 0, $aResult[0]) ;~ consolewrite($aResult[2]) Local $aResult = DllCall($hJSRuntime, "dword", "JsStringToPointer", "ptr", $tResult, "ptr*", 0, "int*", 0) If @error Then Return SetError(3, 0, @error) If $aResult[0] <> 0 Then Return SetError(4, 0, $aResult[0]) Local $tString = DllStructCreate("wchar string["&$aResult[3]&"]", $aResult[2]) consolewrite("+Parameter: " & $tString.string & @CRLF) Return 0 EndFunc ;==>_printf ;~ typedef void *JsRuntimeHandle; ;~ // Create a runtime. ;~ Edge mode signature STDAPI_(JsErrorCode) JsCreateRuntime( ;~ _In_ JsRuntimeAttributes attributes, ;~ _In_opt_ JsThreadServiceCallback threadService, ;~ _Out_ JsRuntimeHandle *runtime); ;~ Legacy mode signature ;~ STDAPI_(JsErrorCode) JsCreateRuntime( ;~ _In_ JsRuntimeAttributes attributes, ;~ _In_ JsRuntimeVersion version, ;~ _In_opt_ JsThreadServiceCallback threadService, ;~ _Out_ JsRuntimeHandle *runtime ;~ ); ;~ $runtime=_JsCreateRuntime(JsRuntimeAttributeNone, 0, $runtime); Func _JsCreateRuntime($JsRuntimeAttributeNone, $JSRuntimeVersion, $runtime) $aResult = DllCall($hJSRuntime, "int", "JsCreateRuntime", "int", $JsRuntimeAttributeNone, "int", $JSRuntimeVersion, "ptr", 0, "ptr*", $runtime) If @error Then Return SetError(1, @error, 0) Return $aResult[4] EndFunc ;==>_JsCreateRuntime ;~ // Edge mode signature ;~ STDAPI_(JsErrorCode) JsCreateContext( ;~ _In_ JsRuntimeHandle runtime, ;~ _Out_ JsContextRef *newContext); ;~ // Legacy mode signature ;~ STDAPI_(JsErrorCode) JsCreateContext( ;~ _In_ JsRuntimeHandle runtime, ;~ _In_ IDebugApplication *debugApplication, ;~ _Out_ JsContextRef *newContext ;~ ); ;~ JsCreateContext(runtime, &context); Func _JsCreateContext($runtime, $context) $aResult = DllCall($hJSRuntime, "int", "JsCreateContext", "ptr", $runtime, "ptr", 0, "ptr*", $context) If @error Then Return SetError(1, @error, 0) Return $aResult[3] EndFunc ;==>_JsCreateContext ;~ STDAPI_(JsErrorCode) JsSetCurrentContext( ;~ _In_ JsContextRef context ;~ ); ;~ JsSetCurrentContext(context); Func _JsSetCurrentContext($context) $aResult = DllCall($hJSRuntime, "int", "JsSetCurrentContext", "ptr", $context) If @error Then Return SetError(1, @error, 0) Return $JsNoError EndFunc ;==>_JsSetCurrentContext ; Get the Global object for adding stuff ;~ STDAPI_(JsErrorCode) JsGetGlobalObject( ;~ _Out_ JsValueRef *globalObject ;~ ); ;~ JsValueRef global; ;~ JsGetGlobalObject(&global); Func _JsGetGlobalObject($global) $aResult = DllCall($hJSRuntime, "int", "JsGetGlobalObject", "ptr*", $global) If @error Then Return SetError(1, @error, 0) Return $aResult[1] EndFunc ;==>_JsGetGlobalObject ; Get a property ID for the name "host" ;~ STDAPI_(JsErrorCode) JsGetPropertyIdFromName( ;~ _In_z_ const wchar_t *name, ;~ _Out_ JsPropertyIdRef *propertyId ;~ ); ;~ DllCall("jscript9\JsGetPropertyIdFromName", "wstr", "host", "ptr*", hostPropertyId) ;~ local $hostPropertyID ;~ $aResult=DllCall($hJSRuntime, "int","JsGetPropertyIdFromName", "wstr", "host", "ptr*", $hostPropertyId) ;~ consolewrite("Error 5: " & @error & @CRLF) ;~ if @error=0 Then ;~ consolewrite($aResult[0] & ";" & $aResult[1] & ";" & $aResult[2] & @CRLF) ;~ EndIf ;~ JsPropertyIdRef nativeProp; ;~ JsGetPropertyIdFromName(L"native", &nativeProp); Func _JsGetPropertyIdFromName($propname, $nativeProp) $aResult = DllCall($hJSRuntime, "int", "JsGetPropertyIdFromName", "wstr", $propname, "ptr*", $nativeProp) If @error Then Return SetError(1, @error, 0) Return $aResult[2] EndFunc ;==>_JsGetPropertyIdFromName ;~ STDAPI_(JsErrorCode) JsCreateObject( ;~ _Out_ JsValueRef *object ;~ ); ;~ JsValueRef nativeObj; ;~ JsCreateObject(&nativeObj); Local $nativeObj Func _JsCreateObject($JSRTobject) $aResult = DllCall($hJSRuntime, "int", "JsCreateObject", "ptr*", $JSRTobject) If @error Then Return SetError(1, @error, 0) Return $aResult[1] EndFunc ;==>_JsCreateObject ;~ STDAPI_(JsErrorCode) JsCreateFunction( ;~ _In_ JsNativeFunction nativeFunction, ;~ _In_opt_ void *callbackState, ;~ _Out_ JsValueRef *function ;~ ); Func _JsCreateFunction($fncCallBackPtr, $callbackState, $fncVar) $aResult = DllCall($hJSRuntime, "int", "JsCreateFunction", "ptr", $fncCallBackPtr, "ptr*", $callbackState, "ptr*", $fncVar) If @error Then Return SetError(1, @error, 0) Return $aResult[3] EndFunc ;==>_JsCreateFunction ;~ JsSetProperty(nativeObj, printfProp, printfFunc, true); ;~ STDAPI_(JsErrorCode) JsSetProperty( ;~ _In_ JsValueRef object, ;~ _In_ JsPropertyIdRef propertyId, ;~ _In_ JsValueRef value, ;~ _In_ bool useStrictRules ;~ ); Func _JsSetProperty($Obj, $Prop, $Func, $val) ; $aResult = DllCall($hJSRuntime, "int", "JsSetProperty", "ptr", $Obj, "ptr", $Prop, "ptr", $Func, "int", $val) If @error Then Return SetError(1, @error, 0) EndFunc ;==>_JsSetProperty  
    • kcvinu
      By kcvinu
      Hi all,
      I know this is a crazy idea. But i think it might be a help for somebody. The name of this program is GRM Helper. i.e. GUIRegisterMsg Helper. 
      This program helps you to write the guiregistermsg function code automatically. You can choose a control from the combo box. Then all events of that control will be displayed in a list view. You can click on an event for it;s details. Then you can check the events which you want to include in your code. Then type some details like; 1) Your control's handle. 2) Line number for inserting GUIRegisterMsg code. 3) Line number for inserting main function.
      And press the "Isert To SciTE" button. Your code is ready in scite.
       
      Here is the program.
      Updated Version 1.1
      GRM Helper V1.1.zip
       
       

      The code written by this program.
      GUIRegisterMsg($WM_COMMAND, "WM_COMMAND") Func WM_COMMAND($hWnd, $iMsg, $wParam, $lParam) #forceref $hWnd, $iMsg Local $hWndFrom, $iIDFrom, $iCode, $hWndListBox If Not IsHWnd($Sample) Then $hWndListBox = GUICtrlGetHandle($Sample) $hWndFrom = $lParam $iIDFrom = BitAND($wParam, 0xFFFF) ; Low Word $iCode = BitShift($wParam, 16) ; Hi Word Switch $hWndFrom Case $Sample, $hWndListBox Switch $iCode Case $LBN_ERRSPACE ; Insert your code here Case $LBN_SELCHANGE ; Insert your code here Case $LBN_DBLCLK ; Insert your code here Case $LBN_SELCANCEL ; Insert your code here EndSwitch EndSwitch Return $GUI_RUNDEFMSG EndFunc ;==>WM_COMMAND  
       
    • kcvinu
      By kcvinu
      Hi all,
      I am playing with a combo box. The code from help file is working. But the code i wrote is not working. Help file uses "_GUICtrlComboBox_Create" for creating combo box. But i used native "GUICtrlCreateCombo". Then i replaced my native combo creation function with the UDF. Then my code worked. I think the hi word and low word parameters are the problem. 
      Here is my code.
      #include <ComboConstants.au3> #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> Local $sCMB_Items = "Apple|Orange|Mango|Banana|Grape" #Region ### START Koda GUI section ### Form= Global $hForm1 = GUICreate("Form1", 283, 188, 312, 166) Global $hCombo1 = GUICtrlCreateCombo("", 40, 48, 185, 25, BitOR($CBS_DROPDOWN,$CBS_AUTOHSCROLL)) GUISetState(@SW_SHOW) #EndRegion ### END Koda GUI section ### GUICtrlSetData($hCombo1, $sCMB_Items) GUIRegisterMsg($WM_COMMAND, "WM_COMMAND") While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit EndSwitch WEnd Func WM_COMMAND($hWnd, $iMsg, $wParam, $lParam) #forceref $hWnd, $iMsg Local $hWndFrom, $iIDFrom, $iCode $hWndFrom = $lParam $iIDFrom = BitAND($wParam, 0xFFFF) ; Low Word $iCode = BitShift($wParam, 16) ; Hi Word Switch $hWndFrom Case $hCombo1 Switch $iCode Case $CBN_DBLCLK ; Insert your code here MsgBox(0,"","$CBN_DBLCLK") Case $CBN_DROPDOWN ; Insert your code here MsgBox(0,"","$CBN_DROPDOWN") Case $CBN_EDITCHANGE ; Insert your code here MsgBox(0,"","$CBN_EDITCHANGE") Case $CBN_SELCHANGE ; Insert your code here MsgBox(0,"","$CBN_SELCHANGE") EndSwitch EndSwitch Return $GUI_RUNDEFMSG EndFunc ;==>WM_COMMAND And this is the code from help file. Slightly modified. But working
      #include <GuiComboBox.au3> #include <GUIConstantsEx.au3> #include <MsgBoxConstants.au3> #include <WindowsConstants.au3> Global $g_hCombo Example() Func Example() Local $hGUI ; Create GUI $hGUI = GUICreate("(UDF) ComboBox Create", 400, 296) $g_hCombo = _GUICtrlComboBox_Create($hGUI, "", 2, 2, 396, 296) GUISetState(@SW_SHOW) ; Add files _GUICtrlComboBox_BeginUpdate($g_hCombo) _GUICtrlComboBox_AddDir($g_hCombo, "", $DDL_DRIVES, False) _GUICtrlComboBox_EndUpdate($g_hCombo) GUIRegisterMsg($WM_COMMAND, "WM_COMMAND") ; Loop until the user exits. Do Until GUIGetMsg() = $GUI_EVENT_CLOSE GUIDelete() EndFunc ;==>Example Func WM_COMMAND($hWnd, $iMsg, $wParam, $lParam) #forceref $hWnd, $iMsg Local $hWndFrom, $iIDFrom, $iCode $hWndFrom = $lParam $iIDFrom = BitAND($wParam, 0xFFFF) ; Low Word $iCode = BitShift($wParam, 16) ; Hi Word Switch $hWndFrom Case $g_hCombo Switch $iCode Case $CBN_CLOSEUP ; Sent when the list box of a combo box has been closed MsgBox(0,"","$CBN_CLOSEUP") Case $CBN_DBLCLK ; Sent when the user double-clicks a string in the list box of a combo box MsgBox(0,"","$CBN_DBLCLK") Case $CBN_DROPDOWN ; Sent when the list box of a combo box is about to be made visible MsgBox(0,"","$CBN_DROPDOWN") Case $CBN_EDITCHANGE ; Sent after the user has taken an action that may have altered the text in the edit control portion of a combo box MsgBox(0,"","$CBN_EDITCHANGE") Case $CBN_EDITUPDATE ; Sent when the edit control portion of a combo box is about to display altered text Case $CBN_ERRSPACE ; Sent when a combo box cannot allocate enough memory to meet a specific request Case $CBN_KILLFOCUS ; Sent when a combo box loses the keyboard focus Case $CBN_SELCHANGE ; Sent when the user changes the current selection in the list box of a combo box MsgBox(0,"","$CBN_SELCHANGE") EndSwitch EndSwitch Return $GUI_RUNDEFMSG EndFunc ;==>WM_COMMAND For those who wants the au3 file;
      Here it is
       
      Code From help file.au3
      My code.au3