为什么ActiveX EXE部件发出的事件,引用他的程序收不到?高分求解。
本帖最后由 JiLuoXingRen 于 2011-07-19 18:42:48 编辑 是这样的,我的程序分为两部分,一部分是ActiveX EXE工程,一部分是标准EXE工程。
ActiveX EXE工程的工程属性设置如下:
事件的声明如下:
引发事件的代码如下:
对象的声明代码如下:
程序显示部件的事件如下:
然后ActiveX EXE工程那一部分已经编译成EXE文件,然后标准EXE工程也已经在引用中引用了他。而且只是事件收不到而已,像我在ActiveX EXE部件里设置的ShowMainfrm方法(用来显示ActiveX EXE部件里的窗体),在标准EXE里调用这个方法,窗体的确能显示出来,在任务管理器里也有ActiveX EXE工程的那个EXE的进程。
有做过ActiveX EXE部件的人帮忙看看,到底是哪出了问题,导致事件收不到呢?
[最优解释]
最好是能提供代码。
[其他解释]
行,不过您看了别晕:
'在ActiveX EXE工程的Mainly类模块里
'变量声明
Dim gCancel As Integer
'常数,枚举声明
Public Enum CloseMode
FormControlMenu = 0 '用户从窗体上的“控件”菜单中选择“关闭”指令。
AppWindows = 1 '当前 Microsoft Windows 操作环境会话结束。
AppTaskManager = 2 'Microsoft Windows 任务管理器正在关闭应用程序。
FormOwner = 3 '因为窗体的所有者正在关闭,所以窗体也在关闭。
SmallToSysTray = 4 '最小化到系统托盘
End Enum
'事件声明
Event MainlyClose(CloseMode As CloseMode) '定义主窗体关闭事件
Event MainInitialize(Progress As Integer, Objects As String, Num As String)
Public Sub Closed(CloseMode As CloseMode)
'主窗体关闭前调用此函数,向图形界面管理器申请关闭
RaiseEvent MainlyClose(CloseMode)
End Sub
Public Function ChangIntegerToMode(UnloadMode As Integer) As CloseMode
'将VB的退出值UnloadMode转换为我的程序的退出值CloseMode
Select Case UnloadMode
Case 0
ChangIntegerToMode = FormControlMenu
Case 1
ChangIntegerToMode = AppWindows
Case 2
ChangIntegerToMode = AppTaskManager
Case 3
ChangIntegerToMode = FormOwner
End Select
End Function
Public Sub ShowMainfrm()
'图形界面管理器调用此方法打开主窗体
Form1.Show
End Sub
Private Sub Class_Initialize()
'主界面初始化
RaiseEvent MainInitialize(0, "Mainprogram", "01")
'获得主窗体的菜单ID
Frmhwnds = GetMenu(Form1.hwnd)
'向文件菜单加图标
'取得在主窗体下的某个子菜单的ID,现在这个是取得文件菜单的ID
hwnds = GetSubMenu(Frmhwnds, 0)
ret = SetMenuItemBitmaps(hwnds, 0, MF_BYPOSITION, Form1.Picture1(0).Picture, 0)
RaiseEvent MainInitialize(10, "Mainprogram", "01")
'向新建菜单项添加图标
ret = SetMenuItemBitmaps(hwnds, 1, MF_BYPOSITION, Form1.Picture1(1).Picture, 0)
ret = SetMenuItemBitmaps(hwnds, 3, MF_BYPOSITION, Form1.Picture1(2).Picture, 0)
ret = SetMenuItemBitmaps(hwnds, 4, MF_BYPOSITION, Form1.Picture1(3).Picture, 0)
ret = SetMenuItemBitmaps(hwnds, 6, MF_BYPOSITION, Form1.Picture1(4).Picture, 0)
ret = SetMenuItemBitmaps(hwnds, 9, MF_BYPOSITION, Form1.Picture1(5).Picture, 0)
RaiseEvent MainInitialize(20, "Mainprogram", "01")
'向编辑菜单加图标
hwnds = GetSubMenu(Frmhwnds, 1)
ret = SetMenuItemBitmaps(hwnds, 0, MF_BYPOSITION, Form1.Picture1(6).Picture, 0)
ret = SetMenuItemBitmaps(hwnds, 1, MF_BYPOSITION, Form1.Picture1(7).Picture, 0)
ret = SetMenuItemBitmaps(hwnds, 3, MF_BYPOSITION, Form1.Picture1(8).Picture, 0)
ret = SetMenuItemBitmaps(hwnds, 4, MF_BYPOSITION, Form1.Picture1(9).Picture, 0)
ret = SetMenuItemBitmaps(hwnds, 5, MF_BYPOSITION, Form1.Picture1(10).Picture, 0)
ret = SetMenuItemBitmaps(hwnds, 7, MF_BYPOSITION, Form1.Picture1(11).Picture, 0)
RaiseEvent MainInitialize(30, "Mainprogram", "01")
'向外接程序菜单加图标
hwnds = GetSubMenu(Frmhwnds, 2)
ret = SetMenuItemBitmaps(hwnds, 0, MF_BYPOSITION, Form1.Picture1(12).Picture, 0)
ret = SetMenuItemBitmaps(hwnds, 1, MF_BYPOSITION, Form1.Picture1(13).Picture, 0)
ret = SetMenuItemBitmaps(hwnds, 2, MF_BYPOSITION, Form1.Picture1(14).Picture, 0)
'向计算工具菜单加图标
hwnds = GetSubMenu(Frmhwnds, 3)
ret = SetMenuItemBitmaps(hwnds, 0, MF_BYPOSITION, Form1.Picture1(15).Picture, 0)
RaiseEvent MainInitialize(40, "Mainprogram", "01")
'向统计工具菜单加图标
hwnds = GetSubMenu(Frmhwnds, 4)
ret = SetMenuItemBitmaps(hwnds, 0, MF_BYPOSITION, Form1.Picture1(16).Picture, 0)
ret = SetMenuItemBitmaps(hwnds, 1, MF_BYPOSITION, Form1.Picture1(17).Picture, 0)
'向绘图工具菜单加图标
hwnds = GetSubMenu(Frmhwnds, 5)
ret = SetMenuItemBitmaps(hwnds, 0, MF_BYPOSITION, Form1.Picture1(18).Picture, 0)
ret = SetMenuItemBitmaps(hwnds, 1, MF_BYPOSITION, Form1.Picture1(19).Picture, 0)
ret = SetMenuItemBitmaps(hwnds, 2, MF_BYPOSITION, Form1.Picture1(20).Picture, 0)
RaiseEvent MainInitialize(50, "Mainprogram", "01")
'向函数工具菜单加图标
hwnds = GetSubMenu(Frmhwnds, 6)
ret = SetMenuItemBitmaps(hwnds, 3, MF_BYPOSITION, Form1.Picture1(21).Picture, 0)
ret = SetMenuItemBitmaps(hwnds, 7, MF_BYPOSITION, Form1.Picture1(22).Picture, 0)
ret = SetMenuItemBitmaps(hwnds, 11, MF_BYPOSITION, Form1.Picture1(23).Picture, 0)
RaiseEvent MainInitialize(60, "Mainprogram", "01")
'向二元函数菜单加图标
hwndss = GetSubMenu(hwnds, 16)
ret = SetMenuItemBitmaps(hwndss, 4, MF_BYPOSITION, Form1.Picture1(24).Picture, 0)
'向几何工具菜单加图标
hwnds = GetSubMenu(Frmhwnds, 7)
ret = SetMenuItemBitmaps(hwnds, 0, MF_BYPOSITION, Form1.Picture1(25).Picture, 0)
ret = SetMenuItemBitmaps(hwnds, 1, MF_BYPOSITION, Form1.Picture1(26).Picture, 0)
ret = SetMenuItemBitmaps(hwnds, 2, MF_BYPOSITION, Form1.Picture1(27).Picture, 0)
'向非欧几何菜单加图标
hwndss = GetSubMenu(hwnds, 4)
ret = SetMenuItemBitmaps(hwndss, 0, MF_BYPOSITION, Form1.Picture1(28).Picture, 0)
ret = SetMenuItemBitmaps(hwndss, 1, MF_BYPOSITION, Form1.Picture1(29).Picture, 0)
RaiseEvent MainInitialize(70, "Mainprogram", "01")
'向空间几何菜单加图标
hwndss = GetSubMenu(hwnds, 6)
ret = SetMenuItemBitmaps(hwndss, 4, MF_BYPOSITION, Form1.Picture1(30).Picture, 0)
ret = SetMenuItemBitmaps(hwndss, 5, MF_BYPOSITION, Form1.Picture1(31).Picture, 0)
ret = SetMenuItemBitmaps(hwndss, 6, MF_BYPOSITION, Form1.Picture1(32).Picture, 0)
ret = SetMenuItemBitmaps(hwndss, 7, MF_BYPOSITION, Form1.Picture1(33).Picture, 0)
RaiseEvent MainInitialize(80, "Mainprogram", "01")
'向空间非欧几何菜单添加图标
hwndsss = GetSubMenu(hwndss, 8)
ret = SetMenuItemBitmaps(hwndsss, 0, MF_BYPOSITION, Form1.Picture1(34).Picture, 0)
ret = SetMenuItemBitmaps(hwndsss, 1, MF_BYPOSITION, Form1.Picture1(35).Picture, 0)
ret = SetMenuItemBitmaps(hwndsss, 2, MF_BYPOSITION, Form1.Picture1(36).Picture, 0)
ret = SetMenuItemBitmaps(hwndsss, 3, MF_BYPOSITION, Form1.Picture1(37).Picture, 0)
ret = SetMenuItemBitmaps(hwndsss, 4, MF_BYPOSITION, Form1.Picture1(38).Picture, 0)
RaiseEvent MainInitialize(90, "Mainprogram", "01")
'向矩阵行列式工具加图标
hwnds = GetSubMenu(Frmhwnds, 9)
ret = SetMenuItemBitmaps(hwnds, 0, MF_BYPOSITION, Form1.Picture1(39).Picture, 0)
ret = SetMenuItemBitmaps(hwnds, 1, MF_BYPOSITION, Form1.Picture1(40).Picture, 0)
'向帮助菜单加图标
hwnds = GetSubMenu(Frmhwnds, 13)
ret = SetMenuItemBitmaps(hwnds, 0, MF_BYPOSITION, Form1.Picture1(41).Picture, 0)
RaiseEvent MainInitialize(100, "Mainprogram", "01")
End Sub
Public Property Get Cancel() As Integer
'设置指示窗体是否能被关闭的属性
Cancel = gCancel
End Property
Public Property Let Cancel(ByVal NewCancel As Integer)
gCancel = NewCancel
End Property
Public Sub ExitSoft()
'退出软件
End Sub
Private Sub Class_Terminate()
Unload Form1
End Sub
'在标准EXE工程的启动窗口里
Private WithEvents Mainprogram As Mainly
Private WithEvents Cal As Calculator
Private Sub Cal_CalculatorInitialize(Progress As Integer)
frmSplash.Label1.Caption = INIS.GetINIFile(Objects, Num)
frmSplash.Win7ProgressBar1.Value = Progress
frmSplash.Hide
End Sub
Private Sub Cal_MergeToMainForm()
MsgBox ""
End Sub
Private Sub Command1_Click()
Unload Me
Unload frmSplash
End Sub
Private Sub Form_Load()
Set Mainprogram = New Mainly
Set Cal = New Calculator
frmSplash.Show
Cal.ShowCalculator
INIS.IniFilePath = App.Path & "Task Description.ini"
End Sub
Private Sub Form_Unload(Cancel As Integer)
Set Mainprogram = Nothing
Set Cal = Nothing
End Sub
Private Sub Mainprogram_MainInitialize(Progress As Integer, Objects As String, Num As String)
frmSplash.Label1.Caption = INIS.GetINIFile(Objects, Num)
frmSplash.Win7ProgressBar1.Value = Progress
If Progress = 100 Then
Mainprogram.ShowMainfrm
End If
End Sub