VTK+MFC:建立自定义控件显示
来源:互联网 发布:软件源代码出售合同 编辑:程序博客网 时间:2024/06/17 02:21
这里我们用MFC框架来做VTK的界面
VTK比较蛋疼的是不能像图片一样直接在MFC的picture控件中显示,需要自己添加自定义控件来显示画出的模型,
1.首先新建一个类如MyCustomControl
Ctrl+W打开建立类向导界面,选择Add Class->new
名字填写如MyCustomControl
Base class选择generic CWnd
2.在MyCustomControl.cpp文件中添加如下代码:
注册代码:
BOOL MyCustomControl::RegisterWndClass(){ WNDCLASS windowclass; HINSTANCE hInst = AfxGetInstanceHandle(); //Check weather the class is registerd already if (!(::GetClassInfo(hInst, MYWNDCLASS, &windowclass))) { //If not then we have to register the new class windowclass.style = CS_DBLCLKS;// | CS_HREDRAW | CS_VREDRAW; windowclass.lpfnWndProc = ::DefWindowProc; windowclass.cbClsExtra = windowclass.cbWndExtra = 0; windowclass.hInstance = hInst; windowclass.hIcon = NULL; windowclass.hCursor = AfxGetApp()->LoadStandardCursor(IDC_ARROW); windowclass.hbrBackground = ::GetSysColorBrush(COLOR_WINDOW); windowclass.lpszMenuName = NULL; windowclass.lpszClassName = MYWNDCLASS; if (!AfxRegisterClass(&windowclass)) { AfxThrowResourceException(); return FALSE; } } return TRUE;}
在构造函数中添加:
RegisterWndClass();
添加响应函数:
void MyCustomControl::OnLButtonDown(UINT nFlags, CPoint point) { // TODO: Add your message handler code here and/or call default if(flag==FALSE) { oldpt=point; flag=TRUE; } CWnd::OnLButtonDown(nFlags, point);}void MyCustomControl::OnLButtonUp(UINT nFlags, CPoint point) { // TODO: Add your message handler code here and/or call default flag=FALSE; CWnd::OnLButtonUp(nFlags, point);}void MyCustomControl::OnMouseMove(UINT nFlags, CPoint point) { // TODO: Add your message handler code here and/or call default if(flag==TRUE) { CDC *d=GetDC(); d->MoveTo(oldpt); d->LineTo(point); oldpt=point; ReleaseDC(d); } CWnd::OnMouseMove(nFlags, point);}
这几个分别是控制右键按下时vtk画出来的模型的放大缩小,左键按下时vtk模型的旋转,鼠标在自定义控件窗口的移动
再在BEGIN_MESSAGE_MAP(MyCustomControl, CWnd)添加
ON_WM_LBUTTONDOWN()
ON_WM_LBUTTONUP()
ON_WM_MOUSEMOVE()
2.右键点击添加自定义控件在种类中命名如MyDrawPad
3.在MyCustomControl.hpp文件中添加声明等
在文件开头添加:
#define MYWNDCLASS "MyDrawPad"
在public中添加:
MyCustomControl();BOOL SetBitmap(UINT nIDResource);
在protect中修改(添加一些消息相应):
//{{AFX_MSG(MyCustomControl) afx_msg void OnLButtonDown(UINT nFlags, CPoint point); afx_msg void OnLButtonUp(UINT nFlags, CPoint point); afx_msg void OnMouseMove(UINT nFlags, CPoint point); // NOTE - the ClassWizard will add and remove member functions here. //}}AFX_MSG
在private中添加:
private: CDC cDC; BOOL RegisterWndClass(); CPoint oldpt; BOOL flag;
4.在Dlg.cpp中为自定义空键添加变量:
在::DoDataExchange(CDataExchange* pDX)中添加
DDX_Control(pDX,IDC_moxing,m_drawpad1);
5.在Dlh.h中添加头文件:
#include “MyCustomControl.h”
在protected中添加变量:
MyCustomControl m_drawpad1;
6.在vtk要显示的时候加上获取窗口的代码:
vtkRenderer *ren = vtkRenderer::New(); ren->SetBackground(1.0, 1.0, 1.0); vtkRenderWindow *renWindow = vtkRenderWindow::New(); renWindow->AddRenderer(ren); //renWindow->SetSize( 200, 200 ); CRect rect; GetClientRect(&rect); m_drawpad1.GetClientRect(&rect); renWindow->SetParentId(m_drawpad1.m_hWnd); renWindow->SetSize(rect.Width(),rect.Height());
之后可以在mfc框架下显示vtk画出的图像
我用了十五年,帮那时候我最喜欢的女生追回了她的丈夫……
- VTK+MFC:建立自定义控件显示
- VTK嵌入MFC同步显示
- 高版本vtk 的MFC显示
- VTK+MFC
- MFC自定义控件
- MFC自定义控件
- MFC自定义控件
- MFC 控件全屏显示
- mfc edit控件显示
- 把pcl的VTK显示融合到MFC
- VTK:VTK嵌入MFC成功
- Qt下结合vtk控件显示深度图像
- MFC工具栏添加自定义控件
- MFC 自定义控件使用实践
- mfc自定义控件的编程
- MFC控件的自定义绘制
- MFC中控件位图显示
- mfc 窗口控件全屏显示
- 【洛谷P1115】最大子段和
- ubuntu安装groovy
- 文章标题
- 【动态规划】牛符号
- bat批量脚本的简单介绍
- VTK+MFC:建立自定义控件显示
- 小笔记
- Java中使用Runnable接口创建并启动多线程
- java——jdbc数据库连接
- PAT L2044(二叉搜索树的判断)
- 大整数乘法
- 【Mac/ios】Swift3.0 BLE开发
- react native 控件联动
- 第五章 问题的模块化求解