Newsgroup: it.comp.lang.visual-basic
Titolo: Help! Pasting text into any text editor

Hello,
I'm attempting to make a program that will paste text from the clipboard 
into any program of my choosing. The main part of my program is as follows;
Editbox = FindWindowEx(FindWindow(vbNullString, "Document - WordPad"), 0, 
"EDIT", vbNullString)
PostMessage Editbox, WM_PASTE, 0, 0
I can get this working with notepad. However, does anyone have any ideas how 
I can get the above to work with say, WordPad for example? The above code 
doesn't seem to work :o(
Help here would be enormously appreciated,
James 

 ha scritto nel messaggio
news:mTc7f.7645$Ce5....@newsfe1-gui.ntli.net...

You can use SPY++ tool (shipped with MS VS 6.0) to find the correct edit window
of the target program.
In this case you may find that the correct window class parameter is something
like "RICHEDIT50W" instead of "EDIT".
HTH
Bye
Raf

Hi,
Thanks for that. Unfortunately, when I put in the Class of WordPad (which is 
RICHEDIT50W) and replace the string with the correct window title - Wordpad 
crashes :o( please can you help?
James
"Rafunk" <rafun...@NOTHANKSlibero.it> wrote in message 
news:djknd3$p58$1...@alix.livenet.it...


 James
Which Windows version are you working with?
I tried the same code I posted in the previous message, and it works fine under
WinXPSP1.
Can you post your complete code?
Bye
Raf
P.S. 1 - This is an ITALIAN newsgroup: "it." stands for Italy, not "Information
Technology"! So, please be patient if your questions don't receive an
appropriate answer... or don't receive answers at all!
P.S. 2 - Try to use "correct" quoting, i.e. write your replies under previous
message text.

Hi,
Here is my code, I really hope you can help.I'm running WinXP Pro SP2
Option Explicit
Private Declare Function PostMessage Lib "user32" _
Alias "PostMessageA" (ByVal hwnd As Long, _
ByVal wMsg As Long, ByVal wParam As Long, _
lParam As Any) As Long
Private Declare Function FindWindow Lib "user32.dll" _
Alias "FindWindowA" (ByVal lpClassName As String, _
ByVal lpWindowName As String) As Long
Private Declare Function FindWindowEx Lib "user32" _
Alias "FindWindowExA" (ByVal hWnd1 As Long, _
ByVal hWnd2 As Long, ByVal lpsz1 As String, _
ByVal lpsz2 As String) As Long
Private Const WM_PASTE = &H302
Private Sub Command1_Click()
Dim Notepad As Long, Editbox As Long
Notepad = FindWindow(vbNullString, "Document - WordPad")
Editbox = FindWindowEx(Notepad, 0, "RICHEDIT50W", vbNullString)
PostMessage Editbox, WM_PASTE, 0, 0
'MsgBox Editbox
End Sub
Many thanks,
James
"Rafunk" <rafun...@NOTHANKSlibero.it> wrote in message 
news:djl595$8ae$1...@alix.livenet.it...


 PostMessage Editbox, WM_PASTE, 0, 0
Since API declaration has lParam As Any, you have to pass explicitly ByVal any
NULL value:
PostMessage Editbox, WM_PASTE, 0, ByVal 0&
Or rather, you may want to declare PostMessage as follows (as I did in my
trial):
Private Declare Function PostMessage Lib "user32.dll" _
    Alias "PostMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, _
    ByVal wParam As Long, ByVal lParam As Long) As Long
HTH
Raf

Hi,
Thankyou very much for your help. I'm nearly there in understanding what it 
will take to get my program to function with all text editors. However, I've 
become stumped again :o(
I'm trying to paste text on the clipboard into the 'To' field in a new 
outlook express mail message.
I've got down to the sub-window but can't proceed further because the 
textbox is only differentiated with its ID referenced in WinID as 0x3E9 hex
Notepad = FindWindow(vbNullString, "New Message")
nxtwnda = FindWindowEx(Notepad, 0, "OE_Envelope", vbNullString)
nxtwndb = FindWindowEx(nxtwnda, 0, "0x3E9", vbNullString)
PostMessage nxtwndb, WM_PASTE, 0, ByVal 0&
Please can you help?
James
"Rafunk" <rafun...@NOTHANKSlibero.it> wrote in message 
news:djlcid$d41$1...@alix.livenet.it...
