How to register a global hotkey for your application in C#

How to register a global hotkey for your application in C#

Register a hotkey for your application that can be triggered even if your form is minimized and does not have focus. More »

Visual Studio 2013

Visual Studio 2013

Visual Studio 2013 is now available. Make sure to upgrade to the latest version of Visual Studio. More »

How to download a file in C# (progressbar and download speed)

How to download a file in C# (progressbar and download speed)

Learn how to download files in C# while displaying the percentage and the download speed. More »

UDP hole punching implementation in C#

UDP hole punching implementation in C#

Learn how to implement UDP hole punching so you can make your clients life a lot easier by not forcing them to open ports on their end. More »

 

Disable all caps menus in Microsoft Visual Studio 2012

If you are interested in changing the Visual Studio’s 2012 menu from this

Visual Studio 2012 menu all caps

to this

Visual Studio 2012 menu normal
Follow the instructions below.

How to disable all caps.

  1. Open up regedit. (Start -> Run -> Type regedit)
  2. Navigate to HKEY_CURRENT_USER\Software\Microsoft\VisualStudio\11.0\General.
  3. Add a new DWORD value with the name SuppressUppercaseConversion.
  4. Set its hexadecimal value to 1.

That is all, simply restart Visual Studio and the menu should not be in all caps now.

Share on FacebookTweet about this on TwitterShare on Google+Share on StumbleUponShare on LinkedInShare on RedditPin on PinterestShare on TumblrDigg thisPrint this pageEmail this to someone

Monitor clipboard in C#

The best way of monitoring the data in the clipboard through your application is by adding your application’s window to the chain of clipboard viewers so it can receive the WM_DRAWCLIPBOARD message when the clipboard data is modified.

In order to do that we need to make use of the Windows SetClipboardViewer and ChangeClipboardChain APIs in order to monitor when the WM_DRAWCLIPBOARD message triggers.

First we will need to pinvoke SetClipboardViewer and ChangeClipboardChain and WM_DRAWCLIPBOARD and also set the variables that will hold the value for the next window in the chain that is required when we will want to stop our window from monitoring the clipboard. Place the following in your class.

Share on FacebookTweet about this on TwitterShare on Google+Share on StumbleUponShare on LinkedInShare on RedditPin on PinterestShare on TumblrDigg thisPrint this pageEmail this to someone

UDP hole punching implementation in C#

UDP hole punching is a method that is used to establish connectivity between two hosts that are behind a NAT (router) without the need of having the clients port forward specific ports.

When the client sends a UDP packet to the server the router creates a temporary rule mapping, the server then uses the incoming IP address and port it receives the message from to send a message to the client, which refreshes (in most cases) the lifetime of the temporary mapping on the client’s router and allows the server to communicate constantly with the client without the need for the user to do anything from their side.

This method is also used to send messages between two users that are behind different NAT’s. The difference in the implementation is that the clients first contact with the server, which should have a port open in order to be able to receive the information from the clients. After the server receives the information from the clients it sends each client the IP and port of the other client, allowing both of them to communicate with each other.

I’ve created a small example on how the implementation of a UDP hole punching looks in C#, this should give you the general idea of how it works and let you expand it as you like. The example simply receives a message from the client then sends a response. If you want the server to handle more than one message then you will need to add some loops.

Share on FacebookTweet about this on TwitterShare on Google+Share on StumbleUponShare on LinkedInShare on RedditPin on PinterestShare on TumblrDigg thisPrint this pageEmail this to someone

Force Firefox 20 to use the old download manager

Mozilla released Firefox 20 a few days ago that came with various new features such as:

  • a new per-window Private Browsing feature
  • a new download manager
  • the ability to close unresponsive plugins without the need to restart the browser

Sadly my personal opinion about the new download manager feature isn’t very good. The new manager seems to be very user unfriendly and from what I can see there isn’t an option in the settings to clear a download file from the history automatically after the file has been downloaded. Luckily there is an easy solution for this for those that would like to revered back to the old download manager design.

  1. Type about:config in your address bar
  2. Search for browser.download.useToolkitUI
  3. Set its value to true

Now everytime you download something the old version of the download manager will start instead of the new one.

browser.download.useToolkitUI

If you also want to remove the new download button that was added in this new version simply right click on the bar, click Customize… and drag and drop the button you don’t want into the customize toolbar list that will appear.

Share on FacebookTweet about this on TwitterShare on Google+Share on StumbleUponShare on LinkedInShare on RedditPin on PinterestShare on TumblrDigg thisPrint this pageEmail this to someone

How to hash a string with salt using a multi-algorithm method

It is considered a very bad idea to store user credentials in plain text, especially passwords. For that very reason it is always a good idea to hash passwords before you store them, ideally with a unique salt that you can store in another location. That way if for whatever reason your database is compromised your users passwords will not be in plain text and it will require a bit of work in order to find out what each password is, especially if the salt for each password is stored somewhere else.

The following method is a multi algorithm method, that means that with this single method you can use more than one algorithm to hash your data. The snippet below shows an example how to hash your data with a single method using seven different algorithms.

Our main method that will do all the work for us:

Share on FacebookTweet about this on TwitterShare on Google+Share on StumbleUponShare on LinkedInShare on RedditPin on PinterestShare on TumblrDigg thisPrint this pageEmail this to someone