【VC开源代码栏目提醒】:网学会员--在 VC开源代码编辑为广大网友搜集整理了:BaseButton.cpp绩等信息,祝愿广大网友取得需要的信息,参考学习。
// BaseButton.cpp : implementation file
//
#include "stdafx.h"
#include "qpglxt.h"
#include "BaseButton.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CBaseButton
CBaseButton::CBaseButton(UINT NomalPic,UINT DownPic,UINT EnablePic)
{
m_DownPic=DownPic;
m_NomalPic=NomalPic;
m_EnablePic=EnablePic;
}
CBaseButton::~CBaseButton()
{
}
BEGIN_MESSAGE_MAP(CBaseButton, CButton)
//{{AFX_MSG_MAP(CBaseButton)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CBaseButton message handlers
bool CBaseButton::Drawit(CDC *pDC, UINT ResID)
{
CDC memDC;
CBitmap bit;
CBitmap* pbit;
COLORREF Col,OldCol;
BITMAP bitstruct;
bit.LoadBitmap(ResID);
bit.GetBitmap(&bitstruct);
memDC.CreateCompatibleDC(pDC);
pbit=memDC.SelectObject(&bit);
OldCol=memDC.GetPixel(0,0);
for(int x=0;x<bitstruct.bmWidth;x++)
{
for(int y=0;y<bitstruct.bmHeight;y++)
{
Col=memDC.GetPixel(x,y);
if(Col!=OldCol)
pDC->SetPixel(x,y,Col);
}
}
memDC.DeleteDC();
bit.DeleteObject();
pbit->DeleteObject();
return true;
}
void CBaseButton::DrawItem(LPDRAWITEMSTRUCT lpDrawItemStruct)
{
CDC* pDC;
pDC=CDC::FromHandle(lpDrawItemStruct->hDC);
UINT state=lpDrawItemStruct->itemState;
CRect focRect,rect=lpDrawItemStruct->rcItem;
focRect.left=rect.left+3;
focRect.right=rect.right-3;
focRect.top=rect.top+3;
focRect.bottom=rect.bottom-3;
//写按钮文本
pDC->SetBkMode(TRANSPARENT);
CString sCaption;
this->GetWindowText(sCaption);
if(state&ODS_SELECTED)
{
Drawit(pDC,m_DownPic);
pDC->SetTextColor(RGB(255,100,100));
}
else
{
Drawit(pDC,m_NomalPic);
pDC->SetTextColor(RGB(255,255,155));
}
if(state&ODS_FOCUS)
{
pDC->DrawFocusRect(&focRect);
lpDrawItemStruct->itemAction=ODA_FOCUS ;
}
if(state&ODS_DISABLED)
{
Drawit(pDC,m_EnablePic);
pDC->SetTextColor(RGB(96,96,96));
}
pDC->DrawText(sCaption,rect,DT_CENTER|DT_VCENTER|DT_SINGLELINE);
}
BOOL CBaseButton::PreTranslateMessage(MSG* pMsg)
{
if(pMsg->hwnd==this->GetSafeHwnd()&&pMsg->message==WM_KEYDOWN && pMsg->wParam==13)
{
pMsg->lParam=589857;
pMsg->message=WM_LBUTTONDOWN;
}
if(pMsg->hwnd==this->GetSafeHwnd()&&pMsg->message==WM_KEYUP && pMsg->wParam==13)
{
pMsg->lParam=589857;
pMsg->message=WM_LBUTTONUP;
}
return CButton::PreTranslateMessage(pMsg);
}
上一篇:
BASE64.CPP
下一篇:
法律专业开题报告范文