using the 'sendmessage' command - tutorial

Help each other out

using the 'sendmessage' command - tutorial

Postby jrg on Mon Jan 26, 2004 6:32 pm

can someone post a little bit on how to use this and what all the parameters are and how they are used.

I understand the basic concept in that you are passing a command to a window or program, but that is about it.
jrg
 
Posts: 28
Joined: Thu Nov 06, 2003 8:10 pm

Postby wmandra on Mon Jan 26, 2004 7:59 pm

jrg,

The sendmessage function works just like the Win32 SendMessage API call. The messages that are sent are Windows Messages, an example is WM_CLOSE (&H10), sending this message to a window will cause it to close. There are probably 50 or so standard windows messages that can be sent to a running application you can activate a window, simulate a key event, even scroll a window or listbox. Some programs also implement custom windows messages through WM_USER (1024). For example, a couple of programs that I am working on right now act almost like Xlobby plugins through the use of the sendmessage command.
If you have not done any programming, especially win32 API programming, most of the information you will find on send message will probably not help you much. However, I will try and to my best to explain it a little more in detail.

Ok, in order to send a message to a window you have to know it's window handle, hwnd for short. A windows handle is a unique number that gets assigned to every window in the system and changes everytime a program runs. So, to find a hwnd we need 2 pieces of information: The window class name and the Window caption. Of course, window caption is usually fairly easy to get, just look at the window, but the class name requires either the person who wrote the program to tell you, or a program like MS Spy++ (included with MS Visual Studio).

Now that you have the Window Caption and Class Name you can decide what message you want to send. Check out http://msdn.microsoft.com/library/default.asp?url=/library/en-us/winui/WinUI/WindowsUserInterface/Windowing/Windows/WindowReference/WindowMessages/WM_CLOSE.asp for a complete listing (look under notifications on the menu on the left).

Each message can take to different parameters wParam and lParam. I really can't go into too much detail on these because they are specific for each different windows message. An example I can give you is how I use these parameters for a command in my WMP9 plugin. A good example would be the Fast Forward command:
sendmessage:WMP9player:ThunderRT6FormDC:1024:103:5
As you can see the first two parameters are the Window Caption and Class Name. Xlobby uses these 2 parameters to find the hwnd of the window so it can send the message. The third parameter, 1024, is the WM_USER message. Then you have wParam (103) and lParam(5). When my program recieves this message it identifies it as a WM_USER message and looks at wParam to see which command it was sent. Command 103 is fast forward(104 rewind, etc.) Then it looks at lParam (5), this tells the program to skip ahead 5 seconds. So if I sent the message with an lParam of 2 it would fast forward 2 seconds.

I know all of this seems very long, and probably a bit confusing, but it can pay off in the end. You can also do a google search for the win32 API sendmessage command, the parameters are a little different (it needs an hwnd instead of window caption & window class), but it should give you a better idea on how to use windows messaging.
wmandra
 
Posts: 43
Joined: Sun Jan 18, 2004 5:59 pm
Location: Bloomfield, NJ

Postby Arthur on Mon Jan 26, 2004 9:33 pm

:D A very interesting post wmandra. The whole sendmessage thing is much clearer to me now! Good link too. Thank you.

Arthur
Arthur
 
Posts: 207
Joined: Thu Dec 25, 2003 8:52 am
Location: The Hague, The Netherlands

Postby stevenhanna6 on Mon Jan 26, 2004 10:47 pm

little preview of the new sendmessage command :)

Image
stevenhanna6
 
Posts: 904
Joined: Tue Feb 18, 2003 10:39 am
Location: Ontario, Canada

Postby jrg on Tue Jan 27, 2004 4:31 pm

wmandra, thanks!!!!!!!!!

The last programming i have done was assembly language for the old motorola 8086. Slightly better than punch cards :oops:.

Where do you find out what params do what? i.e. how did you know that 105 was the command for fast forward in wmp9?

If it was the Spy program, then i will definitely have to check it out.

I am wanting to integrate Beyond TV into Xlobby.
jrg
 
Posts: 28
Joined: Thu Nov 06, 2003 8:10 pm

Postby chadwolcott on Tue Jan 27, 2004 6:14 pm

I don't believe that BeyondTV can accept sendMessage commands. I think you have to use keyboard commands and create girder events.
chadwolcott
 
Posts: 107
Joined: Fri Sep 05, 2003 2:34 pm
Location: Boston, MA

Postby wmandra on Tue Jan 27, 2004 9:18 pm

I'm not real familiar with Beyond TV so I can't really say if it can respond to sendmessage commands for anything other than stanard window messages. I tried the demo out, but didn't really like it. Instead, I decided to use GotTV. Since it was written to be a plug-in for myHTPC it was fairly easy to write a program to make it work with Xlobby. I still waiting to get some more information on the Xlobby EPG so I can finish it up.

As far as your other question, about how I found sendmessage commands for WMP9, I think you kind of misunderstood. I had to write a new program that uses the WMP9 activeX control, and wrote the ability to respond to sendmessage commands into the program.
It is possible, to use a program like Spy++ to figure out what the message numbers are, but it is extremely involved. In your case I think using girder is probably your best option. Or if you could wait a little bit, I will have my Xlobby - GotTV interface program finished in a week or two (depends on the Xlobby EPG stuff)

Bill
wmandra
 
Posts: 43
Joined: Sun Jan 18, 2004 5:59 pm
Location: Bloomfield, NJ

Postby Arthur on Fri Mar 05, 2004 8:48 pm

Can it be that the send message command isn't functioning in 40exp5?
Thanks to wmandra post I thought I understood but nothing is happening :(
I use the following parameters (I use the image from steven's post):
Image
Class name: #32770 (found this number with Girder as well as with windows spy, which, by the way is easy to recover the class name. Seems to work a bit like spy++, but I've never used that program. The free download link is: http://www.windows-spy.com/download)
Window name: TerraTec ActiveRadio (I'm a bit worried about the space between the two words, didn't produce any problem in Girder though)
Message: WM_CLOSE
Also tried WM_DESTROY, but no reaction whatsoever.
Can anyone give me a hint?

Arthur
Arthur
 
Posts: 207
Joined: Thu Dec 25, 2003 8:52 am
Location: The Hague, The Netherlands

Postby stevenhanna6 on Sat Mar 06, 2004 6:02 pm

I'm pretty sure I didn't hard code the variables for WM_CLOSE and WM_DESTROY....you'll have to use their integer values.

WM_CLOSE = 16
WM_DESTROY = 2

try that out and tell me if it works.
stevenhanna6
 
Posts: 904
Joined: Tue Feb 18, 2003 10:39 am
Location: Ontario, Canada

Postby stevenhanna6 on Sat Mar 06, 2004 6:58 pm

Arthur, you were right I looked into my sendmessage code and it was messed up....you'll have to wait until the next release to try it.

I've also added support to the standard way of declaring a message like

WM_NULL
WM_CREATE
WM_DESTROY
WM_MOVE
WM_SIZE
etc..

you get the idea....so you DONT have to use integers in the next release.
stevenhanna6
 
Posts: 904
Joined: Tue Feb 18, 2003 10:39 am
Location: Ontario, Canada

Postby Arthur on Tue Mar 09, 2004 10:18 pm

:lol: :lol: It works in 40exp6 !
Now I can open and close an application (my internal radiocard) by pushing a button.
I can't show a window. So each time I leave the screen I will have to close the application, because I can't bring it back to front on reentering the window.
When I used girder, I wasn't able to bring the window to front either.
Maybe XLobby likes to stay in front?
Anyone a suggestion?

Arthur
Arthur
 
Posts: 207
Joined: Thu Dec 25, 2003 8:52 am
Location: The Hague, The Netherlands