|
//-----------------------------------------------------------------------------
#include "StdAfx.h"
#include "resource.h"
#include "ArxMsgHandler.h"
//-----------------------------------------------------------------------------
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
//-----------------------------------------------------------------------------
//工具栏按钮的相关设置
#define BUTTON_COUNT 6
#define BUTTON_WIDTH 16
#define BUTTON_HEIGHT 16
#define BUTTON_ID 10240
extern HINSTANCE _hInstance;
//-----------------------------------------------------------------------------
IMPLEMENT_DYNAMIC (CArxMsgHandler, CWnd)
BEGIN_MESSAGE_MAP(CArxMsgHandler, CWnd)
//{{AFX_MSG_MAP(CArxMsgHandler)
ON_WM_CREATE()
ON_WM_DESTROY()
ON_COMMAND_RANGE(BUTTON_ID, BUTTON_ID + BUTTON_COUNT - 1, OnSendCmd)
ON_NOTIFY_EX(TTN_NEEDTEXT, 0, OnTipText)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
//-----------------------------------------------------------------------------
CArxMsgHandler::CArxMsgHandler()
{
}
CArxMsgHandler::~CArxMsgHandler()
{
}
int CArxMsgHandler::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
if (CWnd::OnCreate(lpCreateStruct) == -1)
return -1;
m_imageList.Create(BUTTON_WIDTH, BUTTON_HEIGHT, ILC_COLOR32|ILC_MASK, 6, 6);
m_imageList.Add(::LoadIcon(_hInstance, MAKEINTRESOURCE(IDI_ICON1)));
m_imageList.Add(::LoadIcon(_hInstance, MAKEINTRESOURCE(IDI_ICON2)));
m_imageList.Add(::LoadIcon(_hInstance, MAKEINTRESOURCE(IDI_ICON3)));
m_imageList.Add(::LoadIcon(_hInstance, MAKEINTRESOURCE(IDI_ICON4)));
m_imageList.Add(::LoadIcon(_hInstance, MAKEINTRESOURCE(IDI_ICON5)));
m_imageList.Add(::LoadIcon(_hInstance, MAKEINTRESOURCE(IDI_ICON6)));
TBBUTTON tbButton[BUTTON_COUNT] = {0};
for(int i = 0; i < BUTTON_COUNT; i++)
{
tbButton[i].dwData = NULL;
tbButton[i].fsState = TBSTATE_ENABLED;
tbButton[i].fsStyle = (BYTE)(TBSTYLE_FLAT);//add tips
tbButton[i].iBitmap = i;
tbButton[i].idCommand = BUTTON_ID + i;
}
// 创建工具栏
m_pToolbar = new CAcToolBar;
m_pToolbar->Create(acedGetAcadFrame(), this);
m_pToolbar->EnableDocking(CBRS_ALIGN_ANY);
m_pToolbar->GetToolBarCtrl().SetImageList(&m_imageList);
m_pToolbar->GetToolBarCtrl().AddButtons(BUTTON_COUNT, tbButton);
CSize buttonSize(BUTTON_WIDTH, BUTTON_WIDTH);
m_pToolbar->SetSizes(buttonSize, buttonSize);
CRect rect;
acedGetAcadDwgView()->GetClientRect(rect);
CPoint pt = rect.TopLeft();
::ClientToScreen(acedGetAcadDwgView()->m_hWnd, &pt);
acedGetAcadFrame()->FloatControlBar(m_pToolbar, pt, CBRS_ALIGN_TOP);
acedGetAcadFrame()->ShowControlBar(m_pToolbar, TRUE, TRUE);
return 0;
}
void CArxMsgHandler::OnDestroy()
{
// 销毁工具栏
delete m_pToolbar;
m_pToolbar = NULL;
CWnd::OnDestroy();
}
void CArxMsgHandler::OnSendCmd(UINT id)
{
acutPrintf(_T("id = %d\n"), id);
switch (id)
{
case BUTTON_ID:
acDocManager->sendStringToExecute(acDocManager->curDocument(), _T("line "));
break;
case BUTTON_ID + 1:
acDocManager->sendStringToExecute(acDocManager->curDocument(), _T("arc "));
break;
case BUTTON_ID + 2:
acDocManager->sendStringToExecute(acDocManager->curDocument(), _T("circle "));
break;
case BUTTON_ID + 3:
acDocManager->sendStringToExecute(acDocManager->curDocument(), _T("rectangle "));
break;
case BUTTON_ID + 4:
acDocManager->sendStringToExecute(acDocManager->curDocument(), _T("point "));
break;
case BUTTON_ID + 5:
acDocManager->sendStringToExecute(acDocManager->curDocument(), _T("ellipse "));
break;
default:
break;
}
}
BOOL CArxMsgHandler::OnTipText(UINT id, NMHDR* pNMHDR, LRESULT *pResult)
{
TOOLTIPTEXT * pTTT = (TOOLTIPTEXT*)(pNMHDR);
UINT_PTR nID = pNMHDR->idFrom;
if (nID)
{
int nIndex = m_pToolbar->CommandToIndex(nID);
CString strTipText= _T("");
//判断索引是否正确
if (-1 != nIndex)
{
//获得提示信息
pTTT->lpszText = _T("信息提示");
//获得资源句柄
//pTTT->hinst = AfxGetResourceHandle();
return true;
}
}
return TRUE;
}
//
//静态变量及函数
CArxMsgHandler *CArxMsgHandler::pgArxMsgHandler = NULL;
BOOL CArxMsgHandler::CreateArxMsgHandler()
{
if (pgArxMsgHandler != NULL)
{
if (pgArxMsgHandler->GetSafeHwnd() != NULL)
return TRUE;
}
else
{
pgArxMsgHandler = new CArxMsgHandler;
}
return pgArxMsgHandler->Create(NULL, NULL, WS_CHILD | WS_MINIMIZE, CRect(0, 0, 1, 1), acedGetAcadFrame(), 10);
}
void CArxMsgHandler::DestroyArxMsgHandler()
{
if (pgArxMsgHandler == NULL)
return;
if ( pgArxMsgHandler->GetSafeHwnd() != NULL)
pgArxMsgHandler->DestroyWindow();
delete pgArxMsgHandler;
pgArxMsgHandler = NULL;
}
CArxMsgHandler *CArxMsgHandler::GetArxMsgHandler()
{
if (pgArxMsgHandler != NULL && pgArxMsgHandler->GetSafeHwnd() != NULL)
return pgArxMsgHandler;
return NULL;
}
void CArxMsgHandler::ShowToolbar()
{
CAcToolBar* p = GetArxMsgHandler()->GetToolBar();
if (p != NULL)
acedGetAcadFrame()->ShowControlBar(p, TRUE, TRUE);
} |
|