#include
#include
#include
#define Test(x,y) x##y //自动连接 xy
#define T2(x) #x //自动转为字符串 "x"
int main()
{
auto p = Test(Message, Box);
(*p)(NULL, _T(T2(Hello aaa)), _T("温馨提示"), 0);
puts(T2(hehehe hahaha));
return 0;
}
因为这边用24色位图 尺寸过大不符合所以返回了NULL
if((lpBitmap== NULL)||(lpBitmap->biBitCount>8))//要不就是你加载的图片为空 要不图像尺寸大于256色了
if (!m_toolBox.CreateEx(this, TBSTYLE_FLAT, WS_CHILD | WS_VISIBLE | CBRS_TOP
| CBRS_GRIPPER | CBRS_TOOLTIPS | CBRS_FLYBY | CBRS_SIZE_DYNAMIC) ||
!m_toolBox.LoadToolBar(IDR_TOOLBOX))
{
TRACE0("未能创建工具栏\n");
return -1; // 未能创建
}
LPBITMAPINFOHEADER lpBitmap = (LPBITMAPINFOHEADER)LockResource(hglb);
if ((lpBitmap == NULL) || (lpBitmap->biBitCount > 8))
{
return NULL;
}
例如:
afx_msg void OnDrawTools(UINT);
/*afx_msg void OnDrawEllipse();
afx_msg void OnDrawLine();
afx_msg void OnDrawPencil();
afx_msg void OnDrawPolygon();
afx_msg void OnDrawRect();
afx_msg void OnDrawRrect(); */
afx_msg void OnUpdateDrawTools(CCmdUI* pCmdUI);
/*afx_msg void OnUpdateDrawDrag(CCmdUI* pCmdUI);
afx_msg void OnUpdateDrawEllipse(CCmdUI* pCmdUI);
afx_msg void OnUpdateDrawLine(CCmdUI* pCmdUI);
afx_msg void OnUpdateDrawPencil(CCmdUI* pCmdUI);
afx_msg void OnUpdateDrawPolygon(CCmdUI* pCmdUI);
afx_msg void OnUpdateDrawRect(CCmdUI* pCmdUI);
afx_msg void OnUpdateDrawRrect(CCmdUI* pCmdUI);*/
//void CMainView::OnDrawDrag(){
// m_nIndex = ID_DRAW_DRAG;
//}
//void CMainView::OnDrawEllipse(){
// m_nIndex = ID_DRAW_ELLIPSE;
//}
//void CMainView::OnDrawLine(){
// m_nIndex = ID_DRAW_LINE;
//}
//void CMainView::OnDrawPencil(){
// m_nIndex = ID_DRAW_PENCIL;
//}
//void CMainView::OnDrawPolygon(){
// m_nIndex = ID_DRAW_POLYGON;
//}
//void CMainView::OnDrawRect()
//{
// m_nIndex = ID_DRAW_RECT;
//}
//void CMainView::OnDrawRrect()
//{
// m_nIndex = ID_DRAW_RRECT;
//}
//void CMainView::OnUpdateDrawDrag(CCmdUI* pCmdUI)
//{
// //pCmdUI->SetCheck(m_nIndex == ID_DRAW_DRAG);
// pCmdUI->SetCheck(m_nIndex == pCmdUI->m_nID);
//}
//void CMainView::OnUpdateDrawEllipse(CCmdUI* pCmdUI)
//{
// pCmdUI->SetCheck(m_nIndex == pCmdUI->m_nID);
//}
//void CMainView::OnUpdateDrawLine(CCmdUI* pCmdUI)
//{
// pCmdUI->SetCheck(m_nIndex == pCmdUI->m_nID);
//}
//void CMainView::OnUpdateDrawPencil(CCmdUI* pCmdUI)
//{
// pCmdUI->SetCheck(m_nIndex == pCmdUI->m_nID);
//}
//void CMainView::OnUpdateDrawPolygon(CCmdUI* pCmdUI)
//{
// pCmdUI->SetCheck(m_nIndex == pCmdUI->m_nID);
//}
//void CMainView::OnUpdateDrawRect(CCmdUI* pCmdUI)
//{
// pCmdUI->SetCheck(m_nIndex == pCmdUI->m_nID);
//}
//void CMainView::OnUpdateDrawRrect(CCmdUI* pCmdUI)
//{
// pCmdUI->SetCheck(m_nIndex == pCmdUI->m_nID);
//}
void CMainView::OnDrawTools(UINT nID)
{
m_nIndex = nID;
}
void CMainView::OnUpdateDrawTools(CCmdUI* pCmdUI)
{
//pCmdUI->SetCheck(); //这个TRUE的话7个都会亮起来
pCmdUI->SetCheck(pCmdUI->m_nID == m_nIndex);
}
#define ON_COMMAND(id, memberFxn) \ 一消息一函数
{WM_COMMAND,CN_COMMAND,(WORD)id,(WORD)id,AfxSigCmd_v,static_cast<AFX_PMSG> (memberFxn)},
// ON_COMMAND(id, OnBar) is the same as
// ON_CONTROL(0, id, OnBar) or ON_BN_CLICKED(0, id, OnBar)
#define ON_COMMAND_RANGE(id, idLast, memberFxn) \
一消息的范围 参数为 起始消息 到最终消息 都来搞memberFxn) 这个函数
{ WM_COMMAND, CN_COMMAND, (WORD)id, (WORD)idLast, AfxSigCmd_RANGE, \
(AFX_PMSG) \
(static_cast< void (AFX_MSG_CALL CCmdTarget::*)(UINT) > \
(memberFxn)) },
// ON_COMMAND_RANGE(id, idLast, OnBar) is the same as
// ON_CONTROL_RANGE(0, id, idLast, OnBar)
有可能是没有进行初始化
#include 对应头文件
using namespace Gdiplus;命名空间
GdiplusStartupInput gdiplusStartupInput;
ULONG_PTR gdiplusToken;
GdiplusStartup(&gdiplusToken, &gdiplusStartupInput, NULL);
确保句柄有效
if (pDC->GetSafeHdc() == NULL) {
// 绘图上下文无效,无法绘制
return;
}
Graphics g(pDC->GetSafeHdc());