Monday, October 4, 2004


Using the clipboard from .NET CF

I was about to implement my own clipboard classes for .NET CF when I found the Clipboard usage article.

It has complete source code that implements the two alternatives for working with the clipboard in .NET CF.

Alternative 1: use P/Invoke to call the following methods:
[DllImport("Coredll.dll")] private static extern bool OpenClipboard(IntPtr hWndNewOwner);
[DllImport("Coredll.dll")] private static extern bool CloseClipboard();
[DllImport("Coredll.dll")] private static extern bool EmptyClipboard();
[DllImport("Coredll.dll")] private static extern bool IsClipboardFormatAvailable(uint uFormat);
[DllImport("Coredll.dll")] private static extern IntPtr GetClipboardData(uint uFormat);
[DllImport("Coredll.dll")] private static extern IntPtr SetClipboardData(uint uFormat, IntPtr hMem);

Alternative 2: use the keyboard shortcuts
So far I manually work around the missing clipboard support in .NET CF by switching to the Keyboard instead of the "Block Recognizer" when I have to cut and paste. The Windows shortcuts for cut and paste works like a charm;
Ctrl + X: Cut
Ctrl + C: Copy
Ctrl + V: Paste

The textbox example adds a popup menu to a text field and simulates the user pressing keys buy using the keybd_event API.

No comments:

Post a Comment