Re: Get return from form in ActiveX dll
- From: "RB Smissaert" <bartsmissaert@xxxxxxxxxxxxxxxx>
- Date: Sat, 11 Feb 2006 01:04:01 -0000
Karl,
Yes, that is much better and it works perfect.
Thanks a lot for the trouble taken.
This was the essential bit I hadn't thought of:
In the form:
Public Property Get ReturnValue() As Long
ReturnValue = m_RetVal
End Property
In the class:
ShowMessage = frm.ReturnValue
Of course a form is just a class and I indeed don't need to mess with events.
I can work it all out now and if you are interested I will post the finished dll back.
Thanks again for the assistance.
RBS
"Karl E. Peterson" <karl@xxxxxxxx> wrote in message news:umslYFqLGHA.536@xxxxxxxxxxxxxxxxxxxxxxx
RB Smissaert wrote:frmMB
Yes, that was a remnant from another project where it was needed.
Worked it all round, but now on pressing a button nothing happens:
Yeah, you never instantiate your MB variable...
In Excel:
-------------
-----------------
Normal Module:
---------------------
Sub Test()
Dim MSB As clsMsg
Set MSB = New clsMsg
MSB.LoadMsgBox
End Sub
Class Module:
------------------
Option Explicit
Private WithEvents MB As MsgBoxDLL.clsMsgBox
Public Sub LoadMsgBox()
MsgBoxLoad Application.Hwnd, "prompt", "title", "OK"
End Sub
Private Sub MB_evtButton(strCaption As String)
MsgBox strCaption
End Sub
That event can never happen, eh? I'm not at all sure where MsgBoxLoad is
coming from, either.
VB6:
---------
----------
Form:
---------
Option Explicit
Private cMB As clsMsgBox
Private Sub cmdButton1_Click()
'strReturn = cmdButton1.Caption
'cMB.strButtonReturn = cmdButton1.Caption
cMB.RaiseClickEvent cmdButton1.Caption
Unload Me
End Sub
Private Sub Form_Load()
Set cMB = New clsMsgBox
End Sub
Class module:
------------------
Option Explicit
Public Event evtButton(strCaption As String)
Private Const GWL_HWNDPARENT As Long = -8
Private mxlApp As Excel.Application
Private mlXLhWnd As Long
Private Declare Function FindWindow _
Lib "user32" _
Alias "FindWindowA" _
(ByVal lpClassName As String, _
ByVal lpWindowName As String) As Long
Private Declare Function SetWindowLong _
Lib "user32" _
Alias "SetWindowLongA" _
(ByVal hWnd As Long, _
ByVal nIndex As Long, _
ByVal dwNewLong As Long) As Long
Public Property Set ExcelApp(ByRef xlApp As Excel.Application)
Set mxlApp = xlApp
mlXLhWnd = FindWindow(vbNullString, mxlApp.Caption)
End Property
Public Sub RaiseClickEvent(strCaption As String)
RaiseEvent evtButton(strCaption)
End Sub
Public Sub MsgBoxLoad(lHwnd As Long, _
strPrompt As String, _
strTitle As String, _
Optional strButton1 As String = "OK", _
Optional strButton2 As String, _
Optional strButton3 As String, _
Optional strButton4 As String, _
Optional btDefault As Byte = 1, _
Optional lFormColour As Long, _
Optional lLabelColour As Long, _
Optional lButtonColour As Long)
Dim frmMB As frmMsgBox
Set frmMB = New frmMsgBox
Load frmMB
SetWindowLong frmMB.hWnd, GWL_HWNDPARENT, lHwnd
frmMB.Show
End Sub
Private Sub Class_Terminate()
Set mxlApp = Nothing
End Sub
Any further suggestions?
This is tough. I really don't "get" your architecture scheme, here. Seems
to still be more hoops than needed. But then, that's the course you chose,
to a degree.
Anyway, in VB6,
* Create a new ActiveX DLL project.
* Rename the default Class1 to CMsgBox.
* Add a new form to the project, and name it FMsgBox
* Add the following function to CMsgBox:
Option Explicit
Public Function ShowMessage(ByVal Prompt As String, ByVal Title As
String) As Long
Dim frm As FMsgBox
Set frm = New FMsgBox
frm.Prompt = Prompt
frm.Title = Title
frm.Show vbModal
ShowMessage = frm.ReturnValue
Unload frm
Set frm = Nothing
End Function
* Add the following code to FMsgBox:
Option Explicit
Private m_Prompt As String
Private m_Title As String
Private m_RetVal As Long
Public Property Let Prompt(ByVal SomeText As String)
m_Prompt = SomeText
End Property
Public Property Let Title(ByVal SomeText As String)
m_Title = SomeText
End Property
Public Property Get ReturnValue() As Long
ReturnValue = m_RetVal
End Property
Private Sub cmdCancel_Click()
m_RetVal = 0
Me.Hide
End Sub
Private Sub cmdOK_Click()
m_RetVal = 1
Me.Hide
End Sub
Private Sub Form_Load()
lblPrompt.Caption = m_Prompt
Me.Caption = m_Title
End Sub
Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer)
If UnloadMode = vbFormControlMenu Then
' Behave identically to Cancel button
m_RetVal = 0
Me.Hide
End If
End Sub
You'll probably want to also add properties for your custom button text,
icons, whatever. Adjust return value appropriately. In VBA, you'd just do
something like:
Dim mb As New MyDll.CMsgBox
Dim retval As Long
retval = mb.ShowMessage("Prompt", "Title")
Later... Karl
--
Working without a .NET?
http://classicvb.org/
.
- Follow-Ups:
- Re: Get return from form in ActiveX dll
- From: Karl E. Peterson
- Re: Get return from form in ActiveX dll
- References:
- Get return from form in ActiveX dll
- From: RB Smissaert
- Re: Get return from form in ActiveX dll
- From: Karl E. Peterson
- Re: Get return from form in ActiveX dll
- From: RB Smissaert
- Re: Get return from form in ActiveX dll
- From: Karl E. Peterson
- Re: Get return from form in ActiveX dll
- From: RB Smissaert
- Re: Get return from form in ActiveX dll
- From: Karl E. Peterson
- Re: Get return from form in ActiveX dll
- From: RB Smissaert
- Re: Get return from form in ActiveX dll
- From: Karl E. Peterson
- Re: Get return from form in ActiveX dll
- From: RB Smissaert
- Re: Get return from form in ActiveX dll
- From: Karl E. Peterson
- Get return from form in ActiveX dll
- Prev by Date: Re: Fore color VB buttons
- Next by Date: Re: CONST Array
- Previous by thread: Re: Get return from form in ActiveX dll
- Next by thread: Re: Get return from form in ActiveX dll
- Index(es):