Click here to Skip to main content
15,885,998 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am having a hard time understanding this piece of code.. I am a complete beginner in programming and I am trying to learn new things. Someone kindly explain this for me? Specially the parameters... what purpose each of the parameters will do..

VB
<DllImport("user32.dll", SetLastError:=True, CharSet:=CharSet.Auto)> _
Private Shared Function SendMessage(ByVal hWnd As IntPtr,_
ByVal Msg As UInteger, ByVal wParam As IntPtr, ByVal lParam As IntPtr) As IntPtr
End Function


I tried looking in the net but I really can't understand .. maybe you guys can give a more easy to understand explanation.
Posted

This is known as Platform Invoke[^], and is a way of using the system API directly from .NET languages. In this specific case it allows you to use the Windows SendMessage function[^], which is a somewhat advanced topic for a beginner. I would suggest that you stick to pure .NET code until you are fully comfortable with it before moving on to using the Win32 functions.
 
Share this answer
 
Comments
Minazeh 30-Dec-12 12:01pm    
i know that this is a bit advance, i think i might need to include this to the program i am currently developing(well, its not a big program though) because in the program i am developing now. i want to add a feature like when a new window pops out like yahoo messenger window for example.. it will automatically focus on that new window appeared then it will automatically send message like "the user of the pc is sleeping..." something like that.. is there a way to achieve this kind of thing with pure .net?
Richard MacCutchan 30-Dec-12 12:10pm    
It's not something I have done, but take a look at some of these links.
Minazeh 30-Dec-12 12:19pm    
Thanks for the response.. I will review this links for the meantime. maybe I can message you if i have more clarifications to ask?
Richard MacCutchan 30-Dec-12 12:31pm    
If you are interested in Windows Hooks then I would suggest starting a new thread, there are probably many people here who can give you help on the subject.
Minazeh 30-Dec-12 12:34pm    
maybe i should, but one more question.. related in the code above..the..

ByVal wParam As IntPtr
and
ByVal lParam As IntPtr

what do they do?...
After a long lasting clarification, I have some idea what you want.
If you like to send keystrokes to an other window, you can use SendMessage, since that is the very basic tool of Windows messaging. Look here: http://improve.dk/archive/2007/04/06/sending-keypresses-to-a-window.aspx[^].
But there is a more convenient way than using P/Invoke: SendKeys class[^].
Look here:
- http://www.devx.com/dotnet/Article/7914/0/page/5[^]
- http://www.java2s.com/Tutorial/VB/0260__GUI/SendKeys.htm[^]
- http://www.java2s.com/Code/VB/GUI/UsingSendKeystosimulatekeypress.htm[^]

But you might find this also interesting: Sending Keystrokes to another Application in C#[^]
 
Share this answer
 
Comments
Minazeh 31-Dec-12 11:21am    
thank you for this. i will review them and tell if they solved my problem.
Minazeh 31-Dec-12 11:32am    
This is a a lot more easy to understand because the links provide a more easy to understand examples. i will accept this as a solution thanks.
Zoltán Zörgő 31-Dec-12 13:17pm    
You are welcome, and thank you.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900