Write simple Debug helpers to help you debug and maintain your code

Much of my time is spent using the Visual Studio debugger examining code to figure out how it works and how to fix it. When stepping through a function, the values the function uses are very useful for code understanding. The debugger shows these values in the Watch/Locals/Auto/Callstack windows.  For example, the Locals window shows…

3

You can use HWndHost to host a Win32 HWnd window inside a WPF element

  Suppose you have some old code lying around that creates a Win32 window with an HWnd (perhaps ATL, MFC, or just C/ C++). For example, if you type some erroneous code into a VB application in Visual Studio:           Dim x=4: catch ex As Exception     The “Exception” will be squiggled and…

2

Dynamically load a DLL from a runtime specified path

When running VB.Net or C# code, often it’s useful to call native code. One way is using PInvoke. (for other ways, see How fast is interop code?)   For example, you can call GetWindowText to get the title of a window. To get it’s managed signature, you can use this code from http://www.pinvoke.net/default.aspx/user32/GetWindowText.html      …

0

Synchronize your files across machines with Mesh

I have a collection of almost 30,000 pictures and videos. When I add new pictures to the collection, I had been running a script file to synchronize the collection across various machines.     for %%s in (\\calvinh6\e$ \\calvinh3\e$ \\calvinh4\e$) do (                 robocopy  /s /fp %2 %1 %%s\pictures\%1                 Echo done 2 )  …

13

Magnify your pictures using a PictureBox so that you can zoom with the Mouse Wheel

Today’s digital cameras take pictures with much higher resolution than many computer screens. My Canon PowerShot SD800 IS camera takes pictures at 3072 x 2204 resolution.   One of my laptops died recently, and I noticed that local laptop retailers have machines with 1280 X 1024 resolution. I much prefer a higher resolution display, so…

18

Make your code more maintainable: The evils of the Return statement

What does it mean to make code more maintainable? Certainly obfuscated code is hard to understand, by definition.   A big part of maintainability is making it easier for others to read and understand what the code is doing. Your code may have been working for years, but then somebody comes along and wants to…

9

Cellular Automata: The Game of Life

I remember my dad getting a copy of Scientific American magazine every month when I was a kid. He kept back issues on a shelf in our living room. I remember being fascinated by the issue (Oct 1970) which described John Conway’s Game of Life.   A few decades later, in the mid 80’s I…

5

A WPF version of the Typing Tutor game

In my prior post I show a Windows Form version of the typing tutor game.   Here is a WPF version. Start Visual Studio 2008. Choose File->New->Project->VB->WPF Application. Dbl-Click the form in the designer to open the code window. Paste in the code below.   Notice how the logic differs from the WinForm version. In…

2

The VB WinForm version of the typing tutor game

In this post, Create your own typing tutor! is code to create a game for learning the letters of the keyboard by typing the letters that fly across the screen. As times goes by, they fly faster.   Below is a VB version of the game. Can you score higher than 3000?   Start Visual…

4

Use a dictionary to help create a mnemonic

I was using a program that was yet another TLA and I wanted to create a mnemonic to help me remember what it was. One of the letters was “k”, so I wanted to find a word that starts with “k”   Simple: load a dictionary, search for words starting with “k” and browse through…

2