Click here to Skip to main content
15,887,318 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi friends,

I am running a hidden windows application made in C#.
If the user copies a number from anywhere, A window Popup will come and show "Call ######?" with a Call and Cancel Button....

C#
public partial class Form1 : Form
 {
     string LastClipBoardText = "";
 private void timer2_Tick(object sender, EventArgs e)
     {


         List<string> phone_nums = new List<string>();
         if (Clipboard.ContainsText())
         {

             if (LastClipBoardText != Clipboard.GetText(TextDataFormat.Text))
             {
                     LastClipBoardText =  Clipboard.GetText(TextDataFormat.Text);
         //Some code here
     }
      }
 }
   }

I am using LastClipboardText to avoid checking again and again for the same data. and It works well...
Problem comes, when a customer again copies the same text with mouse... :D He expects the window again to show up; But won't, as it is the same data stored in LastCLipboardText....

Is there any idea to solve this issue? Can I get the copied time from clipboard ???
Posted
Updated 2-Oct-13 23:30pm
v2

I think you'll have to use some p/invoke:

C#
[DllImport("User32.dll", CharSet=CharSet.Auto)]
public static extern IntPtr SetClipboardViewer(IntPtr hWndNewViewer);


See this [^] article on how to set up a clipboard monitor in c#. Basically you register your app as a clipboard viewer using

C#
_ClipboardViewerNext = SetClipboardViewer(this.Handle);

and then you will recieve the WM_DRAWCLIPBOARD message, which you can handle by overriding WndProc:

C#
protected override void WndProc(ref Message m)
{
    switch ((Win32.Msgs)m.Msg)
    {
        case Win32.Msgs.WM_DRAWCLIPBOARD:
        // Handle clipboard changed
        break;
        // ... 
   }
}
 
Share this answer
 
Comments
Yesudasan Moses 3-Oct-13 6:12am    
Wow.... That is very cool & working.... Thanks so much dear friend :)
Yesudasan Moses 3-Oct-13 6:18am    
That replaced my timer too.... :)
I suggest you learn about GlobalHooks in .NET: [^].

If the end-user triggers your GlobalHook action by copying some text, and then pressing some keyboard combination: you have the great advantage that you don't have to parse every single number the user copies, and your code doesn't have to respond to every single copy to the clipboard, no matter what object is being copied.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900