实例介绍
【实例截图】
【核心代码】
//============================================================================================ // //============================================================================================ #include "stdafx.h" #include "BitmapKeyed.h" #ifdef _DEBUG #define new DEBUG_NEW #undef THIS_FILE static char THIS_FILE[] = __FILE__; #endif #define TOOLTIP_ID 1 //-------------------------------------------------------------------------------------------- // //-------------------------------------------------------------------------------------------- IMPLEMENT_DYNCREATE(CBitmapKeyed, CBitmap) //-------------------------------------------------------------------------------------------- // //-------------------------------------------------------------------------------------------- BEGIN_MESSAGE_MAP(CBitmapKeyed, CStatic) //{{AFX_MSG_MAP(CBitmapKeyed) ON_WM_CREATE() ON_WM_PAINT() //}}AFX_MSG_MAP ON_WM_NCHITTEST() END_MESSAGE_MAP() //-------------------------------------------------------------------------------------------- // //-------------------------------------------------------------------------------------------- UINT CBitmapKeyed::OnNcHitTest(CPoint /*point*/) { return HTCLIENT; } //-------------------------------------------------------------------------------------------- // //-------------------------------------------------------------------------------------------- void CBitmapKeyed::Init (CWnd *pParent, int nIDC, int idBitmap, int idBitmapKey) { if (nIDC) pParent->GetDlgItem(nIDC)->ShowWindow(false); Bitmap.DeleteObject (); BitmapKey.DeleteObject (); Bitmap.LoadBitmap(idBitmap); BitmapKey.LoadBitmap(idBitmapKey); if (nIDC) { CRect rect; pParent->GetDlgItem(nIDC)->GetWindowRect(&rect); pParent->ScreenToClient (&rect); DestroyWindow(); Create ("a", WS_VISIBLE|WS_CHILD, rect, pParent, nIDC); } // Create the tooltip if (m_tooltipOverride!="") { CRect rect; GetClientRect(rect); m_ToolTip.Create(this); m_ToolTip.SendMessage(TTM_SETMAXTIPWIDTH, 0, 400); m_ToolTip.AddTool(this, m_tooltipOverride, rect, TOOLTIP_ID); } } //-------------------------------------------------------------------------------------------- // //-------------------------------------------------------------------------------------------- int CBitmapKeyed::OnCreate(LPCREATESTRUCT lpCreateStruct) { if (CStatic::OnCreate(lpCreateStruct) == -1) return -1; SetWindowSize(); // resize appropriately return 0; } //-------------------------------------------------------------------------------------------- // //-------------------------------------------------------------------------------------------- void CBitmapKeyed::OnPaint(void) { CPaintDC dc(this); CDC dcImage; if (!dcImage.CreateCompatibleDC(&dc)) return; BITMAP bm; Bitmap.GetBitmap(&bm); // Bild zeichnen CBitmap* pOldBitmap = dcImage.SelectObject(&BitmapKey); dc.BitBlt(0, 0, bm.bmWidth, bm.bmHeight, &dcImage, 0, 0, SRCAND); dcImage.SelectObject(&Bitmap); dc.BitBlt(0, 0, bm.bmWidth, bm.bmHeight, &dcImage, 0, 0, SRCPAINT); dcImage.SelectObject(pOldBitmap); } //-------------------------------------------------------------------------------------------- // //-------------------------------------------------------------------------------------------- void CBitmapKeyed::PreSubclassWindow() { ModifyStyle(0, BS_OWNERDRAW); // Make it owner drawn CStatic::PreSubclassWindow(); SetWindowSize(); // resize appropriately } //-------------------------------------------------------------------------------------------- // //-------------------------------------------------------------------------------------------- void CBitmapKeyed::SetWindowSize() { // Get size dimensions of edges CSize MarginSize(::GetSystemMetrics(SM_CXEDGE), ::GetSystemMetrics(SM_CYEDGE)); // Get window size CRect rect; GetWindowRect(rect); CWnd* pParent = GetParent(); if (pParent) pParent->ScreenToClient(rect); // Set window size at least as wide as 2 arrows, and as high as arrow margins int nWidth = max(rect.Width(), rect.Height()); MoveWindow(rect.left, rect.top, nWidth, rect.Height(), TRUE); // Get the new coords of this window GetWindowRect(rect); ScreenToClient(rect); } //-------------------------------------------------------------------------------------------- // //-------------------------------------------------------------------------------------------- BOOL CBitmapKeyed::PreTranslateMessage(MSG* pMsg) { if (m_tooltipOverride!="" && m_ToolTip.GetSafeHwnd()) m_ToolTip.RelayEvent(pMsg); return CStatic::PreTranslateMessage(pMsg); }
标签: combox
小贴士
感谢您为本站写下的评论,您的评论对其它用户来说具有重要的参考价值,所以请认真填写。
- 类似“顶”、“沙发”之类没有营养的文字,对勤劳贡献的楼主来说是令人沮丧的反馈信息。
- 相信您也不想看到一排文字/表情墙,所以请不要反馈意义不大的重复字符,也请尽量不要纯表情的回复。
- 提问之前请再仔细看一遍楼主的说明,或许是您遗漏了。
- 请勿到处挖坑绊人、招贴广告。既占空间让人厌烦,又没人会搭理,于人于己都无利。
关于好例子网
本站旨在为广大IT学习爱好者提供一个非营利性互相学习交流分享平台。本站所有资源都可以被免费获取学习研究。本站资源来自网友分享,对搜索内容的合法性不具有预见性、识别性、控制性,仅供学习研究,请务必在下载后24小时内给予删除,不得用于其他任何用途,否则后果自负。基于互联网的特殊性,平台无法对用户传输的作品、信息、内容的权属或合法性、安全性、合规性、真实性、科学性、完整权、有效性等进行实质审查;无论平台是否已进行审查,用户均应自行承担因其传输的作品、信息、内容而可能或已经产生的侵权或权属纠纷等法律责任。本站所有资源不代表本站的观点或立场,基于网友分享,根据中国法律《信息网络传播权保护条例》第二十二与二十三条之规定,若资源存在侵权或相关问题请联系本站客服人员,点此联系我们。关于更多版权及免责申明参见 版权及免责申明
网友评论
我要评论