“方法没有重载'WndProc'需要0个参数”

时间:2013-04-25 03:38:09

标签: c#

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之后缺少()中的某些内容,但我不确定是什么 ...有人可以帮忙吗?

2 个答案:

答案 0 :(得分: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);
    }

答案 1 :(得分:1)

当我在Windows消息处理程序中放置一个断点时,我注意到当背景发生变化时,它会收到一个42而不是20的Wparam,它可能是Bits的组合,所以你可以试试这样的东西。

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);

}

如果您想要使用计时器轮询更改,可以创建一个Message,然后像这样调用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);

}