按钮类头文件
/*
* @file MyBitmapBtn.h
* @note ...
* @brief 能修改图片的自定义按钮类
* @author ...
* @date 2013/09/20
*/
#pragma once#define WM_CONNECTWIFI WM_USER+700class CMyBitmapBtn : public CBitmapButton
{
DECLARE_DYNAMIC(CMyBitmapBtn)public:
CMyBitmapBtn();
virtual ~CMyBitmapBtn();protected:
DECLARE_MESSAGE_MAP()
public:
COLORREF TextColor;
CString m_sSsid;//如果这个按钮被用于WIFI列表中的按钮,这个成员变量必须要赋值成ssid,否则的话是普通按钮.
void SetTextColor(COLORREF crColor);
void SetSsidString(CString ssid);
virtual void DrawItem(LPDRAWITEMSTRUCT lpDrawItemStruct);
afx_msg void OnLButtonUp(UINT nFlags, CPoint point);
};-------------------------------------------------------------------------------
// MyBitmapBtn.cpp : 实现文件#include "stdafx.h"
#include "MyBitmapBtn.h"IMPLEMENT_DYNAMIC(CMyBitmapBtn, CBitmapButton)CMyBitmapBtn::CMyBitmapBtn():m_sSsid("")
{
}CMyBitmapBtn::~CMyBitmapBtn()
{
}
BEGIN_MESSAGE_MAP(CMyBitmapBtn, CBitmapButton)
ON_WM_LBUTTONUP()
END_MESSAGE_MAP()
void CMyBitmapBtn::SetTextColor(COLORREF crColor)
{
TextColor = crColor;
}
void CMyBitmapBtn::DrawItem(LPDRAWITEMSTRUCT lpDrawItemStruct)
{
// TODO: Add your code to draw the specified item
CRect rect = lpDrawItemStruct->rcItem;
CDC *pDC = CDC::FromHandle(lpDrawItemStruct->hDC);
int nSaveDC = pDC->SaveDC();
UINT state = lpDrawItemStruct->itemState;
TCHAR strText[MAX_PATH + 1];
::GetWindowText(m_hWnd, strText, MAX_PATH);
CBitmapButton::DrawItem(lpDrawItemStruct);
pDC->SetTextColor(TextColor);
if (strText!=NULL)
{
CFont *hFont = GetFont();
CFont *hOldFont = pDC->SelectObject(hFont);
CSize szExtent = pDC->GetTextExtent(strText, lstrlen(strText));
CPoint pt(rect.CenterPoint().x - szExtent.cx / 2, rect.CenterPoint().y - szExtent.cy / 2);
if (state & ODS_SELECTED)
{
pt.Offset(1,1);
}
int nMode = pDC->SetBkMode(TRANSPARENT);
if (state & ODS_DISABLED)
{
pDC->DrawState(pt, szExtent, strText, DSS_DISABLED, TRUE, 0, (HBRUSH)NULL);
}
else
{
pDC->DrawState(pt, szExtent, strText, DSS_NORMAL, TRUE, 0, (HBRUSH)NULL);
}
pDC->SelectObject(hOldFont);
pDC->SetBkMode(nMode);
}
pDC->RestoreDC(nSaveDC);
}void CMyBitmapBtn::SetSsidString(CString ssid)
{
m_sSsid = ssid;
}void CMyBitmapBtn::OnLButtonUp(UINT nFlags, CPoint point)
{
// TODO: 在此添加消息处理程序代码和/或调用默认值
if (!m_sSsid.IsEmpty())
{
CString* str = new CString(m_sSsid);
assert(str);
::PostMessage(this->GetParent()->m_hWnd,WM_CONNECTWIFI,(WPARAM)str,1);
OutputDebugString("-----------------右键消息\n");
}
else
{
CBitmapButton::OnLButtonUp(nFlags, point);
}
}
/*
* @file MyBitmapBtn.h
* @note ...
* @brief 能修改图片的自定义按钮类
* @author ...
* @date 2013/09/20
*/
#pragma once#define WM_CONNECTWIFI WM_USER+700class CMyBitmapBtn : public CBitmapButton
{
DECLARE_DYNAMIC(CMyBitmapBtn)public:
CMyBitmapBtn();
virtual ~CMyBitmapBtn();protected:
DECLARE_MESSAGE_MAP()
public:
COLORREF TextColor;
CString m_sSsid;//如果这个按钮被用于WIFI列表中的按钮,这个成员变量必须要赋值成ssid,否则的话是普通按钮.
void SetTextColor(COLORREF crColor);
void SetSsidString(CString ssid);
virtual void DrawItem(LPDRAWITEMSTRUCT lpDrawItemStruct);
afx_msg void OnLButtonUp(UINT nFlags, CPoint point);
};-------------------------------------------------------------------------------
// MyBitmapBtn.cpp : 实现文件#include "stdafx.h"
#include "MyBitmapBtn.h"IMPLEMENT_DYNAMIC(CMyBitmapBtn, CBitmapButton)CMyBitmapBtn::CMyBitmapBtn():m_sSsid("")
{
}CMyBitmapBtn::~CMyBitmapBtn()
{
}
BEGIN_MESSAGE_MAP(CMyBitmapBtn, CBitmapButton)
ON_WM_LBUTTONUP()
END_MESSAGE_MAP()
void CMyBitmapBtn::SetTextColor(COLORREF crColor)
{
TextColor = crColor;
}
void CMyBitmapBtn::DrawItem(LPDRAWITEMSTRUCT lpDrawItemStruct)
{
// TODO: Add your code to draw the specified item
CRect rect = lpDrawItemStruct->rcItem;
CDC *pDC = CDC::FromHandle(lpDrawItemStruct->hDC);
int nSaveDC = pDC->SaveDC();
UINT state = lpDrawItemStruct->itemState;
TCHAR strText[MAX_PATH + 1];
::GetWindowText(m_hWnd, strText, MAX_PATH);
CBitmapButton::DrawItem(lpDrawItemStruct);
pDC->SetTextColor(TextColor);
if (strText!=NULL)
{
CFont *hFont = GetFont();
CFont *hOldFont = pDC->SelectObject(hFont);
CSize szExtent = pDC->GetTextExtent(strText, lstrlen(strText));
CPoint pt(rect.CenterPoint().x - szExtent.cx / 2, rect.CenterPoint().y - szExtent.cy / 2);
if (state & ODS_SELECTED)
{
pt.Offset(1,1);
}
int nMode = pDC->SetBkMode(TRANSPARENT);
if (state & ODS_DISABLED)
{
pDC->DrawState(pt, szExtent, strText, DSS_DISABLED, TRUE, 0, (HBRUSH)NULL);
}
else
{
pDC->DrawState(pt, szExtent, strText, DSS_NORMAL, TRUE, 0, (HBRUSH)NULL);
}
pDC->SelectObject(hOldFont);
pDC->SetBkMode(nMode);
}
pDC->RestoreDC(nSaveDC);
}void CMyBitmapBtn::SetSsidString(CString ssid)
{
m_sSsid = ssid;
}void CMyBitmapBtn::OnLButtonUp(UINT nFlags, CPoint point)
{
// TODO: 在此添加消息处理程序代码和/或调用默认值
if (!m_sSsid.IsEmpty())
{
CString* str = new CString(m_sSsid);
assert(str);
::PostMessage(this->GetParent()->m_hWnd,WM_CONNECTWIFI,(WPARAM)str,1);
OutputDebugString("-----------------右键消息\n");
}
else
{
CBitmapButton::OnLButtonUp(nFlags, point);
}
}
解决方案 »
- 下面阴影处理中// GetRValue(oldcolor) * alpha / 1;改成/255,怎么与/1没什么变化?????
- 用c++实现:输入unicode码输出汉字
- 《新手》想做个c语言考试系统,打算用vc开发,请高手提点意见或者类似的源代码?
- 如何使用代码设置当前用户不能在计算机管理---磁盘管理中格式化和更改盘符
- 我在对话框里用了浏览器控件,怎么按ESC或回车键。这个控件会突然消失呢?
- MFC第二次建了对话框后,出现了一个问题,求高手解决!
- 问一个ODBC的编程问题
- 应届毕业生,到深圳,起薪才给我3000,是不是低了点?
- 怎样用vc编出来的程序能够隐藏起来,就象任务管理器那样
- 如何使得自己的程序不被关闭( Win98,Win2K )?
- 求字符数组转16进制
- mfc如何从txt文件中读取数据并保存到数组中?如下图txt内容
if (pMsg->message == WM_LBUTTONUP)
{
int a = 0;
OutputDebugString("!!!!!!!!!!!!!!!!!!消息调度\n");
}
正常情况下, 鼠标消息是不可能自动增加的. 按一下是一下.或者新建一个工程, 看在其它MFC标准对话框中鼠标事件是否会变多.
!!!!!!!!!!!!!!!!!!按下--消息调度捕获
!!!!!!!!!!!!!!!!!!抬起--消息调度捕获
-----------------右键消息
****************创建了连接WIFI线程
Call send message cmd 3
Call send message cmd 4
!!!!!!!!!!!!!!!!!!按下--消息调度捕获
!!!!!!!!!!!!!!!!!!抬起--消息调度捕获
-----------------右键消息
****************创建了连接WIFI线程
Call send message cmd 4
这里是做了什么呢?
{
// TODO: 在此添加消息处理程序代码和/或调用默认值
if (!m_sSsid.IsEmpty())
{
/*
CString* str = new CString(m_sSsid);
assert(str);
::PostMessage(this->GetParent()->m_hWnd,WM_CONNECTWIFI,(WPARAM)str,1);
*/
OutputDebugString("-----------------右键消息\n");
}
else
{
CBitmapButton::OnLButtonUp(nFlags, point);
}
}