Question

    uMsgNotify = WinApi.RegisterWindowMessage("SHELLHOOK");
    WinApi.RegisterShellHookWindow(this.Handle);

in my Form constructor

and this in my overrided WndProc:

protected override void WndProc(ref System.Windows.Forms.Message m)
{
    IntPtr handle;
    if (m.Msg == uMsgNotify)
    {
        switch (m.WParam.ToInt32())
        {
            case WinApi.HSHELL_WINDOWCREATED:
                handle = m.LParam;
                string windowName = GetWindowName(handle);
                MessageBox.Show(windowName+" "+handle.ToString());
                break;
            case WinApi.HSHELL_WINDOWDESTROYED:
                handle = m.LParam;
                MessageBox.Show(handle.ToString());
                break;
        }
    }
    base.WndProc(ref m);
}

So this Win Form Works fine when default windows shell is explorer.exe. I can get all events All created and destroyed windows and their names. When i set my app.exe as defaul windows Shell. It doesn't receive messages.

Do I have to use dll function injection, separate dll file for hooking? I was trying to get simplier and easier solution.

Any ideas?

Thanks

Was it helpful?

Solution

The WH_SHELL documentation explicitly states:

Note that custom shell applications do not receive WH_SHELL messages. Therefore, any application that registers itself as the default shell must call the SystemParametersInfo function before it (or any other application) can receive WH_SHELL messages. This function must be called with SPI_SETMINIMIZEDMETRICS and a MINIMIZEDMETRICS structure. Set the iArrange member of this structure to ARW_HIDE.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top