Linked Questions

Popular Questions

GetMessage API for another process like Spy++

Asked by At

I'm trying watch other process if window is flashing.

I tried to GetMessage API in user32 but it doesn't gets any message from given handle. I'm trying catch the "message 0x0118" it is appears in spy++ when window is started

[DllImport("user32.dll")]
static extern int GetMessage(out tagMSG lpMsg, IntPtr hWnd, uint wMsgFilterMin, uint wMsgFilterMax);

var p = Process.GetProcessesByName("process").FirstOrDefault();
tagMSG msg = new tagMSG();
DWORD res = 1;
while (res != 0)
{
    res = GetMessage(out msg, p.MainWindowHandle, 0, 0);
    if (res == -1)
    {
        Console.Write("-1");
    }
    else
    {
        if (msg.message == 0x0118)
        {
            Console.WriteLine("flashing");
        }
        else
        {
            Console.WriteLine(msg.message.ToString("x2"));
        }
    }
}
class POINT
{
    public long x;
    public long y;
}
class tagMSG
{
    public HWND hwnd;
    public UINT message;
    public WPARAM wParam;
    public LPARAM lParam;
    public DWORD time;
    public POINT pt;
    public DWORD lPrivate;
}

using HWND = System.IntPtr;
using UINT = System.UInt32;
using WPARAM = System.IntPtr;
using LPARAM = System.IntPtr;
using DWORD = System.Int32;

when run this code, it stops at GetMessage line and waiting for message but message never coming. I was compared Handle in spy++ with p.MainWindowHandle is equals. Note: Running visual studio as administrator

Related Questions