Using System icons in dialog boxes and forms

Source: Internet
Author: User
Tags resource

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;
    ......
  {

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.