SetFocus to WordPad

SetFocus to WordPad

Post by Tanya Karpi » Thu, 26 Jun 2003 17:05:39



Hi,
I'm not sure that it's a right newsgroup, so please
redirect me if not.

I develop application that processes data from clipboard
and should return
it back to clipboard owner like Wordpad, MS Word, etc.

My question is how I can set focus to clipboard owner
(RichEdit, WordPad...)
to paste the data back? My application runs as independent
process. I tryed
following 2 versions (see code snippet below), but it
works only for Notepad and not WordPad/MS Word.

Please advice.
Tanya

        HWND    hOwner = NULL;
        HWND    hpar = NULL;
        hOwner = ::GetClipboardOwner();
        hpar = hOwner;

/*
// version1-----------------------------------
        BOOL b1 = ::SetForegroundWindow(hpar);
*/

// version2-------------------------------------
DWORD   lpdwProcessId;
DWORD   idAttach = GetWindowThreadProcessId(

hpar,             //IN handle to window

&lpdwProcessId);  //OUT process identifier
DWORD idAttachTo = GetCurrentThreadId();
BOOL bb = AttachThreadInput(

idAttach,    // thread to attach

idAttachTo,  // thread to attach to

TRUE );      // attach or detach
HWND hw = ::SetFocus(hpar);
        bb = AttachThreadInput(

idAttach,    // thread to attach

idAttachTo,  // thread to attach to

FALSE);      // attach or detach

 
 
 

SetFocus to WordPad

Post by Jim Barr » Fri, 27 Jun 2003 09:52:21



> I develop application that processes data from clipboard
> and should return
> it back to clipboard owner like Wordpad, MS Word, etc.

> My question is how I can set focus to clipboard owner
> (RichEdit, WordPad...)

For OLE applications the clipboard owner appears to be a private OLE-managed window of class CLIPBRDWNDCLASS. These windows don't show up in the window hierarchy shown by Spy++. You can find out which process the window belongs to with GetWindowThreadProcessId. The problem then is that applications like Word have multiple document windows within a single process, and there is no way to tell which one the clipboard data came from.

--
Jim Barry, MVP for Windows SDK

 
 
 

1. Running WordPad from Excel VBA (if necessary)

I am a new VB programmer and can't find a good example to assist me -
wondering if someone out there can.

My VB app is exporting a file with string data that, when exported, has
quotes around the data.

If possible I'd like turn that option off when writing.

Otherwise, after I'm done writing all my data, what I'd like to do is

Start up WordPad
Open this exported file
Do a Replace on all quotes to nothing
Save the file
Close the file

Any help GREATLY appreciated.
Robin

2. pine and uqwk

3. Printing PDF from Windows 95 WordPad

4. Samba+KerberosIV

5. help with wordpad

6. Stocks with decimals

7. Wordpad layout? Font size?

8. uploading problem on GTE ADSL

9. OLE with WordPad (W95)

10. Reading in files w/ Wordpad associations under NT

11. lcc-Win32 -- Manual.doc doesn't display properly in Wordpad

12. Setfocus

13. Zinc and setFocus()