471,354 Members | 1,284 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,354 software developers and data experts.

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

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

Similar topics

5 posts views Thread by Tim | last post: by
6 posts views Thread by scottt | last post: by
reply views Thread by raludamian | last post: by
6 posts views Thread by alexia.bee | last post: by
4 posts views Thread by Luc The Perverse | last post: by
reply views Thread by machetesk8 | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.