关于剪贴板(50分)

D

DNChen

Unregistered / Unconfirmed
GUEST, unregistred user!
怎样在剪贴板内容发生改变时获得消息,不能用timer和HOOK,有没有其他方法呢?
 
可以自己写剪贴板处理程序!
 
不用Timer或Hook, 至少也得有一个While循环来分析和转发消息.
 
哦?没有其他办法了吗?
 
有办法,让剪贴板向你发消息。
 
to chenke: 又跟着感觉走了, 不是所有的东西都能发消息的.针对这个问题我仔细的<br>查看了win32 api.因为ClipBoard本身不具有自己的Handle,它本身也不是Windows<br>的一个类,故ClipBoard是不会发消息的,但是系统能够接收Cut,Copy to Clipboard<br>等消息. 能够发消息的是Clipboard Viewer, 或者是Clipboard Server. 其实做一<br>个hook检测Clipboard的变化是最实际的. 如果你想要根据Clipboard里面是否有适<br>合粘贴的内容来动态改变你菜单中的"粘贴"是否可用的话, timer也是需要的.<br>
 
just a joke.
 
DNChen, 问到了吗?<br>顺便告诉你一声,最好别做“收费系统”, 光那药品编码就搞死你。
 
呵呵lewis hong的资料还没有过来,过来后我看看,如果有用会贴在这儿
 
to dnchen:我没有找到消息<br>实际上用TIMER也不会浪费太多的系统资源
 
资料过来了,不要用timer,也不要用hook得,有谁要得话留个条子,我贴出来,挺<br>长得,各位先表个态,不要我就不贴,结束这个帖子了
 
贴出来看看,如何? <br>让俺长长见识。 谢谢!
 
我也想看看!
 
呵呵,六个人已经有三个同意了,CJ应该不会骂我,六比四,来点心理准备,28K<br>得文字,所以把C++源程序省了,要得人可以写信给我,如果实在多,我可以给YYSUN<br><br>Creating a Clipboard Viewer Window<br><br>A clipboard viewer window displays the current content of the clipboard, and receives messages when the clipboard content changes. To create a clipboard viewer window, your application must do the following: <br>· Add the window to the clipboard viewer chain. <br>· Process the WM_CHANGECBCHAIN message. <br>· Process the WM_DRAWCLIPBOARD message. <br>· Remove the window from the clipboard viewer chain before it is destroyed. <br><br>Adding a Window to the Clipboard Viewer Chain<br><br>A window adds itself to the clipboard viewer chain by calling the SetClipboardViewer function. The return value is the handle of the next window in the chain. A window must keep track of this value ? for example, by saving it in a static variable named hwndNextViewer. <br>The following example adds a window to the clipboard viewer chain in response to the WM_CREATE message. <br>case WM_CREATE: &nbsp;<br>&nbsp;<br>&nbsp; &nbsp; // Add the window to the clipboard viewer chain. <br>&nbsp;<br>&nbsp; &nbsp; hwndNextViewer = SetClipboardViewer(hwnd); <br>&nbsp; &nbsp; break; <br>&nbsp;<br>Processing the WM_CHANGECBCHAIN Message<br><br>A clipboard viewer window receives the WM_CHANGECBCHAIN message when another window is removing itself from the clipboard viewer chain. If the window being removed is the next window in the chain, the window receiving the message must unlink the next window from the chain. Otherwise, this message should be passed to the next window in the chain. <br>The following example shows the processing of the WM_CHANGECBCHAIN message. <br>case WM_CHANGECBCHAIN: &nbsp;<br>&nbsp;<br>&nbsp; &nbsp; // If the next window is closing, repair the chain. <br>&nbsp;<br>&nbsp; &nbsp; if ((HWND) wParam == hwndNextViewer) <br>&nbsp; &nbsp; &nbsp; &nbsp; hwndNextViewer = (HWND) lParam; <br>&nbsp;<br>&nbsp; &nbsp; // Otherwise, pass the message to the next link. <br>&nbsp;<br>&nbsp; &nbsp; else if (hwndNextViewer != NULL) <br>&nbsp; &nbsp; &nbsp; &nbsp; SendMessage(hwndNextViewer, uMsg, wParam, lParam); <br>&nbsp;<br>&nbsp; &nbsp; break; <br>&nbsp;<br><br>&nbsp;<br>Removing a Window from the Clipboard Viewer Chain<br><br>To remove itself from the clipboard viewer chain, a window calls the ChangeClipboardChain function. The following example removes a window from the clipboard viewer chain in response to the WM_DESTROY message. <br>case WM_DESTROY: &nbsp;<br>&nbsp; &nbsp; ChangeClipboardChain(hwnd, hwndNextViewer); <br>&nbsp; &nbsp; PostQuitMessage(0); <br>&nbsp; &nbsp; break; <br><br>Processing the WM_DRAWCLIPBOARD Message<br><br>The WM_DRAWCLIPBOARD message notifies a clipboard viewer window that the content of the clipboard has changed. A window should do the following when processing the WM_DRAWCLIPBOARD message: <br> 1. Determine which of the available clipboard formats to display. <br> 2. Retrieve the clipboard data and display it in the window. Or if the clipboard format is CF_OWNERDISPLAY, send a WM_PAINTCLIPBOARD message to the clipboard owner. <br> 3. Send the message to the next window in the clipboard viewer chain. <br>&nbsp;<br>For an example of processing the WM_DRAWCLIPBOARD message, see the example listing in Example of a Clipboard Viewer. <br><br>Example of a Clipboard Viewer<br>
 
我还以为什么呢!我不是说:可以自己写剪贴板处理程序!<br>在一本delphi的书上有原程序!<br>
 
呵呵,这么不客气,不过还是开始分赃了!
 

Similar threads

回复
0
查看
813
不得闲
S
回复
0
查看
970
swish
S
I
回复
0
查看
657
import
I
顶部