难题,在一背景图片上放一个CSliderCtrl控件,如何让此控件透明?

djhdu 2003-02-12 01:41:48
也就是如何实现一个透明的CSliderCtrl控件!
...全文
266 11 打赏 收藏 举报
写回复
用AI写文章
11 条回复
切换为时间正序
请发表友善的回复…
发表回复
Gargamel 2003-02-13
  • 打赏
  • 举报
回复
留个邮箱,发给你一个demo
kingzai 2003-02-13
  • 打赏
  • 举报
回复
in your CSliderCtrl derived class, in your OnPaint message handler,
first let the control draw itself into a memory dc, then draw it
transparently on the screen using COLOR_BTNFACE as tranparent color.

See http://www.codeguru.com/treeview/background_image.shtml for an
example on how to implement it.
djhdu 2003-02-13
  • 打赏
  • 举报
回复
怎么没有人帮助我啊?
chenzhou35 2003-02-13
  • 打赏
  • 举报
回复
// MySliderControl.cpp : implementation file
//
//
// Copyright (C) 2001 by Nic Wilsonk
// All rights reserved
//
// This is free software.
// This code may be used in compiled form in any way you desire. This
// file may be redistributed unmodified by any means PROVIDING it is
// not sold for profit without the authors written consent, and
// providing that this notice and the authors name and all copyright
// notices remains intact. If the source code in this file is used in
// any commercial application then a statement along the lines of
// "Portions Copyright ?2001 Nic Wilson" must be included in
// the startup banner, "About" box and printed documentation. An email
// letting me know that you are using it would be nice.
//
// No warrantee of any kind, expressed or implied, is included with this
// software; use at your own risk, responsibility for damages (if any) to
// anyone resulting from the use of this software rests entirely with the
// user.
//
// Version: 1.0
// Release: 1 (www.codeguru.com)
// -----------------------------------------------------------------------
/////////////////////////////////////////////////////////////////////////////
#include "stdafx.h"
#include "MySliderControl.h"
#include "windows.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CMySliderControl

CMySliderControl::CMySliderControl()
{
m_dcBk.m_hDC = NULL;
}

CMySliderControl::~CMySliderControl()
{
DeleteObject(m_dcBk.SelectObject(&m_bmpBkOld));
DeleteDC(m_dcBk);
}


BEGIN_MESSAGE_MAP(CMySliderControl, CSliderCtrl)
//{{AFX_MSG_MAP(CMySliderControl)
ON_NOTIFY_REFLECT(NM_CUSTOMDRAW, OnCustomDraw)
ON_WM_ERASEBKGND()
//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CMySliderControl message handlers
//-------------------------------------------------------------------
//
void CMySliderControl::OnCustomDraw(NMHDR* pNMHDR, LRESULT* pResult)
//
// Description : Sent by the slider control to notify the parent window
// about drawing operations. This notification is sent in
// the form of a WM_NOTIFY message.
// Parameters : pNMHDR - a pointer to a NM_CUSTOMDRAW structure.
// pResult - value depends on the current drawing state.
{
LPNMCUSTOMDRAW lpcd = (LPNMCUSTOMDRAW)pNMHDR;
CDC *pDC = CDC::FromHandle(lpcd->hdc);
switch(lpcd->dwDrawStage)
{
case CDDS_PREPAINT:
*pResult = CDRF_NOTIFYITEMDRAW ;
TRACE("CDDS_PREPAINT\n");
break;
//return;
case CDDS_ITEMPREPAINT:
TRACE("CDDS_ITEMPREPAINT\n");
if (lpcd->dwItemSpec == TBCD_THUMB)
{
*pResult = CDRF_DODEFAULT;
TRACE("TBCD_THUMB\n");
break;
}
if(lpcd->dwItemSpec == TBCD_TICS )
{
TRACE("TBCD_TICS\n");
break;
}
if (lpcd->dwItemSpec == TBCD_CHANNEL)
{
TRACE("TBCD_CHANNEL\n");
CClientDC clientDC(GetParent());
CRect crect;
CRect wrect;
GetClientRect(crect);
GetWindowRect(wrect);
GetParent()->ScreenToClient(wrect);
if (m_dcBk.m_hDC == NULL)
{
m_dcBk.CreateCompatibleDC(&clientDC);
m_bmpBk.CreateCompatibleBitmap(&clientDC, crect.Width(), crect.Height());
m_bmpBkOld = m_dcBk.SelectObject(&m_bmpBk);
m_dcBk.BitBlt(0, 0, crect.Width(), crect.Height(), &clientDC, wrect.left, wrect.top, SRCCOPY);
}
//This bit does the tics marks transparently.
//create a memory dc to hold a copy of the oldbitmap data that includes the tics,
//because when we add the background in we will lose the tic marks
CDC SaveCDC;
CBitmap SaveCBmp, maskBitmap;
//set the colours for the monochrome mask bitmap
COLORREF crOldBack = pDC->SetBkColor(RGB(0,0,0));
COLORREF crOldText = pDC->SetTextColor(RGB(255,255,255));
CDC maskDC;
int iWidth = crect.Width();
int iHeight = crect.Height();
SaveCDC.CreateCompatibleDC(pDC);
SaveCBmp.CreateCompatibleBitmap(&SaveCDC, iWidth, iHeight);
CBitmap* SaveCBmpOld = (CBitmap *)SaveCDC.SelectObject(SaveCBmp);
//fill in the memory dc for the mask
maskDC.CreateCompatibleDC(&SaveCDC);
//create a monochrome bitmap
maskBitmap.CreateBitmap(iWidth, iHeight, 1, 1, NULL);
//select the mask bitmap into the dc
CBitmap* OldmaskBitmap = maskDC.SelectObject(&maskBitmap);
//copy the oldbitmap data into the bitmap, this includes the tics.
SaveCDC.BitBlt(0, 0, iWidth, iHeight, pDC, crect.left, crect.top, SRCCOPY);
//now copy the background into the slider
BitBlt(lpcd->hdc, 0, 0, iWidth, iHeight, m_dcBk.m_hDC, 0, 0, SRCCOPY);
// Blit the mask based on background colour
maskDC.BitBlt(0, 0, iWidth, iHeight, &SaveCDC, 0, 0, SRCCOPY);
// Blit the image using the mask
pDC->BitBlt(0, 0, iWidth, iHeight, &SaveCDC, 0, 0, SRCINVERT);
pDC->BitBlt(0, 0, iWidth, iHeight, &maskDC, 0, 0, SRCAND);
pDC->BitBlt(0, 0, iWidth, iHeight, &SaveCDC, 0, 0, SRCINVERT);
//restore and clean up
pDC->SetBkColor(crOldBack);
pDC->SetTextColor(crOldText);
DeleteObject(SelectObject(SaveCDC, SaveCBmpOld));
DeleteDC(SaveCDC);
DeleteObject(maskDC.SelectObject(OldmaskBitmap));
DeleteDC(maskDC);
*pResult = 0;
break;
}
}
}

BOOL CMySliderControl::OnEraseBkgnd(CDC* pDC)
{
return FALSE;
}

djhdu 2003-02-13
  • 打赏
  • 举报
回复
djhdu@163.com,谢谢!
demetry 2003-02-13
  • 打赏
  • 举报
回复
demetry@263.net
djhdu 2003-02-12
  • 打赏
  • 举报
回复
我重载了OnPaint,什么代码也没写,CSliderCtrl显示的部门只剩下一片灰色,原来的滑块都没有了,是不是我应该从新画原来所有的东西,有没有什么例子啊?
kingzai 2003-02-12
  • 打赏
  • 举报
回复
you may try try handling NM_CUSTOMDRAW or WM_PAINT notifications,then use HOLLOW BRUSH draw it
zcpro 2003-02-12
  • 打赏
  • 举报
回复
在父窗口中处理WM_CTLCOLOR消息,返回空刷子。
djhdu 2003-02-12
  • 打赏
  • 举报
回复
真的吗,谢谢,哪个出版社的!
tudou614 2003-02-12
  • 打赏
  • 举报
回复
书店有这方面的书
VC100???????
确切名记不得了
我有一本
内容概要:本文介绍了COSO企业风险管理框架,阐述了企业风险管理的定义、目标、构成要素及其与内部控制的关系。文章指出,企业风险管理是一个由董事会、管理层及其他人员实施的,应用于战略制定并贯穿于企业之中的过程,旨在识别可能影响主体的潜在事项,管理风险以使其在该主体的风险容量之内,并为主体目标的实现提供合理保证。该框架强调了企业风险管理的八大构成要素:内部环境、目标设定、事项识别、风险评估、风险应对、控制活动、信息与沟通、监控。此外,文章还讨论了企业风险管理的局限性,如人为判断失误、成本与效益的权衡、管理层凌驾等。 适合人群:具备一定管理学基础知识,对风险管理有兴趣的学者、企业管理人员、内部审计师及外部审计师。 使用场景及目标:①帮助组织理解并应用企业风险管理框架,以提高组织的风险管理水平;②指导企业如何通过有效的风险管理来实现其战略、经营、报告和合规目标;③为企业提供一套标准化的风险管理语言,促进内外部沟通与合作。 阅读建议:读者应结合实际案例,深入理解每个构成要素的具体应用,同时关注企业风险管理的局限性,以全面把握企业风险管理的本质。此外,建议定期回顾和更新风险管理策略,以适应不断变化的内外部环境。

15,976

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC 界面
社区管理员
  • 界面
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧