海信家电”换帅 “ 高玉玲接替代慧忠出任新任董事长
2024-11-22
图一、显示系统的当前图标 |
HICON hIconQuestion = ::LoadIcon(NULL, IDI_QUESTION); |
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 } }; |
for (UINT i=0; SysIcons[i].nResID; i++) { HICON hicon = ::LoadIcon(NULL, SysIcons[i].nResID); ASSERT(hicon); CString name = SysIcons[i].name; ...... } ...... |
HICON hicon = ::LoadIcon(NULL, IDI_HAND); m_wndStatic.SetIcon(hicon); |
#if(WINVER >= 0x0400) #define IDI_WARNING IDI_EXCLAMATION #define IDI_ERROR IDI_HAND #define IDI_INFORMATION IDI_ASTERISK #endif /* WINVER >= 0x0400 */ |
如果你想跟上微软的这些变化,那么就使用新符号好了。这样你的代码也会更可读一些,因为现在的警告、错误和信息符号更能传达图标所要表达的本意。
二、编程步骤
1、 启动Visual C++6.0,生成一个单文档视图结构的应用程序,将该程序命名为"FindSysIcon";
2、 使用Class Wizard重载应用程序的CMainFrame类的OnPaint()函数;
3、 添加代码,编译运行程序。
三、程序代码
//////// MainFrm.cpp : implementation of the CMainFrame class #include "stdafx.h" #include "FindSysIcon.h" #include "MainFrm.h" #ifdef _DEBUG #define new DEBUG_NEW #undef THIS_FILE static char THIS_FILE[] = __FILE__; #endif IMPLEMENT_DYNAMIC(CMainFrame, CFrameWnd) BEGIN_MESSAGE_MAP(CMainFrame, CFrameWnd) //{{AFX_MSG_MAP(CMainFrame) // NOTE - the ClassWizard will add and remove mapping macros here. // DO NOT EDIT what you see in these blocks of generated code ! ON_WM_CREATE() ON_WM_PAINT() //}}AFX_MSG_MAP END_MESSAGE_MAP() #p#分页标题#e# static UINT indicators[] = { ID_SEPARATOR, // status line indicator ID_INDICATOR_CAPS, ID_INDICATOR_NUM, ID_INDICATOR_SCRL, }; 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 } }; CMainFrame::CMainFrame() { // TODO: add member initialization code here } CMainFrame::~CMainFrame() {} int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct) { return CFrameWnd::OnCreate(lpCreateStruct); } BOOL CMainFrame::PreCreateWindow(CREATESTRUCT& cs) { BOOL bRet = CFrameWnd::PreCreateWindow(cs); cs.cx=200; cs.cy=400; return bRet; } #ifdef _DEBUG void CMainFrame::AssertValid() const { CFrameWnd::AssertValid(); } void CMainFrame::Dump(CDumpContext& dc) const { CFrameWnd::Dump(dc); } #endif //_DEBUG void CMainFrame::OnPaint() { CPaintDC dc(this); CRect rcClient; GetClientRect(&rcClient); int cyIcon = GetSystemMetrics(SM_CYICON); int cxIcon = GetSystemMetrics(SM_CXICON); CRect rcIcon(0,0,cxIcon,cyIcon); CRect rcText(cxIcon, 0, rcClient.Width()-cxIcon, cyIcon); for (UINT i=0; SysIcons[i].nResID; i++) { HICON hicon = ::LoadIcon(NULL, SysIcons[i].nResID); ASSERT(hicon); CString name = SysIcons[i].name; dc.DrawIcon(rcIcon.TopLeft(), hicon); dc.DrawText(name, rcText, DT_LEFT); rcIcon += CPoint(0, rcIcon.Height()); rcText += CPoint(0, rcIcon.Height()); } } |
评论 {{userinfo.comments}}
{{child.content}}
{{question.question}}
提交