4 Jul, 2006
C#
//DllImport using System.Runtime.InteropServices;
//Left Button - Mouse Down
public const int WM_LBUTTONDOWN = 0x0201;
//Left Button - Mouse Up
public const int WM_LBUTTONUP = 0x0202;
/// <summary>
/// The SendMessage function sends the specified message to a window or windows. The function calls the window procedure for the specified window and does not return until the window procedure has processed the message. The PostMessage function, in contrast, posts a message to a thread’s message queue and returns immediately.
/// </summary>
///<param name="hWnd"></param>Identifies the window whose window procedure will receive the message. If this parameter is HWND_BROADCAST, the message is sent to all top-level windows in the system, including disabled or invisible unowned windows, overlapped windows, and pop-up windows; but the message is not sent to child windows.
///<param name="wMsg"></param>Specifies the message to be sent.
///<param name="wParam"></param>Specifies additional message-specific information.
///<param name="lParam"></param>Specifies additional message-specific information. ///<returns>The return value specifies the result of the message processing and depends on the message sent. </returns>
[DllImport("user32.dll",CharSet=CharSet.Auto)]
private static extern int SendMessage(IntPtr hWnd, int wMsg, IntPtr wParam, IntPtr lParam);
long lngResult = SendMessage(btn1.Handle, WM_LBUTTONDOWN, IntPtr.Zero, IntPtr.Zero);
lngResult = SendMessage(btn1.Handle, WM_LBUTTONUP, IntPtr.Zero, IntPtr.Zero);
Communication between classes in C# at Neonlabs Innovations said
am August 5 2006 @ 11:59 pm
[...] This piece of code would allow me to use messaging just like I did in C++. I didn’t even test this solution. I found full fledge solution using the Win32 API like Michael Sync’s version, which seemed too much for what I wanted. It seemed un-elegant and even lazy to try to use another language’s perspective of class messaging. So I went on and searched for a more C#’ed way to communicate between two classes. [...]
SEan Strand said
am November 28 2006 @ 4:57 pm
Hi-Ho, I am SeanS, from the AJX Course.
Can U Please send me / tell me How I can down load or even link into the ZenGardens master.html
so that I am able to complete the homework ?
At present I am running round in circles.
All regards SEanS
seanjstrand@gmail.com
Michael Sync said
am November 29 2006 @ 1:08 pm
ZenGardens master.html?
maybe. you can download from CSS Zengarden
just open any page that you wanna get CSS. Click to “View Source”. then you will see the CSS link in source..
I think, you dont need to use the CSS file of CSS Zengarden for Homework #11.
you can use your owned css file since Sangsing is just checking how we understand about CSS..
Waheed said
am December 29 2006 @ 12:39 am
Very nice piece of code and explains very well, but this code calls the button down and button up events of whatever windows handle is passed, is there any way to call th click event, I know this should form a click but it doesnt.
Thanks.
Michael Sync said
am December 30 2006 @ 3:12 pm
Yeah. click event should fire when you sent a msg to button… I will chk in details on coming monday.. and will let you know…
can u show me the code that you hav done so far? maybe. i can point out some points in ur code….
aniway, i will definetely let u know on coming monday..
GramBorder said
am March 20 2007 @ 1:26 am
Hi all!
I want to all of you know, World is mine, and yoursite good
Bye
Michael Sync said
am March 20 2007 @ 2:14 am
>>World is mine,
Oh. really..
>>and yoursite good
Thanks..
anatol said
am May 31 2007 @ 5:10 pm
Nise site!
kazim said
am June 28 2007 @ 9:28 am
Above Send message code is fine as i have written it in the thread and want to send message whenever some data is receieved
How can i make equivlant of C++ in C#
C++ code is given:
ON_MESSAGE(Msg_UpdateM, OnUpdateM)
Msg_updateM is my custom Message
OnUpdate is my function to update some value taken from thread and want to write in User interface
Thanks in advance
Kazim
Michael Sync said
am September 21 2007 @ 1:26 am
Thanks. Dopler.
Kazim, I’m not very familiar with C++ (I know only C++ 3.0 dos version that I learnt at collage.) I will find out about ON_MESSAGE and will let u know..
irfan said
am November 26 2007 @ 11:08 pm
Hello
I am using combobox.can any body please explain in how to send message using combo in C#
Michael Sync said
am November 26 2007 @ 11:57 pm
Have you tried this code?
SendMessage(combobox1.Handle, WM_LBUTTONDOWN, IntPtr.Zero, IntPtr.Zero);
Note: combobox1 is the name of your combobox.
rajan said
am April 19 2008 @ 5:21 am
i want to know how to send a message through c#
Michael Sync said
am April 19 2008 @ 6:00 am
>>>>i want to know how to send a message through c#
hum? I already wrote in this post, isn’t it?
S. Geier said
am April 26 2008 @ 6:47 am
Hi,
this is some really spiffy code fragment but I am wondering how to send a Keystroke like “Shift + B” to another application.
I am aware of the fact that 3 messages have to be send WM_KEYDOWN, WM_CHAR and finally WM_KEYUP to make the application recognize a keystroke… the thing is I dont know how to implement all the virtual codes like ing VK_F5 = 0×74, int VK_E = 0×45 into the SendMessage methode ;(
I have succeeded in sending keys by using C#’s Sendkeys.Send() methode but its kinda limited in serveral ways. For example you cannot broadcast NUMPAD keys because its just not supported (correct me if I am wrong).
Thanks for your help