Using system;
Using system. Collections. Generic;
Using system. componentmodel;
Using system. Data;
Using system. drawing;
Using system. text;
Using system. Windows. forms;
Using system. runtime. interopservices;
Namespace windowsapplication4
{
Public partial class form1: Form
{
Public form1 ()
{
Initializecomponent ();
}
Const int wm_lbutton = 0x201; // defines the left-click message of the mouse
Const int wm_rbuttondown = 0x204; // right-click to define
Const int wm_keydown = 0x100;
Public const int user = 0x0400; // is a user message defined by windows.
[Dllimport ("user32.dll", entrypoint = "sendmessage")]
Private Static extern int sendmessage (
Int hwnd, // handle to destination window
Int MSG, // message
Int wparam, // first Message Parameter
Int lparam // second Message Parameter
);
Protected override void defwndproc (Ref system. Windows. Forms. Message m)
{
String message = "";
Switch (M. msg)
{
Case wm_lbutton:
/// The format function of string and cstring in MFC is used differently.
Message = string. Format ("Message received! Parameter: {0}, {1} ", M. wparam, M. lparam );
MessageBox. Show (Message); // display a message box
Break;
Case 0:
Message = string. Format ("receive the message of clicking the mouse! Parameter: {0}, {1} ", M. wparam, M. lparam );
MessageBox. Show (Message );
Break;
Case wm_rbuttondown:
MessageBox. Show ("right-click! "," Prompt ", messageboxbuttons. OK, messageboxicon. information );
Break;
Case wm_keydown:
MessageBox. Show ("you pressed the keyboard! "," Prompt ", messageboxbuttons. OK, messageboxicon. information );
Break;
Default:
Base. defwndproc (ref m); // call the base class function to process non-custom messages.
Break;
}
}
Private void button#click (Object sender, eventargs E)
{
System. Windows. Forms. Message M = new message ();
M. MSG = 0;
M. lparam = (intptr) 10;
M. wparam = (intptr) 11;
Sendmessage (INT) This. Handle, (INT) M. MSG, (INT) M. wparam, (INT) M. lparam );
}
}
}