The MASM Forum Archive 2004 to 2012

General Forums => The Campus => Topic started by: Xacker on October 21, 2008, 02:11:07 PM

Title: What is the best way to monitor clipboard events?
Post by: Xacker on October 21, 2008, 02:11:07 PM
Hi,

old thread: http://www.masm32.com/board/index.php?topic=10155.msg74362#msg74362 (not that old)

this is not a double post, this is a separation between the two different concepts so moderators don't miss understand it with some illegal activities because I can tell the old thread got totally ignored.

Q:
What is the best way to monitor clipboard activities especially the copy event?

I've done my googling, I read articles, I'm not looking for a full source of code, just pointers from professional people who must have done it before and figured several ways for doing it.

thank you in advance.
Xacker.
Title: Re: What is the best way to monitor clipboard events?
Post by: qWord on October 21, 2008, 03:04:36 PM
Do you want to write a "Clipboard-Extension" ? - if so, there is an simple method without monitoring. Just Register your own Hotkey e.g. : CONTROL+"y". While processing WM_HOTKEY you can use keybd_event to simulate CONTROL+c. After waiting some milliseconds you can open the clipboard to obtain data.
Title: Re: What is the best way to monitor clipboard events?
Post by: Xacker on October 21, 2008, 03:12:09 PM
Quote from: qWord on October 21, 2008, 03:04:36 PM
Do you want to write a "Clipboard-Extension" ?

sort of, but not exactly, from my old topic

Quote
it's a small utility to allow me copy several phrases/words several times from any window and put them in a list, then by user request and right click of the mouse a pop-up menu shows up to select what phrases/words to paste so the user doesn't have to copy > paste immediately but only when he feels to.

I was trying to avoid the sleep API thing (the concept of waiting for xyz milliseconds not the API itself), add to that it has to work on CTRL+C event, not all users read the manual.

Any other suggestions?
thank you for your time.
Title: Re: What is the best way to monitor clipboard events?
Post by: Jimg on October 21, 2008, 03:23:36 PM
add a window to the clipboard chain
(google "clipboard chain")
Title: Re: What is the best way to monitor clipboard events?
Post by: Xacker on October 21, 2008, 06:48:15 PM
Quote from: Jimg on October 21, 2008, 03:23:36 PM
add a window to the clipboard chain
(google "clipboard chain")

We meet again JimG :)

I thought of that, what if my program doesn't have a dialog (in other words, no window > no window handle)?
Title: Re: What is the best way to monitor clipboard events?
Post by: BogdanOntanu on October 21, 2008, 09:18:37 PM
Quote
I thought of that, what if my program doesn't have a dialog (in other words, no window > no window handle)?

Make a window for it ... or we and your users are going to think that you intend to hide something :D
Title: Re: What is the best way to monitor clipboard events?
Post by: donkey on October 21, 2008, 11:28:52 PM
Register as a clipboard viewer window, that way you get a notification every time the clipboard changes


http://msdn.microsoft.com/en-us/library/ms649052(VS.85).aspx
Title: Re: What is the best way to monitor clipboard events?
Post by: hutch-- on October 21, 2008, 11:33:56 PM
I have a clipboard viewer in the current version of QE and they are very easy to write, just set up a timer at whatever is a convenient interval and read the text from the clipboard into the viewer. It would be easy enough to just append each change to the clipboard to the end of an edit control so you have a clipboard log to check.
Title: Re: What is the best way to monitor clipboard events?
Post by: donkey on October 21, 2008, 11:39:07 PM
Quote from: Xacker on October 21, 2008, 06:48:15 PM
Quote from: Jimg on October 21, 2008, 03:23:36 PM
add a window to the clipboard chain
(google "clipboard chain")

We meet again JimG :)

I thought of that, what if my program doesn't have a dialog (in other words, no window > no window handle)?

Use a message only window...

QuoteMessage-Only Windows

A message-only window enables you to send and receive messages. It is not visible, has no z-order, cannot be enumerated, and does not receive broadcast messages. The window simply dispatches messages.

To create a message-only window, specify the HWND_MESSAGE constant or a handle to an existing message-only window in the hWndParent parameter of the CreateWindowEx function. You can also change an existing window to a message-only window by specifying HWND_MESSAGE in the hWndNewParent parameter of the SetParent function.

To find message-only windows, specify HWND_MESSAGE in the hwndParent parameter of the FindWindowEx function. In addition, FindWindowEx searches message-only windows as well as top-level windows if both the hwndParent and hwndChildAfter parameters are NULL.
Title: Re: What is the best way to monitor clipboard events?
Post by: hutch-- on October 22, 2008, 12:44:06 AM
i had a quick look around and here is a reference that may be useful, the examples are in Delphi but the API reference should do the job.

http://www.delphidabbler.com/articles?article=9
Title: Re: What is the best way to monitor clipboard events?
Post by: Xacker on October 23, 2008, 02:44:32 AM
Quote from: donkey on October 21, 2008, 11:39:07 PM
Use a message only window...

Which is exactly what I want  :U thank you it works.

Quote
i had a quick look around and here is a reference that may be useful, the examples are in Delphi but the API reference should do the job.

http://www.delphidabbler.com/articles?article=9

Thanks alot hutch :)

appreciated.
Title: Re: What is the best way to monitor clipboard events?
Post by: kero on November 03, 2008, 09:33:41 AM
Following MSDN's info contains some serious inaccuracies:

Quote
Message-Only Windows

A message-only window enables you to send and receive messages. It is not visible, has no z-order, cannot be enumerated, and does not receive broadcast messages. The window simply dispatches messages.

To create a message-only window, specify the HWND_MESSAGE constant or a handle to an existing message-only window in the hWndParent parameter of the CreateWindowEx function. You can also change an existing window to a message-only window by specifying HWND_MESSAGE in the hWndNewParent parameter of the SetParent function.

To find message-only windows, specify HWND_MESSAGE in the hwndParent parameter of the FindWindowEx function. In addition, FindWindowEx searches message-only windows as well as top-level windows if both the hwndParent and hwndChildAfter parameters are NULL.

1)   > "cannot be enumerated"

FALSE!

As EnumChildWindows(GetDesktopWindow) enumerates all usual windows -

EnumChildWindows(GetMessageWindow) enumerates all message-only windows,

where GetMessageWindow = GetAncestor(FindWindowEx(HWND_MESSAGE,0,0,0),GA_PARENT),  GetClassName (GetMessageWindow) = "Message".

Btw symmetry: GetDesktopWindow = GetAncestor(FindWindowEx(HWND_DESKTOP,0,0,0),GA_PARENT).

2)  > "To create a message-only window, specify the HWND_MESSAGE constant or a handle to an existing message-only window in the hWndParent parameter of the CreateWindowEx function".

But it's right only for top message-only window (class "Message")!
Any other message-only owner in the hWndParent parameter of the CreateWindowEx preordains usual, non message-only window.

3)  > "You can also change an existing window to a message-only window by specifying HWND_MESSAGE in the hWndNewParent parameter of the SetParent function."

But here we can use any message-only window, not only HWND_MESSAGE constant or top "Message" window.

So MSDN's explanations about hWndParent and hWndNewParent must be exchange :)


See enumeration of all message-only (and all usual) windows in sources of WinTreeSnap and FrameRector:


[attachment deleted by admin]