I want to paste some text in clipboard into Ms Word. I wrote this following code

a:=findWIndow(pchar('OpusApp'),nil);
 b:=FindWindowEx(a,0,pchar('_WwF'),nil);
 c:=FindWindowEx(b,0,pchar('_WwB'),nil);
 d:=FindWindowEx(c,0,pchar('_WwG'),nil);
 SendMessage(d,wm_paste,0,0);

and it didn't work.

But i wrote the code below to paste into Wordpad,and it works fine

a:=findwindow(pchar('WordPadClass'),nil);
 b:=FindWindowEx(a,0,pchar('RICHEDIT50W'),nil);
 SendMessage(b,wm_paste,0,0);

Am I made some mistake in Ms Words' window structure? The structure above is what i got using Winspector.I'm currently using Ms Word 2007.

Does anyone have solution?

Thanks

I don't use Word, so I can't help... but what you are doing is unlikely to work well anyway because the window class names can change between versions of Word... But I think you should be looking for a RichEdit class...

I think you ought to look at OLE automation.
Here's a page all about word
http://www.kayodeok.btinternet.co.uk/favorites/kbofficewordhowto.htm

Search down near the bottom in "How to automate word" for "paste".

The other option would be to send the proper keyboard sequences to Word to access the Edit|Paste menu item.

Sorry I can't be of more help.

I've found a solution in Word VBA reference:

V := GetActiveOleObject('Word.Application');
V.ActiveDocument.ActiveWindow.Selection.Paste;

All i have to do is to check whether the foreground window is Ms Word or not, using GetClassName and GetForegroundWindow.

Problem solve. After all, thanks to you guys...

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.