Keyboard

Illustration

I accidentally “de-enterized” keyboard on my laptop (HP 6730b). Somehow one CD left in my backpack managed to get under my enter key. Plastic beneath could not handle pressure and small piece went off. Although that piece had less than two millimeters in length, my enter key would not stay in it’s place with it missing.

Solution was simple and new keyboard (~40 €) arrived in two weeks (it may seem long, but this is quick for Croatia). Once I decided that I was competent enough to replace it, I took a look at documentation on how to do it.

I was surprised - not only that there was great manual, but there were also videos on how to perform small-scale part replacements.

Keyboard was replaced in less than ten minutes without a hitch. I finally got my enter key back and good feeling about Hewlett-Packard. Although they did nothing other than put some documents on-line, those documents were so good that they made me happy customer.

My next laptop will also be HP.

64-Bit, Where Art Thou

Illustration

Well, presentation is over. I must confess that it was really strange feeling speaking and not seeing anybody. It is so unnatural.

It wasn’t without hitch (even incorrect code was working by accident) but hopefully it was good enough for everybody listening.

Here are source files used during presentation.

I will give link to presentation recording as soon as it goes up.

TechDays

Tomorrow (2009-04-01) I am giving presentation at TechDays virtual conference. Presentation is titled “64-bit where art thou” and it will be about transition to 64-bit framework and issues that can arise. I will try to keep it low on power point and illustrate all through C#.

Windows 7 on High DPI

For “ages”, monitors had resolution of 96 dpi. Every OS and application was designed with it in mind (usually only tested on that resolution). If you buy LCD screen these days, you will see that everything looks a lot smaller. In order to have fine grained picture, pixel density has gone way up. However, your OS still draws everything like it did for years and your eyes are going mad.

Solution is to change DPI to suit your comfort level (usually 125% (120 dpi) is enough). After restart (log off is enough for Windows 7), everything grows a little bit. Applications that are dpi-aware will scale properly and everything should look fine.

Illustration

Old applications that are not aware that 96 dpi is out of fashion, will not look so nice. Most common issues will be some controls that went outside of form bounds and text wrapping at weird places. It can happen that just one button you need is unreachable (notice on this picture, there is also cancel button way to the right - outside of window).

In order to solve this issue, Windows Vista will lie to those applications that everything is still in 96 dpi and then manually scale it (Aero is needed - DWM is culprit). Although this will solve problem with unaware applications, it will also make windows blurry (physics of stretching cannot be avoided). This may seem like a pretty good trade until you became aware that application that knew how to scale in Windows XP gets same blurry treatment (e.g. Visual Studio 2008). Windows Vista assumes that all old applications are DPI unaware and it requires application change to behave “just right” (as easiest solution, you can check ignore DPI on compatibility settings).

Reason behind Windows Vista recognizing all old applications as “problematic ones” is that there is new API in place to assure application is capable of scaling. Since that API hasn’t been there before Vista, applications will not call it. If they do not call it, Vista will think that they cannot scale. Solution is to get new version. Depending on application, that can pose a problem (e.g. there isn’t newer version of Visual Studio 2008 - it doesn’t scale even with service pack applied).

This behavior has changed with Windows 7. Microsoft recognized that most of applications know how to scale and even if they cannot, 25% increase (120 dpi is most common) will trim very little of content. Your application will, for all practical purposes, revert to XP high-DPI behavior.

If you decide to go higher than this (e.g. 150%), DWM will kick back in and scaling will take over. Although this will again make windows blurry (for Vista DPI non-aware applications), it will also make everything fit.

Since DPI settings higher than 120 dpi are not so common, I find this a worthy compromise.

Intercepting Backspace on Windows Mobile

Illustration

Plenty of applications inside mobile windows make use of backspace key. Just imagine how difficult and unintuitive would be to create even simplest folder browser if you could not use that key. However, on smartphone you have just that situation.

Smartphone (or Windows Mobile Standard) is specific in sense that backspace is used as system-wide key for application switching. You can think of it as Tab in normal applications. It is not something you usually override but sometimes overriding that key can prove to be useful. In our desktop application we would just override ProcessCmdKey function or in worse scenario (older frameworks), just override WndProc. This would allow us to intercept those special keys and use them for our own evil purpose.

However, if we try to do this for Smart Device project we have a big problem. Neither of those two functions is supported. Reason is simple - compact framework is trimmed as far as they could go. In my opinion they took it too far.

Those who worked in times before .NET framework, may remember SetWindowLong function and that one of parameters enabled developer to set their own window procedure (GWL_WNDPROC). Fortunately, that is supported (as interop call).

In order to simplify development, I tried to keep it as familiar as possible. Whole idea is to create base form with required WndProc function and later just inherit from it. Whole procedure can be seen from sample, so I will only cover base steps.

Each form that needs to intercept backspace will also need to inherit from WndProcForm. Since WndProcForm inherits from Form, you can safely change that in already existing applications and they should retain their functionality (do not forget to recompile application once you do that - otherwise designer may complain until you can do so). Designer will complain that there visual inheritance is no longer supported for that form (P/Interop is reason) but you may safely ignore that if you don’t have visual components on multiple forms.

After that, simple matter of overriding WndProc and waiting first for WM_HOTKEY and then for both MOD_KEYUP (key is depressed) and VK_TBACK (same code as for escape) will do the job.

Notice that while I only give instructions on one usage, you may use this to intercept any window message going to your window. And that is lot of messages. This is also applicable to Windows Mobile Professional (Pocket PC) for those extended cases (although backspace is not used as switch key there).

Resources