Fusion 360 API : 调用MFC对话框

原文地址: http://modthemachine.typepad.com/my_weblog/2016/02/fusion-add-in-with-mfc.html

我的同事Adam研究了一个有趣的内容,即如何在Fusion 360调用传统的MFC对话框。显然需要用到C++ API . 开始Adam琢磨基于Fusion 产生的C++插件工程,添加MFC支持,最后发现这个太挫折感,最后他想到一个聪明的办法,先创建一个MFC 的DLL,然后在Fusion C++工程中调用之。搞定!

源码在此:https://github.com/AutodeskFusion360/NativeUI

1) 创建一个MFC DLL

MfcCreate1

MfcCreate2

2) 添加对话框资源

  MfcResource

MfcResourceNew


 3)添加对话框类,并根据需要调整合适的名字。

MfcWizard

4) 在对话框.cpp中增加方法显示对话框

void showDialog()
{  
  // Always call this macro first thing in any function that
  // will use MFC functionality 
  AFX_MANAGE_STATE(AfxGetStaticModuleState());

  CMyDialog myDialog; 
  myDialog.DoModal();
};

在对话框.h文件中增加:

#include "MyDialog.h"

void showDialog();


5) 增减一个名为FusionCode.cpp 的c++文件,并添加如下代码:
FusionCode

#include "stdafx.h"

#include <Core/CoreAll.h>
#include <Fusion/FusionAll.h>

// XI_WIN is a macro added by Fusion headers
// to show if the project is a Windows project
#ifdef XI_WIN
  #include "CustomMfcUi.h"
#endif

using namespace adsk::core;
using namespace adsk::fusion;

Ptr<Application> app;
Ptr<UserInterface> ui;

extern "C" XI_EXPORT bool run(const char* context)
{
  app = Application::get();
  if (!app)
    return false;

  ui = app->userInterface();
  if (!ui)
    return false;

  showDialog();

  return true;
}

extern "C" XI_EXPORT bool stop(const char* context)
{
  if (ui)
  {
    ui->messageBox("in stop");
    ui = nullptr;
  }

  return true;
}

6) 修改工程配置为X64,因为Fusion 360只有64位的。

7) 给工程配置好Fusion 360 C++头文件与库文件所在路径。

8) 编译,生成dll,例如CustomMfcUi.dll 

9) 在 "$(APPDATA)\Autodesk\Autodesk Fusion 360\API\AddIns" 创建一个名为CustomMfcUi的文件夹。并添加一个“CustomMfcUi.manifest"。 其内容为:

    

{
"autodeskProduct":"Fusion360",
"type":"addin",
"author":"",
"description":{"":""},
"supportedOS":"windows",
"editEnabled":false,
"id":"38EE9339-591A-4F72-AFFF-7B20111CC10C",
"version":"1.0.0",
"runOnStartup":false
}

id是个guid

10)  将前面编译好的dll也放到这个文件夹。

11) 启动Fusion后,在插件管理器能看到此插件。

MfcTest


点击它,对话框出现: 

MfcTest2

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值