473,387 Members | 1,863 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 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 26550
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: mrzt | last post by:
the following codes won't work. ============================== using System; using System.Runtime; using System.Runtime.InteropServices; namespace Shutdown { /// <summary> /// Class1...
1
by: Frank Meng | last post by:
Hi. I wrote a program to get the directory of "Recycle Bin" with SHGetSpecialFolderLocation . It works for "Recent", "SendTo", etc. but it doesn't work for "Recycle Bin". At...
5
by: Tim | last post by:
Hello All, I am writing a program that checks for the NumLock status and turns the NumLock on if it is off. I'm not sure what I'm overlooking at this point, but the code will compile and run, but...
6
by: scottt | last post by:
I am trying to call into some C++ code from C#. One of the functions requires a handle to the instance (HINSTANCE hInstance) of the C# program. How do I access this in C#. Thanks,
0
by: raludamian | last post by:
Hello! I'm trying to develop a GIS mapping software on smart devices (Pocket PC) using VS 2005, C#. I need to use a library that was written in C++. Being open source I compiled the C++ code...
13
by: Javad | last post by:
Hello I know that I should get the information of windows internet connections by using "rasapi32.dll" library, and I also have some sample codes, but I can't make them work. My exact need is to...
6
by: alexia.bee | last post by:
Hi all, I need to write app in C# that communicates with other app. I need to use "named event" for that. I should use windows APIs SetEvent() and WaitForSingleObject() etc... I looked for help...
4
by: Luc The Perverse | last post by:
Hi - I have very little C# programming experience. I am making a software product which calls for an interface almost identical to Windows Explorer - and I wondered if mounting a "virtual drive"...
0
by: machetesk8 | last post by:
hi, this is my first post ever i have a problem with a dll that my application uses It's a pocket pc application that uses this dll when perform a synchronization i do this: but, after i exit...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.