Jump to content

_SendMessage() to GUIGetMsg()


HeinMueck
 Share

Recommended Posts

Hi Guys!

I am looking for a way to send a user defined message to an AutoIt GUI with _SendMessage that is recognized by GUIGetMsg()?

I guess it is only setting the correct parameters for _SendMessage, but I could not find any docs or examples telling me what to put in. I see that there are some examples using GUIRegisterMsg(), but that is not what I had on my mind ;-)

Any hints?

Cheers,

Hein

Link to comment
Share on other sites

Hi Guys!

I am looking for a way to send a user defined message to an AutoIt GUI with _SendMessage that is recognized by GUIGetMsg()?

I guess it is only setting the correct parameters for _SendMessage, but I could not find any docs or examples telling me what to put in. I see that there are some examples using GUIRegisterMsg(), but that is not what I had on my mind ;-)

Any hints?

Cheers,

Hein

So you want to open a door by turning a knob but you don't want the door to have a knob on it. ;)

Maybe you could explain a bit more? What is wrong with using GuiRegisterMsg or is that you just don't understand it?

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.
Link to comment
Share on other sites

So you want to open a door by turning a knob but you don't want the door to have a knob on it. ;)

Maybe you could explain a bit more? What is wrong with using GuiRegisterMsg or is that you just don't understand it?

Well, the situation is the following: I have a Gui that spawns a bunch of processes through an ActiveX component. Some of them start other processes and return. So the started process might end before the processing itself has finished. But I have the chance to start a script at the end of processing. Now I would like this script to send a message to the GUI when the processing is done.

As a rough example:

Global Const $MY_MESSAGE        = 0x99999

GUICreate("Control Program", 800, 600)

GUISetState(@SW_SHOW)
    
While 1
    $msg = GUIGetMsg()

    If $msg = $MY_MESSAGE Then ExitLoop

WEnd
GUIDelete()

So if I could use _SendMessage() to send $MY_MESSAGE to the GUI, it would work without global vars.

The question is how you need to set the params for _SendMessage() that GUIGetMsg() recognizes it.

Cheers,

Hein

Link to comment
Share on other sites

HeinMueck

Welcome! ;)

Don't completely understand your question, this?

#include <GuiConstantsEx.au3>
#include <WindowsConstants.au3>
#include <WinAPI.au3>

$hGUI = GUICreate("Test", 200, 100)

$FontButton = GUICtrlCreateButton("Paint", 60, 40, 75, 23)

GUIRegisterMsg($WM_PAINT, "WM_PAINT")

GUISetState()

While 1
    $msg = GUIGetMsg()
    Switch $msg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $FontButton
            _SendMessage($hGUI, $WM_PAINT, 0, 0)
    EndSwitch
WEnd

Func WM_PAINT($hWnd, $Msg, $wParam, $lParam)
    
    ConsoleWrite("!> Window painted" & @LF)
    
    Return $GUI_RUNDEFMSG
EndFunc
Link to comment
Share on other sites

Hi Rasim

thanks, yes, kind of. But I was trying to figure out if there is a chance to process the _SendMessage directly with GUIGetMsg(). So without the need to register a separate message handler.

There must be a way to place the message in the message queue in a way that GUIGetMsg can dispatch it ... maybe even using the wparam and lparam by setting the advanced flag to 1 ...

Would be so cool ;)

Another thing one would need to respect is the range of numbers that are created by the GUICtrlCreate... functions. To define the custum event one should choose a number that is usually not received by GUIGetMsg().

Cheers,

Hein

Link to comment
Share on other sites

Hi Rasim

thanks, yes, kind of. But I was trying to figure out if there is a chance to process the _SendMessage directly with GUIGetMsg(). So without the need to register a separate message handler.

There must be a way to place the message in the message queue in a way that GUIGetMsg can dispatch it ... maybe even using the wparam and lparam by setting the advanced flag to 1 ...

Would be so cool ;)

Another thing one would need to respect is the range of numbers that are created by the GUICtrlCreate... functions. To define the custum event one should choose a number that is usually not received by GUIGetMsg().

Cheers,

Hein

You could forget about _SendMessage and do something like this

#include <GuiConstantsEx.au3>
Global $MY_MESSAGE

GUICreate("Control Program", 800, 600)
$MY_MESSAGE = GUICtrlCreateDummy()
GUISetState(@SW_SHOW)

While 1
    $msg = GUIGetMsg()
    If $msg = $GUI_EVENT_CLOSE Then
        GUICtrlSendToDummy($MY_MESSAGE, 0x99999)
    EndIf
    If $msg = $MY_MESSAGE Then
        If GUICtrlRead($MY_MESSAGE) = 0x99999 Then
            ExitLoop
        EndIf
    EndIf

WEnd
GUIDelete()

The statement GUICtrlSendToDummy($MY_MESSAGE, 0x99999) could be placed anywhere in the script you like.

It's a thought.

Link to comment
Share on other sites

Hi Malkey,

using GUICtrlCreateDummy() is also an idea one could follow. But then the sending script, wich is independ from the first, the waiting script, would need to know at least the handle of the dummy control. And I could not find a way to get it, for instance by using ControlGetHandle().

Cheers,

Hein

Link to comment
Share on other sites

Just make an other function, which forwards the Message to the dummy ;)

#include <GuiConstantsEx.au3>
#include <WindowsConstants.au3>
#include <WinAPI.au3>

$WM_MYMSG = $WM_USER+193

$hGUI = GUICreate("Test", 200, 100)

$SendMSGButton = GUICtrlCreateButton("SendMsg", 60, 40, 75, 23)

$MYMSG_Dummy = GUICtrlCreateDummy()
GUIRegisterMsg($WM_MYMSG, "WM_MYMSG")

GUISetState()

While 1
    $msg = GUIGetMsg()
    Switch $msg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $MYMSG_Dummy ; Receiving
            MsgBox(0, 'Received', "The value received with WM_MYMSG: " & GUICtrlRead($MYMSG_Dummy))
        Case $SendMSGButton ; Sending
            _SendMessage($hGUI, $WM_MYMSG, 1234, 0)
    EndSwitch
WEnd

;Func to formward Message to dummy
Func WM_MYMSG($hWnd, $Msg, $wParam, $lParam)
    GUICtrlSendToDummy($MYMSG_Dummy,$wParam)
    Return 1
EndFunc

*GERMAN* [note: you are not allowed to remove author / modified info from my UDFs]My UDFs:[_SetImageBinaryToCtrl] [_TaskDialog] [AutoItObject] [Animated GIF (GDI+)] [ClipPut for Image] [FreeImage] [GDI32 UDFs] [GDIPlus Progressbar] [Hotkey-Selector] [Multiline Inputbox] [MySQL without ODBC] [RichEdit UDFs] [SpeechAPI Example] [WinHTTP]UDFs included in AutoIt: FTP_Ex (as FTPEx), _WinAPI_SetLayeredWindowAttributes

Link to comment
Share on other sites

  • Moderators

You might try:

GetCurrentThreadId

GetWindowThreadProcessId

AttachThreadInput (Set to true)

PostMessage

AttachThreadInput (Set to false)

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.

Link to comment
Share on other sites

Hmm, yes,

things might work that way. If you have a global dummy, then you can shoot something from an external process from behind through the breast into the eye ;)) But handling all messages in the one and only loop directly would be the best way, I think.

I'm sure GUIGetMsg() get's the message from the message queue where _SendMessage would also put it's data. It just reacts on specially crafted messages. Perhaps I can try to use the GetMessage API call to get one of those and inspect it. If I can do that, I will post some info here.

Let's see how far we can get.

Cheers,

Hein

Link to comment
Share on other sites

What you wanna do is use _WinAPI_RegisterWindowMessage("string") to register a message with each process that will use it. If they use the same string, the same message value is returned. Then use GuiRegisterMsg() in the receiving process to receive the message, and _SendMessage() in the sending app.

Link to comment
Share on other sites

What you wanna do is use _WinAPI_RegisterWindowMessage("string") to register a message with each process that will use it. If they use the same string, the same message value is returned. Then use GuiRegisterMsg() in the receiving process to receive the message, and _SendMessage() in the sending app.

Well, yes, this was said before. And in GuiRegisterMsg() I can open a message box saying "Received it" ;)

But why can't I just put something on the Messagequeue that is read by GuiGetMsg? Does AutoIt have it's own? Or are controls posting to the windows queue with _WinAPI_PostMessage and GUIGetMsg uses _WinAPI_GetMessage to read them?

If so, I can place a message in the queue with _SendMessage that would be read by GUIGetMsg() - and it would be the way to do this.

Cheers,

Hein

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...