By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
449,370 Members | 1,581 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 449,370 IT Pros & Developers. It's quick & easy.

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

P: n/a
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???
*** Sent via Developersdex http://www.developersdex.com ***
Dec 2 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
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.

Juan Martinez wrote:
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???
*** Sent via Developersdex http://www.developersdex.com ***

Dec 2 '05 #2

P: n/a
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.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com
"Juan Martinez" <ja*****@hotmail.com> wrote in message
news:ub**************@TK2MSFTNGP15.phx.gbl...
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???
*** Sent via Developersdex http://www.developersdex.com ***

Dec 2 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.