Click here to Skip to main content
Sign Up to vote bad
good
See more: VB.NET
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..
 
<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 30 Dec '12 - 5:47
Minazeh296


2 solutions

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#[^]
  Permalink  
Comments
Minazeh - 31 Dec '12 - 11:21
thank you for this. i will review them and tell if they solved my problem.
Minazeh - 31 Dec '12 - 11:32
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:17
You are welcome, and thank you.
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.
  Permalink  
Comments
Minazeh - 30 Dec '12 - 12:01
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:10
It's not something I have done, but take a look at some of these links.
Minazeh - 30 Dec '12 - 12:19
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:31
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:34
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?...
Zoltán Zörgő - 30 Dec '12 - 12:40
Look at the SendMessage API help page Richared gave to you. There you can see, that both parameters are "additional, message specific" information. But SendMessage is not what you want! This is something to send event messages (like click, or keypress) to a specific window, this does not display anything.
Minazeh - 30 Dec '12 - 12:44
oh. can you tell me something that is more suited?
Zoltán Zörgő - 30 Dec '12 - 12:50
You want to show a popup from a windows forms application?
Minazeh - 30 Dec '12 - 12:55
hmm not that i guess, i want to know if there is a way that i can send a message from a newly opened window like a new friend message from yahoo messenger for example, and it will automatically send a message like "he is not here.." things like that.
Zoltán Zörgő - 30 Dec '12 - 13:01
Send to who, where? Newly created widow of what application? You want to intercept incoming messages of some chat application, and react automatically in name of the user?
Minazeh - 30 Dec '12 - 13:04
yes. something like that.
Zoltán Zörgő - 30 Dec '12 - 13:08
"Something like that" is no specification. But it looks not easy, since you have to control a third party application. Thus it depend mostly on how that was implemented, if it has any api or interface you can connect to, can you connect directly to the server, or you need to control the client, and so on... So either you give us really concrete details, or we are unable to help you for sure.
Minazeh - 30 Dec '12 - 13:24
How about this. Let's say i have a click event in this event it will look for a window that contains a name of "Untitled - Notepad" using the FindWindow Function importing from User32.dll.. then bring it to focus using SetForegroundWindow function ... i already manage to get until here.. my problem is.. Automatically sending/passing a string to the notepad after the SetForegroundWindow function executes. How can i pass a string to that notepad. that is my question. I am sorry for not being clear. or maybe it is still not clear.
Zoltán Zörgő - 31 Dec '12 - 3:19
Any progress?
Minazeh - 31 Dec '12 - 11:19
hmmm .. i am going to try something like using a dll that autoit has.. maybe there is a solution from that. because i use autoit before and i can set focus and send string to a notepad or any window i want. well.. i am hoping there is.
Richard MacCutchan - 30 Dec '12 - 12:48
The ByVal keyword is described here. You should get used to using the MSDN documentation for simple queries, it is an invaluable tool. You should also note Zoltán's comments.
Minazeh - 30 Dec '12 - 12:51
The sayings are true. "There are no easy routes in this world." I am grateful for your responses. I will study harder.
Richard MacCutchan - 30 Dec '12 - 12:57
That's very true. But keep at it, you obviously have the basic understanding so it's just a matter of determination to learn, and practice, practice, practice.

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

  Print Answers RSS
Your Filters
Interested
Ignored
     
0 Sergey Alexandrovich Kryukov 353
1 OriginalGriff 345
2 Arun Vasu 315
3 Maciej Los 208
4 Aarti Meswania 180
0 Sergey Alexandrovich Kryukov 9,755
1 OriginalGriff 7,549
2 CPallini 4,018
3 Rohan Leuva 3,362
4 Maciej Los 2,951


Advertise | Privacy | Mobile
Web01 | 2.6.130523.1 | Last Updated 30 Dec 2012
Copyright © CodeProject, 1999-2013
All Rights Reserved. Terms of Use
Layout: fixed | fluid