Jump to content

Send $CmdLineRaw via _SendMessage() - Possible?


MrCreatoR
 Share

Recommended Posts

Hi all,

My question is - how can i pass the $CmdLine parameters via _SendMessage (or other methods) to the same window process?

See this example please:

#include <GuiConstants.au3>
#include <Misc.au3>

If _Singleton("test", 1) = 0 Then
    $hWnd = WinGetHandle("SendMessage Test")
    _SendMessage($hWnd, $WM_USER, $CmdLineRaw)
    Exit
EndIf

$Gui = GuiCreate("SendMessage Test")

GUIRegisterMsg($WM_USER, "WM_USER")

GUISetState()

While 1
    $Msg = GUIGetMsg()
    Switch $Msg
        Case -3
            Exit
    EndSwitch
WEnd

Func WM_USER($hWnd, $Msg, $wParam, $lParam)
    MsgBox(0, "", $wParam)
EndFunc

Here i want to get the $CmdLineRaw that was passed to the script when it was executed again (while one instance of the script is already runing)..

To check this, just run the script once, and then without exiting run it again (not from SciTE), you will see the message box.

And as you see, only what it returns is 0x00000000 with the $wParam... i guesing that this is incorrect way to pass data, maybe i need to set wParam type or something, but what type? or there is some other way to do it? (without saving data to temporary file).

Thanks.

 

Spoiler

Using OS: Win 7 Professional, Using AutoIt Ver(s): 3.3.6.1 / 3.3.8.1

AutoIt_Rus_Community.png AutoIt Russian Community

My Work...

Spoiler

AutoIt_Icon_small.pngProjects: ATT - Application Translate Tool {new}| BlockIt - Block files & folders {new}| SIP - Selected Image Preview {new}| SISCABMAN - SciTE Abbreviations Manager {new}| AutoIt Path Switcher | AutoIt Menu for Opera! | YouTube Download Center! | Desktop Icons Restorator | Math Tasks | KeyBoard & Mouse Cleaner | CaptureIt - Capture Images Utility | CheckFileSize Program

AutoIt_Icon_small.pngUDFs: OnAutoItErrorRegister - Handle AutoIt critical errors {new}| AutoIt Syntax Highlight {new}| Opera Library! | Winamp Library | GetFolderToMenu | Custom_InputBox()! | _FileRun UDF | _CheckInput() UDF | _GUIInputSetOnlyNumbers() UDF | _FileGetValidName() UDF | _GUICtrlCreateRadioCBox UDF | _GuiCreateGrid() | _PathSplitByRegExp() | _GUICtrlListView_MoveItems - UDF | GUICtrlSetOnHover_UDF! | _ControlTab UDF! | _MouseSetOnEvent() UDF! | _ProcessListEx - UDF | GUICtrl_SetResizing - UDF! | Mod. for _IniString UDFs | _StringStripChars UDF | _ColorIsDarkShade UDF | _ColorConvertValue UDF | _GUICtrlTab_CoverBackground | CUI_App_UDF | _IncludeScripts UDF | _AutoIt3ExecuteCode | _DragList UDF | Mod. for _ListView_Progress | _ListView_SysLink | _GenerateRandomNumbers | _BlockInputEx | _IsPressedEx | OnAutoItExit Handler | _GUICtrlCreateTFLabel UDF | WinControlSetEvent UDF | Mod. for _DirGetSizeEx UDF
 
AutoIt_Icon_small.pngExamples: 
ScreenSaver Demo - Matrix included | Gui Drag Without pause the script | _WinAttach()! | Turn Off/On Monitor | ComboBox Handler Example | Mod. for "Thinking Box" | Cool "About" Box | TasksBar Imitation Demo

Like the Projects/UDFs/Examples? Please rate the topic (up-right corner of the post header: Rating AutoIt_Rating.gif)

* === My topics === *

==================================================
My_Userbar.gif
==================================================

 

 

 

AutoIt is simple, subtle, elegant. © AutoIt Team

Link to comment
Share on other sites

I modified it to work around this in the help file:

Warning: blocking of running user functions which executes window messages with commands such as "Msgbox()" can lead to unexpected behavior, the return to the system should be as fast as possible !!!

This did not change results, but I noticed you didn't type the params in _SendMessage(). Your string is being converted to some kind of hex string at the receiving function:

#include <GuiConstants.au3>
#include <Misc.au3>

If _Singleton("test", 1) = 0 Then
    $hWnd = WinGetHandle("SendMessage Test")
    _SendMessage($hWnd, $WM_USER, $CmdLineRaw, -1, 0, "str", "int")
    Exit
EndIf

Opt("GuiOnEventMode", 1)

Global $Gui, $Label, $hWnd_sav, $Msg_sav, $wParam_sav, $lParam_sav, $MsgFlag = False

$Gui = GUICreate("SendMessage Test", 400, 200)
GUISetOnEvent($GUI_EVENT_CLOSE, "_Quit")
$Label = GUICtrlCreateLabel("<no message>", 10, 10, 380, 180)

GUIRegisterMsg($WM_USER, "WM_USER")

GUISetState()

While 1
    If $MsgFlag Then
        $sMsg = "WM_USER Message:" & @CRLF & _
                @TAB & "$hWnd = " & $hWnd_sav & @CRLF & _
                @TAB & "$Msg = " & $Msg_sav & @CRLF & _
                @TAB & "$wParam = " & $wParam_sav & @CRLF & _
                @TAB & "$lParam = " & $lParam_sav
        GUICtrlSetData($Label, $sMsg)
        $MsgFlag = False
    EndIf
    Sleep(10)
WEnd

Func WM_USER($hWnd, $Msg, $wParam, $lParam)
    $hWnd_sav = $hWnd
    $Msg_sav = $Msg
    $wParam_sav = $wParam
    $lParam_sav = $lParam
    $MsgFlag = True
EndFunc   ;==>WM_USER

Func _Quit()
    Exit
EndFunc   ;==>_Quit

:)

Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
Link to comment
Share on other sites

Thanks, but as you say, it didn't make changes..

For now i am using temporary file (before sending i save $CmdLineRaw to file, and after calling the registered function it reads the file and delete it) - not very practical :).

 

Spoiler

Using OS: Win 7 Professional, Using AutoIt Ver(s): 3.3.6.1 / 3.3.8.1

AutoIt_Rus_Community.png AutoIt Russian Community

My Work...

Spoiler

AutoIt_Icon_small.pngProjects: ATT - Application Translate Tool {new}| BlockIt - Block files & folders {new}| SIP - Selected Image Preview {new}| SISCABMAN - SciTE Abbreviations Manager {new}| AutoIt Path Switcher | AutoIt Menu for Opera! | YouTube Download Center! | Desktop Icons Restorator | Math Tasks | KeyBoard & Mouse Cleaner | CaptureIt - Capture Images Utility | CheckFileSize Program

AutoIt_Icon_small.pngUDFs: OnAutoItErrorRegister - Handle AutoIt critical errors {new}| AutoIt Syntax Highlight {new}| Opera Library! | Winamp Library | GetFolderToMenu | Custom_InputBox()! | _FileRun UDF | _CheckInput() UDF | _GUIInputSetOnlyNumbers() UDF | _FileGetValidName() UDF | _GUICtrlCreateRadioCBox UDF | _GuiCreateGrid() | _PathSplitByRegExp() | _GUICtrlListView_MoveItems - UDF | GUICtrlSetOnHover_UDF! | _ControlTab UDF! | _MouseSetOnEvent() UDF! | _ProcessListEx - UDF | GUICtrl_SetResizing - UDF! | Mod. for _IniString UDFs | _StringStripChars UDF | _ColorIsDarkShade UDF | _ColorConvertValue UDF | _GUICtrlTab_CoverBackground | CUI_App_UDF | _IncludeScripts UDF | _AutoIt3ExecuteCode | _DragList UDF | Mod. for _ListView_Progress | _ListView_SysLink | _GenerateRandomNumbers | _BlockInputEx | _IsPressedEx | OnAutoItExit Handler | _GUICtrlCreateTFLabel UDF | WinControlSetEvent UDF | Mod. for _DirGetSizeEx UDF
 
AutoIt_Icon_small.pngExamples: 
ScreenSaver Demo - Matrix included | Gui Drag Without pause the script | _WinAttach()! | Turn Off/On Monitor | ComboBox Handler Example | Mod. for "Thinking Box" | Cool "About" Box | TasksBar Imitation Demo

Like the Projects/UDFs/Examples? Please rate the topic (up-right corner of the post header: Rating AutoIt_Rating.gif)

* === My topics === *

==================================================
My_Userbar.gif
==================================================

 

 

 

AutoIt is simple, subtle, elegant. © AutoIt Team

Link to comment
Share on other sites

  • Developers

From the Helpfile:

In addition to $CmdLine there is a variable called $CmdLineRaw that contains the entire command line unsplit, so for the above example:

$CmdLineRaw equals... myscript.au3 param1 "this is another param"

If the script was compiled it would have been run like this:

myscript.exe param1 "this is another param"

$CmdLineRaw equals... param1 "this is another param"

Note that $CmdLineRaw just return the parameters.

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

From the Helpfile:

JdeB,

The helpfile for _SendMessage() implies you can type the parameters passed, and therefore pass a string. But the helpfile for GuiRegisterMsg() looks like it can only pass string converted hex?

Is there a way to receive a string in the function called by message in GuiRegisterMsg()?

:)

Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
Link to comment
Share on other sites

  • Developers

JdeB,

The helpfile for _SendMessage() implies you can type the parameters passed, and therefore pass a string. But the helpfile for GuiRegisterMsg() looks like it can only pass string converted hex?

Is there a way to receive a string in the function called by message in GuiRegisterMsg()?

:)

Think you need to use the WM_COPYDATA for that. Posted some example yesterday that uses WM_COPYDATA to receive string information from SciTE's Director interface using GuiRegisterMsg() and somebody posted something in the Examples to interchange information beteen script using it .....

Jos

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

It's not as fashionable as RegisterMsg, but maybe you could do something like this:

#include <Misc.au3>

If _Singleton("test", 1) = 0 Then
    ControlSetText("SendMessage Test", "", "[CLASS:Static; INSTANCE:1]", $CmdLineRaw)
    Exit
EndIf

$Gui = GuiCreate("SendMessage Test")
$ingoing = GUICtrlCreateLabel("",0,0,1,1)

GUISetState()

$str = ""

While 1
    $Msg = GUIGetMsg()
    Switch $Msg
        Case -3
            Exit
    EndSwitch
    $strnew = GUICtrlRead($ingoing)
    If $str <> $strnew Then
        MsgBox(0,'',$strnew)
        $str = $strnew
    EndIf
WEnd
Edited by Siao

"be smart, drink your wine"

Link to comment
Share on other sites

Good idea Siao! Thanks!

Here is how it can be done for me:

#include <GuiConstants.au3>
#include <Misc.au3>

If _Singleton("test", 1) = 0 Then
    $hWnd = WinGetHandle("SendMessage Test")
    ControlSetText($hWnd, "", "Static1", $CmdLineRaw)
    _SendMessage($hWnd, $WM_USER)
    Exit
EndIf

$Gui = GuiCreate("SendMessage Test")

$DummyLabel = GUICtrlCreateLabel("test", -100, -100)

GUIRegisterMsg($WM_USER, "WM_USER")

GUISetState()

While 1
    $Msg = GUIGetMsg()
    Switch $Msg
        Case -3
            Exit
    EndSwitch
WEnd

Func WM_USER($hWnd, $Msg, $wParam, $lParam)
    MsgBox(0, "", GUICtrlRead($DummyLabel))
    GUICtrlSetData($DummyLabel, "")
EndFunc

 

Spoiler

Using OS: Win 7 Professional, Using AutoIt Ver(s): 3.3.6.1 / 3.3.8.1

AutoIt_Rus_Community.png AutoIt Russian Community

My Work...

Spoiler

AutoIt_Icon_small.pngProjects: ATT - Application Translate Tool {new}| BlockIt - Block files & folders {new}| SIP - Selected Image Preview {new}| SISCABMAN - SciTE Abbreviations Manager {new}| AutoIt Path Switcher | AutoIt Menu for Opera! | YouTube Download Center! | Desktop Icons Restorator | Math Tasks | KeyBoard & Mouse Cleaner | CaptureIt - Capture Images Utility | CheckFileSize Program

AutoIt_Icon_small.pngUDFs: OnAutoItErrorRegister - Handle AutoIt critical errors {new}| AutoIt Syntax Highlight {new}| Opera Library! | Winamp Library | GetFolderToMenu | Custom_InputBox()! | _FileRun UDF | _CheckInput() UDF | _GUIInputSetOnlyNumbers() UDF | _FileGetValidName() UDF | _GUICtrlCreateRadioCBox UDF | _GuiCreateGrid() | _PathSplitByRegExp() | _GUICtrlListView_MoveItems - UDF | GUICtrlSetOnHover_UDF! | _ControlTab UDF! | _MouseSetOnEvent() UDF! | _ProcessListEx - UDF | GUICtrl_SetResizing - UDF! | Mod. for _IniString UDFs | _StringStripChars UDF | _ColorIsDarkShade UDF | _ColorConvertValue UDF | _GUICtrlTab_CoverBackground | CUI_App_UDF | _IncludeScripts UDF | _AutoIt3ExecuteCode | _DragList UDF | Mod. for _ListView_Progress | _ListView_SysLink | _GenerateRandomNumbers | _BlockInputEx | _IsPressedEx | OnAutoItExit Handler | _GUICtrlCreateTFLabel UDF | WinControlSetEvent UDF | Mod. for _DirGetSizeEx UDF
 
AutoIt_Icon_small.pngExamples: 
ScreenSaver Demo - Matrix included | Gui Drag Without pause the script | _WinAttach()! | Turn Off/On Monitor | ComboBox Handler Example | Mod. for "Thinking Box" | Cool "About" Box | TasksBar Imitation Demo

Like the Projects/UDFs/Examples? Please rate the topic (up-right corner of the post header: Rating AutoIt_Rating.gif)

* === My topics === *

==================================================
My_Userbar.gif
==================================================

 

 

 

AutoIt is simple, subtle, elegant. © AutoIt Team

Link to comment
Share on other sites

:) , Thanks to JdeB for direction and to JohnBailey in this thread for showing examples!

Here is the final solution for me:

#include <Misc.au3>
#include <GUIConstants.au3>

Global Const $WM_COPYDATA = 0x4A
Global Const $WM_CLOSE = 0x10

If _Singleton("test", 1) = 0 Then
    $hWnd = WinGetHandle("SendMessage Test")
    _AU3COM_SendData($CmdLineRaw, $hWnd)
    Exit
EndIf

$Gui = GUICreate("SendMessage Test")

GUIRegisterMsg($WM_COPYDATA, "_GUIRegisterMsgProc")
GUIRegisterMsg($WM_CLOSE, "_GUIRegisterMsgProc")

GUISetState()

While 1
    $Msg = GUIGetMsg()
    Switch $Msg
        Case -3
            Exit
    EndSwitch
WEnd

Func _GUIRegisterMsgProc($hWnd, $MsgID, $WParam, $LParam)
    If $MsgID = $WM_COPYDATA Then
        Local $vs_msg = _AU3COM_RecvData($LParam)
        Local $MSGRECVD = DllStructGetData($vs_msg, 1)
        ;Here is go whatever we need to do with the recieved string ($MSGRECVD)
        MsgBox(0, "", $MSGRECVD)
    ElseIf $MsgID = $WM_CLOSE Then
        Exit
    EndIf
EndFunc

Func _AU3COM_SendData($InfoToSend, $RecvWinHandle)
    Local $StructDef_COPYDATA = "dword var1;dword var2;ptr var3"
    Local $CDString = DllStructCreate("char var1[256];char var2[256]") ;the array to hold the string we are sending
    
    DllStructSetData($CDString, 1, $InfoToSend)
    Local $pCDString = DllStructGetPtr($CDString) ;the pointer to the string
    Local $vs_cds = DllStructCreate($StructDef_COPYDATA);create the message struct
    DllStructSetData($vs_cds, "var1", 0) ;0 here indicates to the receiving program that we are sending a string
    DllStructSetData($vs_cds, "var2", String(StringLen($InfoToSend) + 1));tell the receiver the length of the string
    DllStructSetData($vs_cds, "var3", $pCDString) ;the pointer to the string
    Local $pStruct = DllStructGetPtr($vs_cds)
    _SendMessage($RecvWinHandle, $WM_COPYDATA, 0, $pStruct)
    
    $vs_cds = 0 ;free the struct
    $CDString = 0 ;free the struct
    
    Return 1
EndFunc

Func _AU3COM_RecvData($COM_LParam)
    ; $COM_LParam = Poiter to a COPYDATA Struct
    Local $STRUCTDEF_AU3MESSAGE = "char var1[256];int"
    Local $StructDef_COPYDATA = "dword var1;dword var2;ptr var3"
    Local $vs_cds = DllStructCreate($StructDef_COPYDATA, $COM_LParam)
    ; Member No. 3 of COPYDATA Struct (PVOID lpData;) = Pointer to Costum Struct
    Local $vs_msg = DllStructCreate($STRUCTDEF_AU3MESSAGE, DllStructGetData($vs_cds, 3))
    Return $vs_msg
EndFunc

Thanks to all! the problem is solved! (imho, we need such feature on the forum -> you click the Options of the topic, and there is Item "Mark as Solved", and to the start of topic title added something like this: [sOLVED] <Original Title>... Then other members will see that this is no longer a "Hot discusions" topic :) - i have seen this on some forums).

Edited by MsCreatoR

 

Spoiler

Using OS: Win 7 Professional, Using AutoIt Ver(s): 3.3.6.1 / 3.3.8.1

AutoIt_Rus_Community.png AutoIt Russian Community

My Work...

Spoiler

AutoIt_Icon_small.pngProjects: ATT - Application Translate Tool {new}| BlockIt - Block files & folders {new}| SIP - Selected Image Preview {new}| SISCABMAN - SciTE Abbreviations Manager {new}| AutoIt Path Switcher | AutoIt Menu for Opera! | YouTube Download Center! | Desktop Icons Restorator | Math Tasks | KeyBoard & Mouse Cleaner | CaptureIt - Capture Images Utility | CheckFileSize Program

AutoIt_Icon_small.pngUDFs: OnAutoItErrorRegister - Handle AutoIt critical errors {new}| AutoIt Syntax Highlight {new}| Opera Library! | Winamp Library | GetFolderToMenu | Custom_InputBox()! | _FileRun UDF | _CheckInput() UDF | _GUIInputSetOnlyNumbers() UDF | _FileGetValidName() UDF | _GUICtrlCreateRadioCBox UDF | _GuiCreateGrid() | _PathSplitByRegExp() | _GUICtrlListView_MoveItems - UDF | GUICtrlSetOnHover_UDF! | _ControlTab UDF! | _MouseSetOnEvent() UDF! | _ProcessListEx - UDF | GUICtrl_SetResizing - UDF! | Mod. for _IniString UDFs | _StringStripChars UDF | _ColorIsDarkShade UDF | _ColorConvertValue UDF | _GUICtrlTab_CoverBackground | CUI_App_UDF | _IncludeScripts UDF | _AutoIt3ExecuteCode | _DragList UDF | Mod. for _ListView_Progress | _ListView_SysLink | _GenerateRandomNumbers | _BlockInputEx | _IsPressedEx | OnAutoItExit Handler | _GUICtrlCreateTFLabel UDF | WinControlSetEvent UDF | Mod. for _DirGetSizeEx UDF
 
AutoIt_Icon_small.pngExamples: 
ScreenSaver Demo - Matrix included | Gui Drag Without pause the script | _WinAttach()! | Turn Off/On Monitor | ComboBox Handler Example | Mod. for "Thinking Box" | Cool "About" Box | TasksBar Imitation Demo

Like the Projects/UDFs/Examples? Please rate the topic (up-right corner of the post header: Rating AutoIt_Rating.gif)

* === My topics === *

==================================================
My_Userbar.gif
==================================================

 

 

 

AutoIt is simple, subtle, elegant. © AutoIt Team

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
 Share

  • Recently Browsing   0 members

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