MFC Feature Pack

At the beginning of January, Microsoft released a beta version of MFC Feature Pack, an exstension to the MFC shipped with Visual Studio 2008. This feature pack allows developers to create applications with the look and feel of Office, Visual Studio and Internet Explorer. MFC application can now support: Office Ribbon Office 2003, XP and … Read more

Forward Declaration for a Class from a Namespace

Suppose you have a class declare in a namespace, like this: #pragma once namespace Test { class foo { public: foo(void); ~foo(void); }; }; #include “foo.h” namespace Test { foo::foo(void) { } foo::~foo(void) { } }; And you want to use that foo class in a another class, with a forward declaration: #pragma once class … Read more

STL string utils

STL’s std::string doesn’t have methods for transforming the string to upper or lower case or for trimming (as other string implementations, such as CString, have). I’ve noticed that many people don’t know how to implement such functions, so I’ll show you here how to do that. class stringutils { public: static void make_upper(std::string& text) { … Read more

Create a font with the desired size

Let’s asume you want to change the font of a window\control and for the sake of simplicity let’s consider an MFC dialog application. In that case, there are several steps you should follow: declare a CFont variable in the dialog class create the font in OnInitDialog (using CreateFont) set the font to the control (using … Read more

Beware of Sequence Points

Consider the following C++ code: void foo(int a, int b, int c) { std::cout << a << ‘ ‘ << b << ‘ ‘ << c << std::endl; } int main(int argc, char* argv[]) { int value = 1; foo(value++, value++, value++); return 0; } That looks pretty straight-forward: there is a function that takes … Read more

Visual C++ 2008 Fix of Containers Swap Bug

The C++ standard, specifies in the paragraph 23.1.10 that swapping two containers should not invalidate any references, pointers or iterators refering to the elements of the containers being swapped. Unfortunatelly, that is not the case of the VC++ 2005 implementation. Imagine the following case: std::vector vec1; vec1.push_back(1); vec1.push_back(2); vec1.push_back(3); std::vector vec2; vec2.push_back(10); vec2.push_back(20); std::vector::iterator it1 = vec1.begin(); … Read more

How to Detect Available COM Ports

I’ve seen this question many times asked in forums. Unfortunatelly, not all the answers are ok. A a good wait to find the available COM ports is by using function GetDefaultCommConfig, that returns the default configuration for a specified communication device. Following code shows how to use it: #include <vector> #include <string> // this can … Read more

Update of Article “Determine Windows Version and Edition”

Recently I have updated my article published on CodeGuru about determining Windows version and edition. The update offers support for determining the Windows Vista and Windows Server 2008 edition installed on a machine. Since both these new operating systems have the same major and minor version returned by GetVersionEx, i.e. 6 for major and 0 … Read more