How to get the current windows wallpaper in C#

Being able to make software is great. Not only because you can make a living from it, but also because it helps you in everyday life. Like when you have to manage your 10k+ wallpaper library. I for once always get baited by these “575 awesome wallpapers you absolutely need” posts and download them right away into my library. Every now and then a black sheep sneaks in but i only see it after it pops up on my Desktop (as if i would review all of these 575 wallpapers).

And here it comes together: as a software developer i have the means to write a small piece of code that gets rid of these ugly wallpapers.

So i hacked this snippet that moves the current wallpaper out of its current folder and into a “reject” folder.
The current wallpaper path can be found in a registry entry “TranscodedImageCache” in “HKCU\Control Panel\Desktop” (at least in Windows 8.1). It’s encoded with unicode though and has to be cleaned a little bit.

Continue reading


Find File Snippet – Depth First And Breadth First Search

Two usefull snippets, if you need to do a quick file search, here a recursive and a breadth first implementation (ignored the not-authorized-exception):
(took me only 2 mins, love .Net 🙂

Depth First Implementation:

static string[] FindFile_DepthFirst(string directoryName, string fileName)
{
   return Directory.GetFiles(directoryName, fileName, SearchOption.AllDirectories);
}

Breadth First Implementation:
Continue reading


Update GUI Control From Non-GUI-Thread Without Marshalling

In .Net when you want to update a GUI Control, for example a ListView, you have to execute your update code in the GUI Thread which controls your Form and its child GUI Objects. While you are in another Thread, you call the Invoke or BeginInvoke (for async.) method of your GUI Control for this purpose. You pass this method a delegate of your method, which contains your update code, and the GUI Thread invokes the method that is passed. Well the whole story is infact much more complicated and this article gives you a nice in-depth view on this topic:
WinForms UI Thread Invokes: An In-Depth Review of Invoke/BeginInvoke/InvokeRequred

 

This is how Microsoft wants us to manage our GUI stuff, Continue reading


How to Upload a Folder Recursive to FTP and display the Progress

I found a nice open-source FTP-Library that can upload files, change the directory etc.  (ftpLib.cs was originally written by Jaimon Mathew and modified by Dan Rolander and others).

But it lacks the feature to upload a Directory recursiv, therefore i coded a class with some Extension Methods.

I also made up a small Example:

Continue reading


SaveProgress Example for DotNetZip

When i was coding Send2FTP i needed a ZIP-Library that would be able to notify me about the progress while the compression.

After a littlebit research i found DotNetZip a really impressive ZIP Libary for dotNet.

But what i couldn’t find was a good WinForms example for the Save Progress Event. I Also don’t like to deliver my application with alot of dll’s therefore i packed the sources of DotNetZip into the Example.

So i made a small WinForms Example for implementing the SaveProgress Event of the DotNetZip Library and want to share it with you:

Continue reading


RarClicker

I often encounter a problem when downloading my daily tv show in form of rar parts. When doing that i want to open the video file already while downloading (like streaming).

Therefore i made up a small application that clicks the button of the rar application every 1,5s.

Winrar

Because of that i can watch the partial extracted movie with VLC (i guess several other players can do that too).

The code of the Application basically consists of two functions:
Continue reading


How to get Main Window Handle of the last active window

While developing a litte application for Windows 7 in C# i encountered the problem that i needed to focus the last window after i started my application. Althought my application was closing after execution immediately, focus was not recurring to the last window because i was starting my application from the windows taskbar. For fixing this side-effect, i needed to find out, which window was active before my programm was “born”. So i did some googling for finding out how to get the previously active window handle in windows 7. In almost every thread, it was recommended to “listen” to window activation changes, and save the previous handle in a variable or so. But in my case, i wanted to avoid, running the programm permanently, or run anything in the background..
Continue reading