.comment-link {margin-left:.6em;}

I Hate Linux

Friday, November 02, 2007

WHS Developer Tip #2: MessageBox alternative

Q: How can I make a more WHS style Message Box like what the Home Server Console uses?

Example:
Example QMessageBox

A: The Windows Home Server team already beat you to it and created the QMessageBox class (Microsoft.HomeServer.Controls, HomeServerControls.dll) which provides a very similar experience to the tried and true MessageBox class... only with a few improvements such as...

Size and Color

One of the first things a programmer testing out QMessageBox will notice is that the dialog is far larger than a regular MessageBox and is formatted to look more WHS like in terms of icons and color and is probably the biggest reason to consider using it (over making ones own dialog from scratch).

Icons

Keeping the future in mind, the developer(s) behind QMessageBox actually changes its appearance in another key way by replacing the default system icons (as based on the MessageBoxIcon enumeration) with those that ship today with Windows Vista instead of the ones that would ordinarily be displayed by Windows Server 2003.

For comparison, the following image (click for larger) shows the difference between MessageBox and QMessageBox being used on Windows XP, 2003, Vista and Home Server:

MessageBox vs QMessageBox

(Note: The above Windows 2003 MessageBox examples were run on a Windows Home Server machine.)

An unfortunate limitation of QMessageBox is that internally something is wrong with it's handling of the MessageBoxIcon.Question value because use of it will raise an ArgumentException, so be sure to stick with one of the other 4 working values (None, Asterisk, Hand, Question & Warning).

If all of this wasn't enough, one of the biggest (and least obvious) features of QMessageBox is that it allows you to specify an arbitrary image in place (in some overloads) of a MessageBoxIcon:

QMessageBox with CustomImage

Multi-line

A major pet peeve of mine about MessageBox was that it only had two text areas that you could use, the text argument displayed in the body of the window while the caption argument was displayed in the title bar. For any more advanced formatting you had to make your own dialog or add new line characters to separate certain areas... QMessageBox takes this idea and extends it by allowing a third argument named title which appears as a bold area of text that appears above where the text is.

Dual Line QMessageBox

Note: The information in this post is based on undocumented and at times deduced information on Windows Home Server and is not officially supported or endorsed by Microsoft and could very easily be wrong or subject to change in future, so please take it and everything else said on this blog with a grain of salt and use with caution.

Labels:

0 Comments:

Post a Comment

<< Home