0
protected override void WndProc(ref Message message)
    {
        if (message.Msg == WM_SETTINGCHANGE)
        {
            if (message.WParam.ToInt32() == SPI_SETDESKWALLPAPER)
            {
                // Handle that wallpaper has been changed.
            }
        }

        base.WndProc(ref message);
    }

    private void check_Tick(object sender, EventArgs e)
    {
        WndProc();
    }

我知道我在 WndProc 之后的 () 中遗漏了一些东西,但我不确定是什么......有人可以帮忙吗?

4

2 回答 2

1

您不需要计时器来检查更改,这是 WndProc 的工作:

    private static readonly UInt32 SPI_SETDESKWALLPAPER = 0x14;
    private static readonly UInt32 WM_SETTINGCHANGE = 0x1A;

    protected override void WndProc(ref Message message)
    {
        if (message.Msg == WM_SETTINGCHANGE)
        {
            if (message.WParam.ToInt32() == SPI_SETDESKWALLPAPER)
            {
                // Handle that wallpaper has been changed.]
                 Console.Beep();
            }
        }

        base.WndProc(ref message);
    }
于 2013-04-25T04:02:38.603 回答
1

当我在 Windows 消息处理程序中放置断点时,我注意到当背景发生变化时,它接收到的 Wparam 为 42 而不是 20,它可能是位的组合,因此您可以尝试这样的事情。

protected override void WndProc(ref Message m)
{
    if (m.Msg == WM_SETTINGCHANGE)
    {
        if ((m.WParam.ToInt32() & (int)SPI_SETDESKWALLPAPER) == SPI_SETDESKWALLPAPER)
        {
            // Handle that wallpaper has been changed.
        }
    }

    base.WndProc(ref m);

}

如果您想使用计时器轮询更改,您可以创建一条消息,然后像这样调用 WndProc 方法。

private void timer1_Tick(object sender, EventArgs e)
{
    Message m = new Message();
    m.Msg = (int)WM_SETTINGCHANGE;
    m.WParam = (IntPtr)SPI_SETDESKWALLPAPER;
    WndProc(ref m);

}
于 2013-04-25T04:19:18.470 回答