July 2006 - Posts

VS Tip #2: Easier File Navigation

If there's one thing I hate when programming it's having to switch between the keyboard and the mouse constantly. A while ago I posted a tip to switch open files more easily without using the mouse.

That's useful but since then I've set up another shortcut - this time to open any file, both existing and unopened files, without using the mouse.

The trick is to set up a shortcut key to the Solution Explorer. You do this in Tools/Options in the Environment/Keyboard area. Find View.SolutionExplorer and set up a shortcut key to something like Ctrl+; (semi-colon) - as this isn't used for anything else.

Then, no matter where you are, you can press Ctrl+; to set focus to the solution explorer. Then comes the trick, rather than using the mouse to select a file to open you can just type in the first few characters of the file you want. This finds the file in the solution explorer and selects it. Then press F7 or Enter to open the file and continue editing.

Voilla - you've now got a shortcut key to open any file without using the mouse.

Hope you find it useful.

Shareware Developers: A Registration Service that Rocks

A couple of weeks ago I was looking for a company that would accept credit cards and fulfill orders for shareware products - generating registration keys, providing some level of support and generally being reliable and helpful.

After reearching about 10 different registration services, I finally found one that I was happy with: BMT Micro Software Registration Services.

My intiial research involved sending each service company an email asking them if they can provide some details about how I might integrate my custom key generation software with their system. It was a short email.

Several just ignored my email. Some wrote back with either a simple link or some standard verbiage that didn't really answer my question. And when I asked them to clarify they didn't respond. My gut feeling was - if they're not willing to help me at this stage, they certainly won't be willing once I have the account set up.

However BMT Micro not only responded within the hour, but they sent me what seemed to be a personal, detailed explanation that directly answered my question. They offered to help more. Each response came just minutes after I hit the send button.

I had the account set up in about 10 minutes. No charge whatsoever.

Over the next couple of days we had a dozen or so emails back and forth (including over the weekend), each providing prompt and very detailed responses to my queries. With their help getting the key generator set up was a breeze, far easier than I imagined.

When you log in to their vendor area you feel like they've thought of everything - ways to pass in test orders, pricing tiers, discount coupons, gift certificates, custom order forms - you name it, they support it.

Their helpfulness didn't just stop after my intiial order page was set up - they would even go beyond that and make suggestions about how to improve the registration process I had come up with. How about that for customer service?

Overall they were extremely helpful and I highly recommend them.

Note - I do not represent and have absolutely no affiliation with the BMT Micro.

If you want more information just go to their website: www.bmtmicro.com.

Transparent RichTextBox in C#

I've come across countless articles in the past explaining how to implement a transparent background in a RichTextBox control. I was disappointed to find that they're all terribly complex, and incredibly slow.

While researching the problem I stumbled across a far easier way to implement this in just a few lines of code.

The real problem isn't so much that the RichTextBox doesn't support transparency, it's that .Net uses an old version of the RichEdit control.

It seems there are 4 versions of the RichEdit control out there - when I'm talking about the RichEdit control, I'm talking about the C DLL that either comes with Windows or some version of Office. The files are named either RICHEDXX.DLL (XX is the version number), or MSFTEDIT.DLL and they're in the System32 folder.

.Net RichTextBox control is bound to version 2. The biggest problem with this version (at least for me) is that it does not render properly if you try to make the window transparent. Later versions, however, do.

We can fix that. If you create a control deriving from the original RichTextBox control, but overriding the CreateParams property, you can put in a new Windows class name (this is the window class name, nothing to do with classes in the C# sense). This effectively gives us a free upgrade. When the .Net RichTextBox control instantiates, it will now use the latest RichEdit control and not the old, archaic, version 2.

There are other benefits too - version 3 and beyond of the RichEdit control support quite an extensive array of layout features, such as tables and full text justification. This is the version of the RichEdit that WordPad uses in Windows XP. To really see what it's capable of displaying you can create documents in Word and save them in RTF, load these into the new RichEdit and in a lot of cases it'll look identical, it's that powerful. A full list of features can be found here:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/shellcc/platform/commctls/richedit/richeditcontrols/aboutricheditcontrols.asp

There are a couple of caveats.
1. The control that this is bound to was shipped with Windows XP, and so this code won't work in Windows 2000 or earlier.
2. The RichTextBox control in C# only knows about version 2, so the interface doesn't include all the new features. You can wrap a few of the features yourself through new methods on the RichEdit50 class. I may implement a few and post them at a future date. nb - I've noticed that SelectedFont also doesn't seem to report the correct values in this version.

The code is as follows:

public class RichEdit50 : RichTextBox
{
 [DllImport("kernel32.dll", CharSet=CharSet.Auto)]
 static extern IntPtr LoadLibrary(string lpFileName);

 protected override CreateParams CreateParams
 {
  get
  {
   CreateParams prams = base.CreateParams;
   if (LoadLibrary("msftedit.dll")!=IntPtr.Zero)
   {
    prams.ExStyle |= 0x020; // transparent
    prams.ClassName = "RICHEDIT50W";
   }
   return prams;
  }
 }
}

Just replace you references to RichTextBox with RichEdit50 and you'll be rolling. Because it's transparent you will need to create some kind of background on the control behind the RichTextBox - draw a gradient or something to get some cool effects. Of course if you just want the features of the RichEdit without transparency, comment out the line that ends with '// transparent'.

Have fun.

---

Download a free trial of Priorganizer the to-do list application, featuring hierarchical tasks: fast, powerful yet very simple to use.

WinFS and Microsoft's Missed Opportunities

The Internet is so vast that the only real way to realize its usefulness is through search. These days when people want to find something out they go straight to their computer. They go through layer upon layer of Microsoft software, all those mouse moves, clicks and keypresses, to get to what? Google.

If I were Bill Gates there'd be a few more holes in the walls at Microsoft.

1. The user turns on the computer and 90% of the time they're going into Windows. At this point, can they search the Internet ? No.

2. So they double click Internet Explorer. At this point can they get what they want? It seems not.

3. They're taken to msn.com. This is a portal that offers a search capability. But is this good enough for the consumer? It appears not.

4. They go to Google. Using Internet Explorer, Microsoft's own browser software, and DHTML, a technology Microsoft mostly pioneered. Isn't that a slap in the face?

Those are very real opportunities that Microsoft have missed to get customers.

I read the other day that Gartner think Microsoft missed an opportunity to turn their killing of WinFS into a public anouncement reinforcing their focus on Live services. What this means is, they think the reason Microsoft dumped WinFS was because it just isn't needed considering most people these days work in the browser and not on their own filing system.

I really don't agree with them. Search is a very primitive way to find information. WinFS was a very innovative move towards making information organization more efficient, improving the exposure of file metadata and linking it together in ways that search cannot. We need to move beyond search. Ideas like WinFS represent new opportunities for Microsoft. This is client-rich technology that Microsoft does best. Dropping it or putting it on the backburner was a bad idea.

If Microsoft can innovate beyond search and integrate this into the operating system, then they will capture a whole new customer base at stage 1 - before they even click on Internet Explorer.

Given this is all it would take to derail Google, remind me again why Google's stock price is so high?