Color, Link and Image Editor Controls for MFC
(Page 1 of 5 )
An operating system has crucial building blocks, without which it cannot function. One of these is its controls. They work together to complete complex tasks and to make your work easier. This article will focus on some new controls for an old favorite.
Controls also provide some harmony and common style to an operating system. This way you generally do not need to spend a lot of time learning how to use a new program if it works with an operating system with which you are already familiar. Because all applications are put together from the same building blocks (controls), once you are familiar with the OS you can use any application in it with minimal headaches.
The last time I started to present how to use these controls if you are creating a new program within Microsoft Visual Studio with the Microsoft Foundation Class Library. I used (and will continue to use) the New Controls application you can find on the MSDN site. I completely covered the button-related controls. Today I will focus on the color, shell, font combo box, link button, image editor, browse and CVS List Box controls.
There is a lot to learn, so let's get on with it. The link button is a sort of extension to the buttons. You could consider it more like a label on what you can click to open up a browser and visit a custom link/site. We will create pages in the same way we did in my previous article. Use the resource editor to create a common button, add a new class and replace the button with a CMFCLinkCtrl.
Afterward you can make all the settings inside the initialization of the property page:
CMFCLinkCtrl m_btnLink;
...
m_btnLink.SetURL (_T ("http://www.microsoft.com"));
m_btnLink.SetTooltip (_T ("Visit Microsoft site"));
m_btnLink.SizeToContent ();

Additionally, you may use the SetURLPrefix function. With this you can set the implicit protocol of the URL. For instance, this can be http or ftp or whatever seems appropriate. Other than these few functions, this will behave just like any other button, and you can use the same methods to change the text and complete other general actions:
CString text (L"Alfa and Omega");
m_btnLink.SetWindowText (text);
m_btnLink.SetURLPrefix (_T ("http:"));
m_btnLink.SetURL (_T ("www.microsoft.com"));
m_btnLink.SetTooltip (_T ("Visit Microsoft site"));
m_btnLink.SizeToContent ();

Next: Colors >>
More .NET Articles
More By Gabor Bernat