0

Recently I’ve been working on a windows wallpaper manager. It will scan multiple directories for images and have a settings window to customize. In addition, I want to bypass the built-in wallpaper and instead use a windows form based off the ideas discussed here: Setting a Windows form to be bottommost to allow for greater control over image placement. I have built the file operations to find the wallpapers, and various other support operations. However, I am stumped on how to implement a windows form properly. Not just the one in the Stack Overflow post above. So far none of my CompSci classes (7 so far) have discussed GUIs, and thus I have no knowledge to work from. I turned to the internet to learn how to work with GUIs. While I learned plenty to start a thread, or show a form, I was never able to find anything that described the proper way to engineer an application with a GUI. All I have learned in respect to engineering the application is to limit the number of threads, and try to separate the GUI from the non-GUI related code (if that makes sense).

Like I have said, I have no clue what I am doing. If someone would be willing to give me pointers or even a link to something on this subject, that would be amazing!

EDIT: I have been using this as a learning exercise, and I have mostly been learning from trial and error, probably mostly error

Community
  • 1
  • 1
techfreek
  • 3
  • 3
  • 1
    As far as I can tell, this will not work for you. Your bottommost form will still be on top of the desktop and its icons hiding them from view which is not what you are looking for. If you want to learn about WinForms just look for a beginner's tutorial. However, WPF is much more prevalent these days so I'd suggest you learn that. – o_weisman Jan 16 '14 at 07:40
  • Thank you! I will be sure to look into that. I've mostly been experimenting with how to build it, and happened to stumble across winforms. – techfreek Jan 16 '14 at 07:48

1 Answers1

1

To draw on the true desktop, you need to get a handle to it: GetDesktopWindow is the function to use. But to change the wallpaper you do not draw on the desktop, but instead you use the dedicated API for handling the desktop wallpaper: SystemParametersInfo(SPI_SETDESKWALLPAPER, ...). There is also the legacy COM Shell interface, IActiveDesktop and IActiveDesktop::SetWallpaper.

As you can see, none of the APIs to manipulate the desktop and the wallpaper are managed (C#, .Net) so you will have to jump through some hoops to get this working from C#. If your goal is to learn C# style UI, I would recommend to stick to the 'blessed' way of doing this (winforms, WPF etc) and do not try to jump straight to p-Invoke and COM interop. Perhaps you can pick another project, eg. display the images/pictures in a carousel in a form.

If you're curious still, Google for C# and SystemParametersInfo or IActiveDesktop and you'll find examples of how to do this from managed C#, many examples right here on StackOverflow.

Bonus: of course Raymond Chen has a blog on this topic: How do I put a different wallpaper on each monitor?.

Remus Rusanu
  • 288,378
  • 40
  • 442
  • 569