Ver Mensaje Individual
  #1 (permalink)  
Antiguo 07/09/2011, 00:37
ll2121
 
Fecha de Ingreso: agosto-2011
Mensajes: 18
Antigüedad: 12 años, 8 meses
Puntos: 0
Pregunta Codigo para detectar el mouse en cualqueir parte de windows

hola, tengo un codigo q cuando doy click ya sea izquierdo o derecho en cualquier parte de windows, deberia retornar el programa y el nombre del archivo, por ejemplo, un archivo de word, deberia retornar Microsoft Word - Documento1, pero lo q me retorna es "Program Manager", el codigo es el siguiente

public partial class Form1 : Form
{
[DllImport("user32.dll", CharSet = CharSet.Auto, ExactSpelling = true)]
public static extern IntPtr GetForegroundWindow();

[DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = true)]
static extern int GetWindowText(IntPtr hWnd, StringBuilder lpString, int nMaxCount);

[DllImport("User32.dll")]
private static extern short GetAsyncKeyState(System.Windows.Forms.Keys vKey);

public Form1()
{
InitializeComponent();
}

private void Form1_Load(object sender, EventArgs e)
{
Timer1.Interval = 10;
}


private void retVentanaActiva()
{
try
{
IntPtr handle;
StringBuilder Buffer = new StringBuilder();

handle = GetForegroundWindow();
if (handle.ToInt32() == 0)
retVentanaActiva();

GetWindowText(handle, Buffer, 255);

label1.Text = ">>se hizo click en : " + Buffer;
}
catch (Exception) { }
}

private void timer1_Tick(object sender, EventArgs e)
{
if (GetAsyncKeyState(Keys.LButton) == -32767)
retVentanaActiva();

if (GetAsyncKeyState(Keys.RButton) == -32767)
retVentanaActiva();
}

}