请教,ActiveX控件的事件响应函数的引用参数,如何返回值?

我在窗体中添加了一个ActiveX控件:FlexGrid,并用comObjConnect(),绑定到用ahk写的事件响应类,其中一个事件函数BeforeRowColChange(),官方文档如下:

Syntax
Private Sub VSFlexGrid_BeforeRowColChange( ByVal OldRow As Long,  ByVal OldCol As Long,  ByVal NewRow As Long,  ByVal NewCol As Long, Cancel As Boolean)
Example:
‘ cancel if new cell is in protected area
Private Sub fg_BeforeRowColChange(ByVal OldRow As Long, ByVal OldCol As Long, _
ByVal NewRow As Long, ByVal NewCol As Long, Cancel As Boolean)
If NewRow >= 2 And NewRow <= 8 And NewCol >= 2 And NewCol <= 4 Then Cancel = True
End Sub
‘ cancel if new selection is on protected area
Private Sub fg_BeforeSelChange(ByVal OldRowSel As Long, ByVal OldColSel As Long, _
ByVal NewRowSel As Long, ByVal NewColSel As Long, Cancel As Boolean)
If (fg.Row < 2 And NewRowSel < 2) Or (fg.Col < 2 And NewColSel < 2) Then Exit Sub
If (fg.Row > 8 And NewRowSel > 8) Or (fg.Col > 4 And NewColSel > 4) Then Exit Sub
Cancel = True
End Sub

函数没有返回值,通过改变传入参数Cancel的值为True,来阻止事件的行为继续发生,参数Cancel应该是按址传入的,但我在ahk中修改该参数值为True,或 ComObject(0xB,-1) 后,都不起作用。请教如何解决?查看ahk相关文档描述如下:

ComObjConnect() [v1.0.90+]
……
Usage
To make effective use of ComObjConnect, you must first write functions in the script to handle any events of interest. Such functions, or “event-handlers,” have the following structure:
PrefixEventName([Params…, ComObject])
{
… event-handling code …
return ReturnValue
}
……
ComObject is optional, and can only be used if the correct number of Params are defined; it contains a reference to the original wrapper object which was passed to ComObjConnect. “ComObject” should be replaced with a name more meaningful in the context of your script.
Note that event handlers may have return values. To return a COM-specific type of value, use ComObject(type, value). For example, return ComObject(0,0) returns a variant of type VT_EMPTY, which is equivalent to returning undefined (or not returning) from a JavaScript function.

对于事件函数PrefixEventName([Params…, ComObject])参数中有个ComObject,是不是可以回传的参数,应该怎么写才对?附部分代码:
Class MainFormGui extends GuiBase {
	Init() {
		this.data:={"Payments_id":0,"PayForm_id":0
					,"StatusBarInfo":""
					,"ddl_month":{"list":[1,2,3,4,5,6,7,8,9,10,11,12],"choose":A_MM*1}
					,"ddl_sender":{"list":["全部"],"choose":1}
					,"ddl_receiver":{"list":["全部"],"choose":1}
					,"ddl_handoverList":{"list":["全部"],"choose":1}
					,"ddl_CheckedList":{"list":["全部","待报送","待接收","已接收"],"choose":1}
					,"fg_payments":{"Headers":[" 编号","日期","用途","金额","科室","经办人","收款账户","备注"]
									,"data":this.fgPaymentsEvents.GridData,count:0,sum:0}}
		
		this.Font("s14","宋体")
		this.sb := this.AddStatusBar()
		this.AddText("x10 y8 w60 h23 ","期间:")
		this.ddl_month := this.AddDropDownList("x70 y6 w50 h23 r12", this.data.ddl_month.list).OnEvent(this.ddl_monthChange.Bind(this))
		this.AddText("x140 y8 w80 h23 ","报账员:")
		this.ddl_sender := this.AddDropDownList("x210 y6 w100 h23 r10 AltSubmit").OnEvent(this.ddl_senderChange.Bind(this))
		this.AddText("x330 y8 w80 h23 ","接收人:")
		this.ddl_receiver := this.AddDropDownList("x410 y6 w100 h23 r10 AltSubmit").OnEvent(this.ddl_receiverChange.Bind(this))
		this.AddText("x530 y8 w80 h23 ","移交单:")
		this.ddl_handoverList := this.AddDropDownList("x610 y6 w160 h23 r10 AltSubmit").OnEvent(this.handoverListChange.Bind(this))
		this.AddText("x790 y8 w60 h23 ","状态:")
		this.ddl_CheckedList := this.AddDropDownList("x850 y6 w100 h23 r4 AltSubmit",this.data.ddl_CheckedList.list).OnEvent(this.ddl_CheckedListChange.Bind(this))
		;数据表,使用ComponentOne FlexGrid8组件。
		this.fg_payments := this.AddFlexGrid("x10 y36 w1180 h500",this.data.fg_payments.Headers)
		this.fg_payments.ConnectEvents(MainFormGui.fgPaymentsEvents)
		Captions := {"add":"新增","modify":"修改","save":"保存","delete":"删除","cancle":"取消"}
		this.fg_payments.CRUD := this.AddCRUDButtonGroup("x10 y536 w200 h36",Captions,[this.fg_payments.ax,this.fgPaymentsEvents.onSave.Bind(this)])
		
		this.Refresh()
	}
......
class fgPaymentsEvents{
		static ax
		static GridData:=ComObjArray(VT_VARIANT:=12,8,50,10)
		Init(){
			this.ax.FontSize        := 14
			;~ this.ax.Editable        := True
			this.ax.AutoResize      := True
			this.ax.AllowUserResizing := (flexResizeColumns:=1)
			this.ax.FixedCols       := 0
			this.ax.ColWidthMin     := 1200
			this.ax.ColDataType(3)  := (FlexDTCurrency:=6)
			this.ax.ColFormat(3)    := "$#,###.00"
			this.ax.ColEditMask(3)  := "#########.##"
			this.ax.ColAlignment(3):= (FlexAlignRightCenter:=7)
			
			this.ax.ColDataType(9)  := flexdtBoolean
			this.ax.ColDataType(10) := flexdtBoolean
			;~ this.ax.ColComboList(5) := c_Data.get_person_comboList()
			;~ this.ax.ColComboList(6) := c_Data.get_bank_comboList()
			this.ax.ComboSearch    := (FlexCmbSearchAll:=3)
			;~ this.ax.ColComboList(1) := "North|South|East|West"
			;~ this.ax.ColComboList(2) := "|Mary|Paula|Sarah"
			
			;~ this.GridData:=ComObjArray(VT_VARIANT:=12,this.ax.Cols,GridPaymentsRows,10)
			this.ax.BindToArray(this.GridData)
		}
		BindToData(dataSrc){
			this.dataSrc:=dataSrc
		}
		
		onSave(){
			;
			return true
		}
		
		BeforeRowColChange( OldRow,  OldCol,  NewRow,  NewCol, ByRef Cancel){
			if(this.ax.Editable && OldRow!=NewRow){
				Cancel:=ComObject(0xB,-1)
			}
		}
	}
}

给TA捐赠
共{{data.count}}人
人已捐赠
其他案例

[AHK]F1键定位当前Word中打开着的文档

2020-3-3 21:56:07

其他

1.2-AutoHotkey鼠标手势2(线程结构)

2020-3-7 21:59:01

2 条回复 A文章作者 M管理员
  1. Cynric肖鹏

    GUI用了第三方库AHK-Object-Oriented-GUIs-master。
    关于FlexGrid控件自己作了扩展。
    用面向对象的方式来写界面,比原生AHK GUI函数舒服多了。贴一下我扩展的FlexGrid控件类。

    Class FlexGridControl extends GuiBase.ControlType {
    	Type := "FlexGrid"
    	
    	__New(Gui, Options := "", Headers := "", cols := 1) {
    		this.Gui := Gui
    		
    		Gui % this.Gui.hwnd ":Add", ActiveX, % "hwndhwnd " Options, VSFlexGrid8.VSFlexGridL 
    		this.hwnd := hwnd
    		GuiControlGet, ctlFlexGrid,, %hwnd%,
    		this.ax:=ctlFlexGrid
    		
    		if(Headers){
    			this.ax.Cols := cols
    			this.ax.FormatString := Headers
    			
    		}
    		
    		SafeRef := new IndirectReferenceHolder(this)
    		
    		this.Position := new GuiBase.ControlPosition(SafeRef)
    		
    		this.Gui.Print(this.__Class " created")
    		
    		return SafeRef
    	}
    	
    	ConnectEvents(FlexGridEvents){
    		FlexGridEvents.ax:=this.ax
    		ComObjConnect(this.ax, FlexGridEvents)
    		FlexGridEvents.Init()
    	}
    }
    
  2. hexuren

    不错 用空测试一下

个人中心
购物车
优惠劵
有新私信 私信列表
搜索