Posts

Showing posts from October, 2009

MFC reading and writing from the registry

After spending some time today coding in MFC I realized I had to store some values in the registry. I haven't done this in a while and didn't find much help on the net so I am adding my experience to hopefully help some folks out. It used to be you had to use the Get/Write private profile string methods in the Win32 API. MFC has made that easier with the CSettingsStore class. This is a new class in the MFC feature pack. So to use it you have to have service pack 1 installed for visual studio 2008. To use the class all you have to do is create an instance of that class and you can use it's methods to read,write,create, and pretty much do whatever you want in the registry. So let's look at some code that does some stuff in the registry. We're going to create/open a new key and write some values to it // let's create a new pointer to our registry class // Sadly the MSDN MFC documentation seems to be wrong // on the constructor logic. // This will put

Visual Studio Tips & Tricks - Part Three Keyboard Shortcuts

Visual Studio has a keyboard command for just about everything. Many coders find having to move their hand away from their keyboard to their mouse slows them down. I agree and always look for a quick way to do something via the keyboard since I'm typing most of the time anyway. Let's start with the complete list from Microsoft. Visual C# 2008 Bindings Visual C# 2005 Bindings Visual Basic 2008 Bindings Visual Basic 2005 Bindings A few of my favorites are: * Ctrl-Shift-B: Build Solution (I'm an old VC coder so mine is set to F7) * Ctrl-. (period): Show "Add Using/Imports" dropdown for unknown types. * Ctrl-K, C: Comment Selection * Ctrl-K, U: Uncomment Selection * Ctrl-K, F: Format Section * Ctrl-K, D: Format Document * Ctrl-Space: Show Intellisense List * Ctrl-Shift-V: Paste Loop - Hit Multiple Times to paste through the list of recent 'copies' * Ctrl-F: Simple Find * Ctrl-Shift-F: Find in Files * Ctr

Visual Studio Tips & Tricks - Part Two Conditional Breakpoints

Image
Many people know and love the debugger in Visual Studio. Being able to set a breakpoint to stop execution at a certain line in code is invaluable. However many times you find yourself only wanting to stop when a certain condition has been meet. So often you find yourself stepping through many lines of code until you reach the desired result. The solution to this is a conditional breakpoint. VS lets you set conditions on breakpoints so they only stop when that condition is met. So let's take a look at a quick example. This is a small console app that prints numbers from 1 to 10. However we want it to stop when the loop counter is equal to 5. First we set a breakpoint on the Console.Write method. So now we have a standard breakpoint set. Now to make it conditional right click on the breakpoint which brings up a context menu. Select the Condition menu item to bring up the Condition dialog box where we can set our condition. VS is pretty smart and in 2008 (not sure abo

Visual Studio Tips & Tricks - Part One Formatting

Image
This is a departure from my regular blogging about code but I find that there are many little tips and tricks you can use in VS that make it easier to use. Not that it's a bad product but there are little things that can allow you to work faster and be just a bit more productive with less effort. As a very lazy coder I find that invaluable. This post or series of posts will cover a wide variety of things but hopefully it will help some people out. First let's mess with some options in Visual Studio. The first thing I do in VS is to turn on word wrap and line numbers. To access these you need to get into the options. So in the main menu select Tools -> then options This will bring up an Options dialog box with a tree view on the left with a whole slew of options. For now we're going to focus on the Text Editor section. Expand the Text Editor node and select the language you are interested in. I have selected C# here for my example. On the right hand side you