in C#

SendMessage – 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>

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);

Leave a Reply


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

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

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


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

  5. Hi all!

    I want to all of you know, World is mine, and yoursite good


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

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

  8. Hello
    I am using combobox.can any body please explain in how to send message using combo in C#

  9. I am using combobox.can any body please explain in how to send message using combo in C#

    Have you tried this code?
    SendMessage(combobox1.Handle, WM_LBUTTONDOWN, IntPtr.Zero, IntPtr.Zero);

    Note: combobox1 is the name of your combobox.

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

  11. C languages are very intersting& its very simple

  12. hi my name is ravi
    i want to knw that how tond an SMS on any mobile no that we want by using the C# language
    IF anyone has the solution please mail me on my gmail account