How to use [DllImport("user32.dll")]

J

Juan Martinez

In a form i have a drawing control called VectorDraw and a textbox. The
text box is disable, when i am using the drawing area i can write some
text, what i want to do is that when i press any key that key show in
the textbox, or if other control has the focus and i press other key
also show in the textbox.

I saw some info about this using the user32.dll like this:

[DllImport("user32.dll")]
static extern bool TranslateMessage([In] ref Message lpMsg);

[DllImport("user32.dll")]
static extern IntPtr DispatchMessage([In] ref Message lpmsg);

and in the controls keydown event i wrote this:

Message Mssg = new Message();

Mssg.HWnd = control.Handle;

// HERE IS WHERE I DONT KNOW WHAT PARAMETERS ARE THE CORRECT ONES TO USE

Mssg.Msg = ???;
Mssg.LParam = ???;
Mssg.WParam = ???;

TranslateMessage(ref Mssg);
DispatchMessage(ref Mssg);


Sombody can help me with this???
 
B

Benny Raymond

You have to look up on the msdn website what the LParam and WParam are
used for for the specific message you recieve/send. You can also look
up the TranslateMessage and DispatchMessage functions there to see
exactly what they require.
 
N

Nicholas Paldino [.NET/C# MVP]

Juan,

You shouldn't be calling TranslateMessage or DispatchMessage. Rather,
you want to call SendMessage to send your message to your control. This is
how notifications are sent from one control to another.

Also, you might want to check to see if you really need to do this,
since there are probably properties on your control which you can call to do
the same thing.

Translating and dispatching of the messages is not something you need to
handle, generally.

Basically, what you should be doing is handling the key press events,
and modifying the Text property of the textbox to reflect the key pressed.

Hope this helps.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top