MFC对话框程序
我要改变对话框上按钮,使按钮既载入位图又能显示caption.因为现在将button的bitmap属性勾上后,显示不了caption了
谢谢
我要改变对话框上按钮,使按钮既载入位图又能显示caption.因为现在将button的bitmap属性勾上后,显示不了caption了
谢谢
解决方案 »
- 国内用VC开发的大型数据库系统有哪些
- 动态创建的Edit控件,为何输入的字符显示为粗体,且字符在垂直方向不居中?
- 我想做一个像拼音输入法那样的灰色的可翻页的小窗口,上面可显示汉字,并且汉字可选择,就像汉字输入法那样的,请给点思路,我是新手,请
- 系统注销或者关机时候要执行程序里面的一段代码,怎么实现?
- 用户权限管理的若干表的数据库设计问题
- 请问如何删除一个文本文件中的最末一行?
- 在调试时如何修改CString 变量的值呢。
- 如何把字符串转换为2进制,字符串中存的是十进制字符,'0'-'9'
- 请问!如何对一文本文件一次一行的读出!!!
- PureCoverage 使用问题
- 【問題】JPG圖片的顯示問題
- CArray 释放内存的问题
#define AFX_FLATB_H__A0160941_6A72_43F1_A2B8_5C1848A91662__INCLUDED_#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
// FlatB.h : header file
///////////////////////////////////////////////////////////////////////////////
// FlatB windowclass FlatB : public CButton
{
// Construction
public:
FlatB();// Attributes
public:// Operations
public:// Overrides
// ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(FlatB)
public:
virtual void DrawItem(LPDRAWITEMSTRUCT lpDrawItemStruct);
//}}AFX_VIRTUAL// Implementation
public:
virtual ~FlatB(); // Generated message map functions
protected:
//{{AFX_MSG(FlatB)
afx_msg void OnMouseMove(UINT nFlags, CPoint point);
afx_msg void OnLButtonUp(UINT nFlags, CPoint point);
afx_msg void OnTimer(UINT nIDEvent);
//}}AFX_MSG DECLARE_MESSAGE_MAP()
private:
bool m_blnRaised;//当鼠标指针在客户区移动时,是否为突起状态
CRect m_rectFocus;//焦点虚线框
bool m_blnFocus;//是否获得焦点
CRect m_rectClient;//客户区范围
CString m_strCaption;//按扭标题
};///////////////////////////////////////////////////////////////////////////////{{AFX_INSERT_LOCATION}}
// Microsoft Visual C++ will insert additional declarations immediately before the previous line.#endif // !defined(AFX_FLATB_H__A0160941_6A72_43F1_A2B8_5C1848A91662__INCLUDED_)
//#include "stdafx.h"
#include "FlatButton.h"
#include "FlatB.h"#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif/////////////////////////////////////////////////////////////////////////////
// FlatBFlatB::FlatB()
{
m_blnRaised=false;
}FlatB::~FlatB()
{
}
BEGIN_MESSAGE_MAP(FlatB, CButton)
//{{AFX_MSG_MAP(FlatB)
ON_WM_MOUSEMOVE()
ON_WM_LBUTTONUP()
ON_WM_TIMER()
//}}AFX_MSG_MAP
END_MESSAGE_MAP()/////////////////////////////////////////////////////////////////////////////
// FlatB message handlersvoid FlatB::DrawItem(LPDRAWITEMSTRUCT lpDrawItemStruct)
{
// TODO: Add your code to draw the specified item
HICON hIcon;
ICONINFO iconinfo;
BITMAP bm;
HBITMAP hBitmap; TEXTMETRIC textMetric; m_rectClient.CopyRect(&lpDrawItemStruct->rcItem);
m_rectFocus.CopyRect(&m_rectClient);
m_rectFocus.DeflateRect(4,4,4,4); CDC *pDc=CDC::FromHandle(lpDrawItemStruct->hDC); pDc->FillSolidRect(&m_rectClient,::GetSysColor(COLOR_BTNFACE)); if(lpDrawItemStruct->itemState&ODS_SELECTED)
{
pDc->Draw3dRect(&m_rectClient,::GetSysColor(COLOR_BTNSHADOW),::GetSysColor(COLOR_BTNSHADOW));
}
else
{
pDc->Draw3dRect(&m_rectClient,::GetSysColor(COLOR_BTNFACE),::GetSysColor(COLOR_BTNFACE));
}
hIcon=GetIcon();
if(hIcon)
{
CRect rectIcon;
rectIcon.CopyRect(m_rectClient);
rectIcon.DeflateRect(2,2,2,2);
GetIconInfo(hIcon,&iconinfo);
hBitmap=iconinfo.hbmMask; ::GetObject(hBitmap,sizeof(bm),&bm); if(lpDrawItemStruct->itemState&ODS_SELECTED)
{
rectIcon.OffsetRect(1,1);
}
DrawIconEx(pDc->GetSafeHdc(),rectIcon.left,rectIcon.top,
GetIcon(),bm.bmWidth,bm.bmHeight,NULL,
(HBRUSH)NULL,DI_NORMAL);
} if(lpDrawItemStruct->itemState&ODS_SELECTED)
{
pDc->DrawFocusRect(m_rectFocus);
m_blnFocus=true;
}
else
{
m_blnFocus=false;
}
pDc->GetTextMetrics(&textMetric); this->GetWindowText(m_strCaption);
//设置字体部分的背景透明
pDc->SetBkMode(TRANSPARENT); pDc->TextOut((m_rectClient.Width()-m_strCaption.GetLength())/2-2*bm.bmWidth/3,
(m_rectClient.Height()-textMetric.tmHeight)/2,m_strCaption);
ReleaseDC(pDc);
}void FlatB::OnMouseMove(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
HICON hIcon;
ICONINFO iconinfo;
BITMAP bm;
HBITMAP hBitmap; TEXTMETRIC textMetric; CRect rectWindow;
GetWindowRect(rectWindow);
CPoint ptCursor;
GetCursorPos(&ptCursor); if(!rectWindow.PtInRect(ptCursor))
{
CButton::OnMouseMove(nFlags, point);
return;
} if(m_blnRaised==false)
{
SetTimer(1,10,NULL);
CDC *pDc=GetDC(); pDc->FillSolidRect(m_rectClient,::GetSysColor(COLOR_BTNFACE)); hIcon=GetIcon();
if(hIcon)
{
CRect rectIcon;
rectIcon.CopyRect(m_rectClient);
rectIcon.DeflateRect(2,2,2,2);//区域略小于客户区 GetIconInfo(hIcon,&iconinfo);
hBitmap=iconinfo.hbmMask;//获取图标中的位图句柄 ::GetObject(hBitmap,sizeof(bm),&bm);//获取位图信息
DrawIconEx(pDc->GetSafeHdc(),rectIcon.left,rectIcon.top,GetIcon(),bm.bmWidth,
bm.bmHeight,NULL,(HBRUSH)NULL,DI_NORMAL);
} //画3D框
pDc->Draw3dRect(m_rectClient,::GetSysColor(COLOR_BTNHIGHLIGHT),::GetSysColor(COLOR_BTNSHADOW));
if(m_blnFocus)
{
pDc->DrawFocusRect(m_rectFocus);
}
m_blnRaised=true; pDc->GetTextMetrics(&textMetric); this->GetWindowText(m_strCaption);
//设置字体部分的背景透明
pDc->SetBkMode(TRANSPARENT); pDc->TextOut((m_rectClient.Width()-m_strCaption.GetLength())/2-2*bm.bmWidth/3,
(m_rectClient.Height()-textMetric.tmHeight)/2,m_strCaption);
ReleaseDC(pDc);
}
CButton::OnMouseMove(nFlags, point);
}void FlatB::OnLButtonUp(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
m_blnRaised=false; //当鼠标抬起时,设置突起框标志为false
CButton::OnLButtonUp(nFlags, point);
}void FlatB::OnTimer(UINT nIDEvent)
{
// TODO: Add your message handler code here and/or call default
CRect rectwindow;
GetWindowRect(rectwindow);
CPoint ptCursor;
GetCursorPos(&ptCursor); if(!rectwindow.PtInRect(ptCursor))
{
CButton::OnTimer(nIDEvent);
KillTimer(nIDEvent);
InvalidateRect(NULL);
m_blnRaised=false;
return;
}
CButton::OnTimer(nIDEvent);
}
OnInitDialog():
……
CRect btnRect(10,100,160,142);
m_btnTry.Create("Just For a Try",WS_VISIBLE|WS_CHILD|BS_OWNERDRAW|BS_ICON|BS_LEFT,
btnRect,this,IDC_btnTRY);
m_btnTry.SetIcon(AfxGetApp()->LoadIcon(IDI_ICON_TRY));
…….h文件中定义
FlatB m_btnTry;