15,979
社区成员
发帖
与我相关
我的任务
分享
if (pMsg->message == WM_LBUTTONUP)
{
int a = 0;
OutputDebugString("!!!!!!!!!!!!!!!!!!消息调度\n");
}
/*
* @file MyBitmapBtn.h
* @note ...
* @brief 能修改图片的自定义按钮类
* @author ...
* @date 2013/09/20
*/
#pragma once
#define WM_CONNECTWIFI WM_USER+700
class 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);
}
}