/// <summary> ///Adds The specified window to the chain of clipboard viewers. Clipboard Viewer windows receive a Wm_drawclipboard message whenever the content of the Clipboard changes. This function was used for backward compatibility with earlier versions of Windows. /// </summary> /// <param name= "Hwndnewviewer" >A handle to the window to being added to the clipboard chain.</param> /// <returns></returns>[DllImport ("User32.dll")] protected Static externIntPtr setclipboardviewer (IntPtr hwndnewviewer); /// <summary> ///removes a specified window from the chain of clipboard viewers. /// </summary> /// <param name= "Hwndremove" >A handle to the window to being removed from the chain. The handle must has been passed to the SetClipboardViewer function.</param> /// <param name= "Hwndnewnext" >A handle to the window, follows the Hwndremove window in the Clipboard viewer chain. (This are the handle returned by SetClipboardViewer, unless the sequence were changed in response to a wm_changecbchain mess Age.)</param> /// <returns>The return value indicates the result of passing the Wm_changecbchain message to the Windows in the Clipboard Viewer C Hain. Because a window in the chain typically returns FALSE if it processes Wm_changecbchain, the return value from Changeclip Boardchain is typically FALSE. If there is a window in the chain, the return value is typically TRUE.</returns>[DllImport ("User32.dll", CharSet =CharSet.Auto)] Public Static extern BOOLChangeclipboardchain (IntPtr hwndremove, IntPtr hwndnewnext); /// <summary> ///sends the specified message to a window or windows. The SendMessage function calls the window procedure for the specified window and does not return until the window Procedur E has processed the message. ///to send a message and return immediately, use the Sendmessagecallback or SendNotifyMessage function. To post a message to a thread ' s message queue and return immediately, use the PostMessage or PostThreadMessage function. /// </summary> /// <param name= "HWnd" >A handle to the window whose window procedure would receive the message. If This parameter are Hwnd_broadcast (HWND) 0xffff), the message is sent to all top-level windows in the system, including Disabled or invisible unowned windows, overlapped Windows, and pop-up windows; But the message isn't sent to child windows. ///Message Sending is subject to UIPI. The thread of a process can send messages only to message queues of threads in processes of lesser or equal integrity Leve L.</param> /// <param name= "MSG" >The message to be sent.</param> /// <param name= "WParam" >Additional message-specific information.</param> /// <param name= "LParam" >Additional message-specific information.</param> /// <returns>The return value specifies the result of the message processing; It depends on the message sent.</returns>[DllImport ("user32.dll", CharSet =CharSet.Auto)] Public Static externIntPtr SendMessage (IntPtr hWnd,intMSG, IntPtr WParam, IntPtr lParam); //defined in Winuser.h Public Const intWm_drawclipboard =0x0308;//message when the contents of the Clipboard change Public Const intWm_changecbchain =0x030d;//maintain message for clipboard chainIntPtr Nextviewer;// Handle PublicForm1 () {InitializeComponent (); Nextviewer= SetClipboardViewer ( This. Handle); } protected Override voidWndProc (refSystem.Windows.Forms.Message m) { //determines the action method based on the obtained message Switch(m.msg) { CaseWm_drawclipboard:displayclipboarddata (); SendMessage (Nextviewer, m.msg, M.wparam, m.LParam); Break; CaseWm_changecbchain:if(M.wparam = =nextviewer) Nextviewer=m.LParam; ElseSendMessage (Nextviewer, m.msg, M.wparam, m.LParam); Break; default: Base. WndProc (refm); Break; } } Private voidDisplayclipboarddata () {IDataObject data=NewDataObject (); Data= Clipboard.getdataobject ();//getting data from the Clipboard if(Data. GetDataPresent (DATAFORMATS.RTF))//determine if the format is the sameTxtdata.rtf = (string) data. GetData (DATAFORMATS.RTF); Else if(data. GetDataPresent (Dataformats.text)) Txtdata.text= (string) data. GetData (Dataformats.text); ElseTxtdata.text="data format is not available in the Clipboard"; }
Getting data from the Clipboard