Desktop Wallpaper Location -> HKCU\Control Panel\Desktop\Wallpaper
Though this is not the most reliable method since some people (me) don't use wallpapers. It'd be much better to grab the desktop's hWnd and copy it into a bitmap object.
Brainstorming time!
Using native .NET code...and totally untested...
- Code: Select all
System.Drawing.Bitmap bmp = new Bitmap(Screen.GetBounds().Width, Screen.GetBounds().Height);
System.Drawing.Graphics bmpGR = new System.Drawing.Graphics.FromImage(bmp);
bmpGR.CopyFromScreen(new Point(1,1), new Point(0,0), Screen.GetBounds().Width, Screen.GetBounds().Height, CopyPixelOperation.SourceCopy); //Though not sure on this line, going from memory here...
Though, I'm not sure if this grabs the icons and start menu as well, but if it does, then I have another idea. Look at the registry key above, see if the user is using a desktop image, and if so, use that as the background. If the key is empty, then grab a group of pixels randomly from the desktop and hope that if they all match, that's the desktop color. I say random pixels, because you never know how icons are arranged on the desktop. Something like this:
- Code: Select all
int[] rndPixels = new int[10];
bool match = false;
while( !match ) {
for( int i = 0; i < 10; i++ ) {
rndPixels[i] = bmp.getpixel(rnd() * Screen.GetBounds().Width, rnd() * Screen.GetBounds().Height);
}
int count = 0;
for( int i = 0; i < 9; i++ ) {
if( rndPixels[i] == [i + 1] )
count++;
}
if ( count >= 3 ) // if at least 3 match, we've probably found the desktop color...I think :P
match = true;
}
As for grabbing icons, I think windows uses a listview so it should be possible to get the desktop handle, and then use FindWindowEx with SysListView or something like that to grab the listview handle. After that, we would probably have to loop through each icon getting each DC, and then create a bitmap for each one...No pseudo-code for this one, I'm too tired...
At least, that should work to grab the desktop and the Icons.