SHARE
TWEET

Untitled

a guest Feb 14th, 2013 382 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Windows.Forms;
  9. using System.Runtime.InteropServices;
  10. using WindowsInput;
  11.  
  12. namespace TesteLibrary
  13. {
  14.     public partial class Form1 : Form
  15.     {
  16.         [DllImport("user32.dll", SetLastError = true)]
  17.         static extern IntPtr FindWindow(string lpClassName, string lpWindowName);
  18.  
  19.         [DllImport("user32.dll")]
  20.         private static extern bool SetForegroundWindow(IntPtr hWnd);
  21.  
  22.         [DllImport("user32.dll")]
  23.         private static extern IntPtr SendMessage(IntPtr hWnd, int Msg,
  24.             IntPtr wParam, IntPtr lParam);
  25.  
  26.         [DllImport("user32.dll", EntryPoint = "WindowFromPoint",
  27.             CharSet = CharSet.Auto, ExactSpelling = true)]
  28.         public static extern IntPtr WindowFromPoint(Point point);
  29.  
  30.         public Form1()
  31.         {
  32.             InitializeComponent();
  33.         }
  34.  
  35.         private void button1_Click(object sender, EventArgs e)
  36.         {
  37.             IntPtr hWnd = (IntPtr)FindWindow("notepad.exe", null);
  38.             SetForegroundWindow(hWnd);
  39.             //InputSimulator.SimulateKeyPress(VirtualKeyCode.F1);
  40.  
  41.             var screenPoint = this.PointToScreen(new Point(1210, 460));
  42.             var handle = WindowFromPoint(screenPoint);
  43.  
  44.             if (handle != IntPtr.Zero)
  45.             {
  46.                 SendMessage(handle, 0x0204, IntPtr.Zero, IntPtr.Zero);
  47.                 SendMessage(handle, 0x0205, IntPtr.Zero, IntPtr.Zero);
  48.             }
  49.  
  50.         }
  51.     }
  52. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top