Reputation: 2584
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();
}
I know that I'm missing something that goes in the () after WndProc, but I'm not sure what... Can someone help?
Upvotes: 0
Views: 230
Reputation: 54532
When I put a breakpoint in the Windows Message Handler I noticed when the background changes it is receiving a Wparam of 42 not 20, it probably is a combination of Bits so you can try something like this.
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);
}
If your are wanting to poll for changes with a timer you can create a Message then call the WndProc Method like this.
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);
}
Upvotes: 1
Reputation: 3840
You don't need a timer to check for changes, that's the job of 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);
}
Upvotes: 1