admin - 10/30/2008 There was once a time when multiple language support for a Windows application used to be a three to six months call, but with the advent of .NET, not anymore. Here is a 20 minutes crash course for globalization / localization of a Windows application. I think you'll find it as useful as I do. |
admin - 10/30/2008 This article describes UITestBench, a small but efficient library to implement User-Interface tests that can be run with NUnit or any other unit test framework. The source code provided with this project, a Visual Studio 2005 solution, is split into three parts/projects:
A small sample application
The UITestBench classes
Two NUnit test cases for the demo application using the UITestBenc |
admin - 10/28/2008 On occasions, one needs to take time samples of an operation but only as a diagnostic during development and/or testing in a debug build. And, while there is an excellent Stopwatch class in .NET 2.0, this class is inappropriate for non-diagnostic time sampling because it:
is not a static class, and
therefore does not support conditional debug builds. |
admin - 10/26/2008 After procrastinating, I finally decided to sit down and learn to program in F#, since functional programming has always intrigued me. Although I had some experience with Prolog many moons ago, I have done most of my programming using imperative rather than functional or declarative languages, with recent work mostly in C#. Whenever I've learned new languages, there is always an effort required to "get up to speed", but with F# I found the initial steps were more difficult than I anticipated due to the lack of a mature IDE on top of learning a new language and adjusting to a different programming paradigm. I'm still no expert in F#, but perhaps some of my early stumbling might be of use to others, so they don't have to go through the same pain that I did. |
admin - 10/16/2008 This article describes a set of classes that are used to perform string conversions between the Unicode and ANSI character sets. Why is it needed? There are several reasons:
If you are developing for COM, then all strings passed via the COM interfaces are wide strings (unless they are part of the VARIANT structure).
If you are developing communication applications then (most probably) you need to send/receive data to/from the communication channel in ANSI character set (and your application is either Unicode or ANSI).
If you want to have a portable application and you need to use either ANSI or Unicode strings for any reason.
You are developing a DLL, service or applications that are not MFC based and you cannot use CString.
In addition, one should consider the following:
When passing wide strings via the COM interfaces, memory for these strings must be allocated with CoTaskMemAlloc() and released with CoTaskMemFree().
In any other situation, it is allowed to use new and delete.
Besides ANSI and Unicode strings, there is also a BSTR string. Microsoft class _bstr_t encapsulates the BSTR strings. |
admin - 10/14/2008 This article shows an example of how we can easily design a web server control that can load or read the ASP.NET Controls collection. This can be really helpful in a situation where we want to store the user selected values in a form which need to be loaded back automatically when he/she logs back in. The control can work on any number of web controls and in any order. You just have to encompass all the controls that you want to load/store within the template of this control, and that’s it. The best part is that you do not have to configure the control on individual pages on what controls to store or restore, it automatically does that. |
admin - 10/14/2008 This article assumes that you have basic knowledge of creating a simple UserControl, so I am not going to go into much detail on creating one here. To demonstrate the Property Editors, I decided to make a control that draws itself in a selected shape. This gave me lots of options to demonstrate different design time editors. This demo uses UITypeEditors, Smart Tags, ControlDesigner Verbs, and Expandable Properties. |
admin - 9/23/2008 There are many Windows C++ programming books that contain chapters on how to use the clipboard and drag-and-drop. Some show how to perform these operations the basic Windows API, some use MFC, and others use COM/OLE to do the job.
However, when I wanted to start doing clipboard operations of my own, I discovered that all of these sources had one limitation in common: They usually only dealt with plain text (CF_TEXT) transfers, but I had to handle my own special objects.
Then I read an article by Keith Rule, showing the use of CMemFile and CSharedFile objects to transfer text blocks via serialization. I decided that this process could be expanded to work on any class which was derived from CObject, as long as the class in question had its own Serialize() method.
The result is the drag-drop manager described in this article. |
admin - 9/23/2008 This piece of code is to help you backup your clipboard data and restore it after you have finished other clipboard operations.
My experience: while I'm developing Word add-in programs, the icon of the new-added button can only be set through clipboard by "...->PasteFace()". This will empty the clipboard data which is going to be pasted in Word. So, I wrote this class, and it helped me a lot. |
admin - 9/23/2008 While I was reading Charles Petzold's Programming Windows book, more specifically the chapter on metafiles, I was wondering what could be the potential usages of such a feature in a real world application. The chapter describes in length what metafiles do and how they work, but little is said about what you can do with them or why you should use them. I think that I found a worthwhile application for metafiles and I am going to share it with you. This article has no claims of inventing a revolutionary technique as it is ridiculously simple, but at the same time, it does not seem to be widely known. This technique is for sharing data among different applications, as for sharing the data among the same application, private data formats might be more appropriate. In this article, I will give a brief overview of what metafiles are, and then I will present the technique. |
admin - 9/23/2008 Recently, I had cause to save a DIB to the clipboard. I tried numerous methods over a four-week period, but none of them worked (many thanks to Chris Losinger and Christian Graus for their willingness to try and provide me with guidance, an answer, or both). This article describes how I finally attained my goal, but also falls neatly into the category It Ain't Pretty But It Works. |
admin - 9/23/2008 This article would be a late follow-up to my previous article, A Separator Combo Box, regarding a control class derived from MFC CCombobox. Since it was posted, several readers have asked for a similar separator combo box in C#. While touching C# programming, I found it easier to write such a custom combo box control as shown in above screen shot. The main point in implementing the separator in a combo box is that a separator should not be selected either from UI or in code logic. We have two choices: let a separator occupy an item space or let a separator reside between items without extra space. I like the latter; it simply draws a line between items, saving space for the whole combo box.
Since both combo box and list box are derived from Windows.Forms.ListControl, they have the same virtual OnDrawItem() and OnMeasureItem() functions available in my customization. Here, the implementation of adding a separator to the combo box can also be applied to the list box. So, I present both SeparatorComboBox and SeparatorListBox, giving the demo as you see it in the screen shot. For simplicity, I only discuss the combo box in the following sections. |
admin - 9/18/2008 Microsoft enters the ORM (Object Relational Mapping) world with the introduction of LINQ (Language Integrated Query). This is provided as a built-in feature in Visual Studio 2008 and the .NET Framework 3.5 which was released to the public on November 19, 2007. |
admin - 9/18/2008 This article discusses EGen - a code generation framework implemented in Ruby that attempts to go beyond the classic substitution of variables in templates. It allows you to create stand-alone templates or embed marked template blocks into C/C++/C#/Java code. These templates contain Ruby code for simple generation but are also able to import and process designated portions from other files in the project that otherwise would need to be synchronized and maintained manually.
It applies the Don't Repeat Yourself(DRY) principle by keeping it's metadata in one place (a lightweight text database) and letting you use it to generate various portions of the project's code.
Keeping the metadata database and templates as text makes it easy to add them to the repository with the rest of the project files and can be restored or branched along with them.
The main focus of the framework is on active code generation. The templates become part of the host project and allow you to automatically refresh the code as the metadata changes and maintain dependencies among code sections. Upon such changes traditional wizards can only re-create the skeleton code and you need to carry over manually all custom modifications from the old code into the new one.
For completeness some passive code generation capability is included although it is less important now that most modern IDEs include plenty of wizards.
The demo included with the article shows its use in a C++ project using Visual Studio 2005. The framework however is dependent only on Ruby and two Ruby gems, therefore it can be used with other development environments and/or languages that use slash-star (/* */) comments. The included AddIn is specific to Visual Studio 2005. |
admin - 9/18/2008 Code generation is a fundamental aspect of flexible, rapid application development. There are many open source and commercial solutions available, such as Microsoft T4 or CodeSmith Tools, but often times these tools are targeted at specific technologies or platforms. With a little legwork you can leverage template processing libraries in modern scripting languages such as Ruby or Python to create powerful, open-ended template engines. You can use these template engines with any language or platform to generate source code, database scripts, configuration files, or any other text-based file. |
admin - 9/18/2008 Intrusion Detection Systems using SNORT (Sourcefire and Snort are Trademarks or Registered Trademarks of Sourcefire, INC) have an ongoing good track record of reporting any event on networks where you can formulate a detection rule. An unfortunate aspect to the use of SNORT or any other IDS system is that you have to know a fair amount about network topology in order to begin to approach the reports. This application takes an approach that considers the users need to be able to perform triage on an infested network at 3:00am and sleep deprived. MYSQLIDS produces a report based upon 5 time criteria as shown above with the ability to correct for 3 time zones. It also allows for optional printing of the payload data. The output is created in a common text file for a reason. File types with complex automation support provided by the OS or |