473,785 Members | 2,400 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How to use [DllImport("user 32.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("user 32.dll")]
static extern bool TranslateMessag e([In] ref Message lpMsg);

[DllImport("user 32.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 = ???;

TranslateMessag e(ref Mssg);
DispatchMessage (ref Mssg);
Sombody can help me with this???
*** Sent via Developersdex http://www.developersdex.com ***
Dec 2 '05 #1
2 26588
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 TranslateMessag e 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("user 32.dll")]
static extern bool TranslateMessag e([In] ref Message lpMsg);

[DllImport("user 32.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 = ???;

TranslateMessag e(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 TranslateMessag e 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.co m
"Juan Martinez" <ja*****@hotmai l.com> wrote in message
news:ub******** ******@TK2MSFTN GP15.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("user 32.dll")]
static extern bool TranslateMessag e([In] ref Message lpMsg);

[DllImport("user 32.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 = ???;

TranslateMessag e(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
8429
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
6445
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 http://www.dot.net.nz/codesamples.browseforfolder.aspx , and other places, the folder Ids are: /// /// Enum of CSIDLs identifying standard shell folders.
5
5107
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 the SendInput call always returns "0". Here is some of the code: Beginning of Code... static extern uint SendInput(uint nInputs, ref INPUT pInputs, int cbSize);
6
19727
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
1411
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 VS 2005 --C++ --Smart Devices and I obtained a DLL. Now I need to access the DLL functions (unmanaged code) from my C# (managed code) application. Unfortunatelly I got a "Can't find PInvoke dll" problem.
13
3523
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 get the "UserName" of a connection. How is it possible? plz hlp thnk u
6
9207
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 but couldn't find any. Can any one please help me with that? Thanks.
4
9159
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" would be feasable for me (someone not good at programming) to implement. -- LTP :)
0
960
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 the application the dll stays open!! and i can't open other applications that uses this dll please i need some help thanx
0
10346
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10096
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9956
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7504
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6742
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5386
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5514
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3658
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2887
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.