title: sendkey enter to a pop up on application in c#
body: <p>I am trying to close this startup pop up in program by sending an enter key programmatically. I have followed some of the examples in this site about creating a class within the same namespace to handel this, but I don't know how to use it in main form. check the code below from the sendkey class. thank you in advance</p>
  
  <pre><code>class winhandler
  {
      [DllImport("user32.dll", SetLastError = true)]
      private static extern uint GetWindowThreadProcessId(IntPtr hWnd, out uint procId);
  
      [DllImport("user32.dll", SetLastError = true)]
      private static extern IntPtr FindWindowEx(IntPtr hwndParent, IntPtr hwndChildAfter, string lpszClass, string lpszWindow);
  
      [DllImport("user32.dll", SetLastError = true)]
      private static extern bool SetForegroundWindow(IntPtr hWnd);
  
      public const uint WM_SETTEXT = 0x000C;
      public const uint WM_GETTEXT = 0x000D;
      public const uint EM_SETSEL = 0x000000B1;
      public const uint WM_GETTEXTLENGTH = 0x000E;
      public const uint SMTO_ABORTIFHUNG = 0x0002;
      public const int BM_CLICK = 0x00F5;
  
      string title = "Card ....";
      public void cancelwindows()
      {
          IntPtr hWnd = FindWindowEx(IntPtr.Zero, IntPtr.Zero, null, title);
  
          uint loginWindowProcId;
          uint loginWindowThreadId = GetWindowThreadProcessId(hWnd, out loginWindowProcId);
  
          // now I can just use .NET to find the Process for me...
          Process loginWindowProcess = null;
  
          if (0 != loginWindowProcId)
          {
              loginWindowProcess = Process.GetProcessById((int)loginWindowProcId);
              loginWindowProcess.WaitForInputIdle();
              SetForegroundWindow(hWnd);
              SendKeys.SendWait("{ENTER}"); 
          }
      }
  }
  </code></pre>