As you know, many Windows programs use MessageBox, as long as you use the MB_ICONQUESTION flag in one of the parameters of this API function, you can display the question mark icon in the MessageBox dialog box. This allows different icons to be displayed with different flags. The icons in Windows 2000 and Windows XP are becoming more attractive and more diverse than previous versions of Windows. To make these beautiful icons more widely available, this article describes how to apply them to your own dialog box or form. To do this, the first problem to solve is: where and how do I get these icons?
This problem is the most basic problem in Windows, and it is also the easiest to forget. Now let's take a look at how we normally do this by using predefined forms for Idi_xxx resource IDs as parameters:: LoadIcon function, we can get any so-called system icons. For example:
HICON hIconQuestion = ::LoadIcon(NULL, IDI_QUESTION);
Figure one is the running picture of this example program, which shows all the system icons.
Figure One example program run Screen
The figure above is the example program that runs the results in Windows 2000+SP3. The implementation details are in the Mainfrm,cpp file. Sysicons[] is an array of structures whose elements define the ID and name of the icon resource:
const struct {
LPCTSTR nResID;
LPCTSTR name;
} SysIcons[] = {
{ IDI_APPLICATION, _T("IDI_APPLICATION") },
{ IDI_HAND, _T("IDI_HAND") },
{ IDI_QUESTION, _T("IDI_QUESTION") },
{ IDI_EXCLAMATION, _T("IDI_EXCLAMATION") },
{ IDI_ASTERISK, _T("IDI_ASTERISK") },
#if(WINVER >= 0x0400)
{ IDI_WINLOGO, _T("IDI_WINLOGO") },
{ IDI_WARNING, _T("IDI_WARNING") },
{ IDI_ERROR, _T("IDI_ERROR") },
{ IDI_INFORMATION, _T("IDI_INFORMATION") },
#endif
{ NULL, NULL }
};
The load icon is in Cmainframe::onpaint ():
......
for (UINT i=0; SysIcons[i].nResID; i++) {
HICON hicon = ::LoadIcon(NULL, SysIcons[i].nResID);
ASSERT(hicon);
CString name = SysIcons[i].name;
......
{