天气与日历 切换到窄版

 找回密码
 立即注册
中国膜结构网
十大进口膜材评选 十大国产膜材评选 十大膜结构设计评选 十大膜结构公司评选
查看: 66|回复: 0

ObjectARX 工具栏控件

[复制链接]

该用户从未签到

主题

0

回帖

2912

积分

管理员

积分
2912
发表于 2024-6-22 09:46:18 | 显示全部楼层 |阅读模式
//-----------------------------------------------------------------------------
#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);
}

 

 

 

 

ObjectARX 工具栏控件
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

QQ|Archiver|中国膜结构网|中国膜结构协会|进口膜材|国产膜材|ETFE|PVDF|PTFE|设计|施工|安装|车棚|看台|污水池|中国膜结构网_中国空间膜结构协会

GMT+8, 2024-11-1 13:25 , Processed in 0.156068 second(s), 27 queries .

Powered by Discuz! X3.5

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表