VB.NET Clipboard Change
-
Hello, I am writing a program and i need to catch the change clipboard msg to start a event. The program is a ScreenDump program so you will understand this short qeustion. I know how to put and get data in or out the clipboard. maybe you can give me a code sample on how the change clipboard msg works after pressing toe Snapshot key. thank you in advanced. Jordan2000
-
Hello, I am writing a program and i need to catch the change clipboard msg to start a event. The program is a ScreenDump program so you will understand this short qeustion. I know how to put and get data in or out the clipboard. maybe you can give me a code sample on how the change clipboard msg works after pressing toe Snapshot key. thank you in advanced. Jordan2000
I'm a bit confused... You're already putting the data on the clipboard and taking it off? If that's the case, why would you need to detect the change in the clipboard? BTW: There is no clipboard changed event... RageInTheMachine9532
-
I'm a bit confused... You're already putting the data on the clipboard and taking it off? If that's the case, why would you need to detect the change in the clipboard? BTW: There is no clipboard changed event... RageInTheMachine9532
I am sorry the question was not clear. ok when i pres on the snapshot key i want that the screendump to be saved. there is a kinde of hook in the clipboard event that i can tap in but i cant find out how it works. WMDrawClipboard i found on msdn but the explenation is not clear. and cant find a soutable code sample fore VB.NET
-
I am sorry the question was not clear. ok when i pres on the snapshot key i want that the screendump to be saved. there is a kinde of hook in the clipboard event that i can tap in but i cant find out how it works. WMDrawClipboard i found on msdn but the explenation is not clear. and cant find a soutable code sample fore VB.NET
Are you saying the when a user presses PrtScrn or Alt-PrtScrn, you want you app to be notified that there is something new on the clipboard? If that's true, now I understand... Ummm...OK. Your going to have to override the WndProc function in your form to receive the WM_DRAWCLIPBOARD message and process it. You'll also need to process WM_CHANGECBCHAIN too if other applications register as clipboard viewers, you can repair the end of the chain if your suddently the last in the chain. You'll need to use the SendMessage, SetClipBoardViewer and ChangeClipboardChain functions, in user32.dll, and GetLastError, in kernel32, to handle this. What your going to do is when your app starts, call SetClipBoardViewer with the window handle of your form. You'll have to save the return value as this is the handle of the next window in the clipboard viewer chain. Next, call GetLastError to see if what you got back was an error or a null handle. Now, in you WndProc procedure, when you get the WM_DRAWCLIPBOARD message, you can use the standard .NET Clipboard functions to get the image from the clipboard and display it in a PictureBox if need be. You'll then need to use SendMessage to send the same message you got to the next window in the chain, (remember that return value from SetClipBoardViewer?) unless it's null. Now, you may be wondering why you have to handle WM_CHANGECBCHAIN. This is because if the next window in the chain is the one that your supposed to send the WM_DRACLIPBOARD to, you'll need to know that it's been removed and you no longer have to send that message, or you'll need to send it to a different window now. . . I've lost you, haven't I...? Last but not least, when your app quits, you have to remove yourself from the viewer chain. This is done by calling ChangeClipboardChain with your window handle and the window handle of the window your supposed to be forwarding WM_DRAWCLIPBOARD messages to. Simple, no? :) RageInTheMachine9532
-
I am sorry the question was not clear. ok when i pres on the snapshot key i want that the screendump to be saved. there is a kinde of hook in the clipboard event that i can tap in but i cant find out how it works. WMDrawClipboard i found on msdn but the explenation is not clear. and cant find a soutable code sample fore VB.NET
jordan2000 wrote: cant find a soutable code sample fore VB.NET That's because there really isn't any. Registering as a clipboard viewer is not a common operation at all. You'll have to piece together example, like overriding WndProc and calling into the Win32 API. But, there is no simple way to do this. There is no event that is fired when the clipboard changes, so you have to go thru the Win32 API pain of registering for notifications yourself. RageInTheMachine9532