深入浅出CChart 每日一课——快乐高四第三十七课 牢记使命,Fortran 对话框窗口绘制柱图

本文介绍CChart在Fortran窗口程序中的应用,以在对话框窗口绘制柱图为例。详细说明了建立Fortran Windows Application、调整对话框和控件大小、添加代码、导入接口函数等步骤,还提醒了Fortran与C++数组编号差异在混合编程时需注意。

这节课继续介绍CChart在Fortran窗口程序里面的应用,作为演示,将在对话框窗口里绘制柱图。

话不多说,直接开始。

第一步,建立一个Fortran Windows Application,名字为LessonA36,选择A simple Dialog Based Application,拷贝CChart.lib,CChart.dll到LessonA36文件夹,并把CChart.lib添加到项目里面。

第二步,在资源管理器中,打开主对话框,删除“TODO: Place dialog controls here.”标签,增加一个Picture控件,ID为IDC_CANVAS,同时调整对话框和控件的大小。

第三步,打开LessonA37.f90文件,找到SUBROUTINE LessonA37Sub( dlg, id, callbacktype )这个过程,在implicit none这一行后面,增加一行代码。

include 'resource.fd'

这是为了在过程中使用对话框及控件的ID

第四步,在上一行代码的后面,增加导入接口的代码。

	interface
	subroutine CreateChart()
		!DEC$ATTRIBUTES DLLIMPORT,ALIAS:'?CreateChart@Classless@@YAXXZ'::CreateChart
	end subroutine CreateChart
	end interface

	interface
	subroutine DestroyChart()
		!DEC$ATTRIBUTES DLLIMPORT,ALIAS:'?DestroyChart@Classless@@YAXXZ'::DestroyChart
	end subroutine DestroyChart
	end interface

	interface
	integer function AttachDlg(hDlg, nCtrlID, nType)
		!DEC$ATTRIBUTES DLLIMPORT,ALIAS:'?AttachDlg@Classless@@YAHPAUHWND__@@IH@Z'::AttachDlg
		!DEC$ATTRIBUTES VALUE::hDlg, nCtrlID, nType
		integer hDlg, nCtrlID, nType
	end function AttachDlg
	end interface

	interface
	integer function AddStems(pData, nLen, title)
		!DEC$ATTRIBUTES DLLIMPORT,ALIAS:'?AddStems@Classless@@YAHPANHPAD@Z'::AddStems
		!DEC$ATTRIBUTES VALUE::pData, nLen, title
		integer pData, nLen, title
	end function AddStems
	end interface

	interface
	subroutine SetStemLabel(label, which)
		!DEC$ATTRIBUTES DLLIMPORT,ALIAS:'?SetStemLabel@Classless@@YAXPBDH@Z'::SetStemLabel
		!DEC$ATTRIBUTES VALUE::label, which
		integer label, which
	end subroutine SetStemLabel
	end interface

	interface
	subroutine SetTitle(title)
		!DEC$ATTRIBUTES DLLIMPORT,ALIAS:'?SetTitle@Classless@@YAXPBD@Z'::SetTitle
		!DEC$ATTRIBUTES VALUE::title
		integer title
	end subroutine SetTitle
	end interface

	interface
	subroutine SetLegendShow(bShow, nPlotIndex)
		!DEC$ATTRIBUTES DLLIMPORT,ALIAS:'?SetLegendShow@Classless@@YAX_NH@Z'::SetLegendShow
		!DEC$ATTRIBUTES VALUE::bShow, nPlotIndex
		integer*1 bShow
		integer nPlotIndex
	end subroutine SetLegendShow
	end interface

导入方法和前面的课程完全一样,这里导入了CreateChart,DestroyChart,AttachDlg,AddStems,SetStemLabel,SetTitle,SetLegendShow这7个函数。

第五步,在integer id, callbacktype这一行下面,再增加一个双精度数组。

double precision pData(5)

第六步,在if (callbacktype == dlg_destroy) then这一行的上面,增加对话框初始化代码。

if (callbacktype == dlg_init) then
	call CreateChart()
	call AttachDlg(dlg%hwnd, IDC_CANVAS, 2)
	pData(1) = 7
	pData(2) = 6
	pData(3) = 1
	pData(4) = 2
	pData(5) = 4
	call AddStems(LOC(pData), 5, LOC("序列1"C))
	pData(1) = 3
	pData(2) = 7
	pData(3) = 5
	pData(4) = 4
	pData(5) = 2
	call AddStems(LOC(pData), 5, LOC("序列2"C))

	call SetStemLabel(LOC("张"C), 0)
	call SetStemLabel(LOC("王"C), 1)
	call SetStemLabel(LOC("李"C), 2)
	call SetStemLabel(LOC("赵"C), 3)
	call SetStemLabel(LOC("陈"C), 4)

	call SetLegendShow(1, 0)
	call SetTitle(LOC("Fortran对话框标题"))
endif

注意到Fortran数组起始编号为1,而C++数组起始编号为0,混合编程时,这要特别小心。上面的代码里面,两者都有。

第七步,在if (callbacktype == dlg_destroy) then的下一行,增加代码。

call DestroyChart()

终于完成了,结果如图。

效果还是不错的!

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值