三、程序代码
//////// 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()
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()); } } |
四、小结
上文介绍了如何获取Windows的系统图标,但是不得不提的一个令人困惑的问题是:虽然winuser.h中新增了一个新的符号IDI_WINLOGO。在基于Windows XP的应用程序里使用这个图标产生的效果并不是我们所熟悉的那个家喻户晓名叫"飞扬"的窗口标志,而是图一里IDI_APPLICATION所表示的一般窗口标志。仔细阅读有关文档后,你会发现微软对此的解释是"设计行为"。为什么这个具有某种代表意义的东西在不同的Windows OS中表现得如此模棱两可呢?此中缘由鲜为人知。 
说明:本教程来源互联网或网友上传或出版商,仅为学习研究或媒体推广,wanshiok.com不保证资料的完整性。
2/2 首页 上一页 1 2 |