UI forms in ActiveX component


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 7 of 7

Thread: UI forms in ActiveX component

Hybrid View

  1. #1
    Kishore Guest

    UI forms in ActiveX component


    Hi, I have an MDI application which currently has several modules, all in
    a standard EXE application. The application exe (compiled as p-code) has
    grown big (around 5 MB) and the application has become slower. I am preparing
    to add another module which I anticipate will make the executable even bigger
    (and probably slower).

    I have considered another alternative as adding the new module as an ActiveX
    DLL which will comprise of all its classes and the UI forms. I plan to reference
    the DLL from the main application and instantiate the classes and invoke
    the forms. My testing has been successful so far, except for one problem.
    When I add the forms in the DLL as MDIChild forms, it gives an error saying
    that no MDI parent form was found. My MDI parent form is a part of the main
    application, but it does not consider the MDI child forms in the DLL as its
    own child forms. When I make the MDI child property in the DLL forms as False,
    it works fine, except that then I cannot use the forms of the new module
    in an MDI environment. Any suggestions...

    The basic key issues here are :
    1. Does the size of an application (standard exe) matter for its performance
    and its responsiveness or does VB dynamically load what is needed ?
    2. Is it a good idea to include UI forms in an ActiveX DLL componenet ?
    3. If I include the UI forms in ActiveX DLL, how do I make them behave as
    the MDI child forms of the MDI parent form in the main client application
    ?

    Thanks a lot in advance for the pointers.



  2. #2
    Shailesh Shah Guest

    Re: UI forms in ActiveX component

    A Guess.
    How about using SetParent Api???

    Might this help you....
    (Courtsey Allapi.net)
    Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal
    lpClassName As Long, ByVal lpWindowName As Long) As Long

    Private Declare Function GetParent Lib "user32" (ByVal hwnd As Long) As Long

    Private Declare Function SetParent Lib "user32" (ByVal hWndChild As Long,
    ByVal hWndNewParent As Long) As Long

    Private Declare Function GetWindowThreadProcessId Lib "user32" (ByVal hwnd
    As Long, lpdwProcessId As Long) As Long

    Private Declare Function GetWindow Lib "user32" (ByVal hwnd As Long, ByVal
    wCmd As Long) As Long

    Private Declare Function LockWindowUpdate Lib "user32" (ByVal hwndLock As
    Long) As Long

    Private Declare Function GetDesktopWindow Lib "user32" () As Long

    Private Declare Function DestroyWindow Lib "user32" (ByVal hwnd As Long) As
    Long

    Private Declare Function TerminateProcess Lib "kernel32" (ByVal hProcess As
    Long, ByVal uExitCode As Long) As Long

    Private Declare Function GetCurrentProcess Lib "kernel32" () As Long

    Private Declare Function Putfocus Lib "user32" Alias "SetFocus" (ByVal hwnd
    As Long) As Long

    Const GW_HWNDNEXT = 2

    Dim mWnd As Long

    Function InstanceToWnd(ByVal target_pid As Long) As Long

    Dim test_hwnd As Long, test_pid As Long, test_thread_id As Long

    'Find the first window

    test_hwnd = FindWindow(ByVal 0&, ByVal 0&)

    Do While test_hwnd <> 0

    'Check if the window isn't a child

    If GetParent(test_hwnd) = 0 Then

    'Get the window's thread

    test_thread_id = GetWindowThreadProcessId(test_hwnd, test_pid)

    If test_pid = target_pid Then

    InstanceToWnd = test_hwnd

    Exit Do

    End If

    End If

    'retrieve the next window

    test_hwnd = GetWindow(test_hwnd, GW_HWNDNEXT)

    Loop

    End Function

    Private Sub Form_Load()

    'KPD-Team 1999

    'URL: http://www.allapi.net/

    'E-Mail: KPDTeam@Allapi.net

    Dim Pid As Long

    'Lock the window update

    LockWindowUpdate GetDesktopWindow

    'Execute notepad.Exe

    Pid = Shell("c:\windows\notepad.exe", vbNormalFocus)

    If Pid = 0 Then MsgBox "Error starting the app"

    'retrieve the handle of the window

    mWnd = InstanceToWnd(Pid)

    'Set the notepad's parent

    SetParent mWnd, Me.hwnd

    'Put the focus on notepad

    Putfocus mWnd

    'Unlock windowupdate

    LockWindowUpdate False

    End Sub

    Private Sub Form_Unload(Cancel As Integer)

    'Unload notepad

    DestroyWindow mWnd

    'End this program

    TerminateProcess GetCurrentProcess, 0

    End Sub



    "Kishore" <kispatel@nettaxi.com> wrote in message
    news:3c0ee8f9$1@147.208.176.211...
    >
    > Hi, I have an MDI application which currently has several modules, all in
    > a standard EXE application. The application exe (compiled as p-code) has
    > grown big (around 5 MB) and the application has become slower. I am

    preparing
    > to add another module which I anticipate will make the executable even

    bigger
    > (and probably slower).
    >
    > I have considered another alternative as adding the new module as an

    ActiveX
    > DLL which will comprise of all its classes and the UI forms. I plan to

    reference
    > the DLL from the main application and instantiate the classes and invoke
    > the forms. My testing has been successful so far, except for one problem.
    > When I add the forms in the DLL as MDIChild forms, it gives an error

    saying
    > that no MDI parent form was found. My MDI parent form is a part of the

    main
    > application, but it does not consider the MDI child forms in the DLL as

    its
    > own child forms. When I make the MDI child property in the DLL forms as

    False,
    > it works fine, except that then I cannot use the forms of the new module
    > in an MDI environment. Any suggestions...
    >
    > The basic key issues here are :
    > 1. Does the size of an application (standard exe) matter for its

    performance
    > and its responsiveness or does VB dynamically load what is needed ?
    > 2. Is it a good idea to include UI forms in an ActiveX DLL componenet ?
    > 3. If I include the UI forms in ActiveX DLL, how do I make them behave as
    > the MDI child forms of the MDI parent form in the main client application
    > ?
    >
    > Thanks a lot in advance for the pointers.
    >
    >




  3. #3
    Matthew Solnit Guest

    Re: UI forms in ActiveX component

    "Kishore" <kispatel@nettaxi.com> wrote in message
    news:3c0ee8f9$1@147.208.176.211...
    >
    > Hi, I have an MDI application which currently has several modules, all in
    > a standard EXE application. The application exe (compiled as p-code) has
    > grown big (around 5 MB) and the application has become slower. I am

    preparing
    > to add another module which I anticipate will make the executable even

    bigger
    > (and probably slower).


    Dan Appleman wrote a great article for VBPJ about storing MDI child forms in
    ActiveX components. Unfortunately, I don't know the date of the issue. But
    if you have DevX Premiere Membership, you can find it easily enough. Even
    if you don't, I think they are offering a free 1-month trial subscription.
    Go to http://www.devx.com and take a look around.

    -- Matthew Solnit



  4. #4
    Thomas Eyde Guest

    Re: UI forms in ActiveX component

    An easier approach which is also supported by VB6:
    1. Convert all childforms to user controls
    2. Create one empty childform in the exe(that is without any controls)
    3. Load a new form and dynamicly add the user control which represent
    this form.

    /Thomas

    "Kishore" <kispatel@nettaxi.com> wrote in message
    news:3c0ee8f9$1@147.208.176.211...
    > 3. If I include the UI forms in ActiveX DLL, how do I make them behave as
    > the MDI child forms of the MDI parent form in the main client application





  5. #5
    Kishore Guest

    Re: UI forms in ActiveX component


    When I use the SetParent API, the window does appear to become the MDIChild
    window of the Parent MDI Window but shows some exceptional behaviour. It
    kind of appears as "Always on Top" and covers other "legitimate" MDI child
    windows. Also, the activeform property does not return its name when this
    "step" MDI child window is active. This is probably because we have bypassed
    VB and tried to make it an MDI child through Windows without informing VB.
    Any idea how this can be handled.

    Thanks a lot for your earlier reply.


    "Shailesh Shah" <shailesh@thegt.com> wrote:
    >A Guess.
    >How about using SetParent Api???
    >
    >Might this help you....
    >(Courtsey Allapi.net)
    >Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal
    >lpClassName As Long, ByVal lpWindowName As Long) As Long
    >
    >Private Declare Function GetParent Lib "user32" (ByVal hwnd As Long) As

    Long
    >
    >Private Declare Function SetParent Lib "user32" (ByVal hWndChild As Long,
    >ByVal hWndNewParent As Long) As Long
    >
    >Private Declare Function GetWindowThreadProcessId Lib "user32" (ByVal hwnd
    >As Long, lpdwProcessId As Long) As Long
    >
    >Private Declare Function GetWindow Lib "user32" (ByVal hwnd As Long, ByVal
    >wCmd As Long) As Long
    >
    >Private Declare Function LockWindowUpdate Lib "user32" (ByVal hwndLock As
    >Long) As Long
    >
    >Private Declare Function GetDesktopWindow Lib "user32" () As Long
    >
    >Private Declare Function DestroyWindow Lib "user32" (ByVal hwnd As Long)

    As
    >Long
    >
    >Private Declare Function TerminateProcess Lib "kernel32" (ByVal hProcess

    As
    >Long, ByVal uExitCode As Long) As Long
    >
    >Private Declare Function GetCurrentProcess Lib "kernel32" () As Long
    >
    >Private Declare Function Putfocus Lib "user32" Alias "SetFocus" (ByVal hwnd
    >As Long) As Long
    >
    >Const GW_HWNDNEXT = 2
    >
    >Dim mWnd As Long
    >
    >Function InstanceToWnd(ByVal target_pid As Long) As Long
    >
    >Dim test_hwnd As Long, test_pid As Long, test_thread_id As Long
    >
    >'Find the first window
    >
    >test_hwnd = FindWindow(ByVal 0&, ByVal 0&)
    >
    >Do While test_hwnd <> 0
    >
    >'Check if the window isn't a child
    >
    >If GetParent(test_hwnd) = 0 Then
    >
    >'Get the window's thread
    >
    >test_thread_id = GetWindowThreadProcessId(test_hwnd, test_pid)
    >
    >If test_pid = target_pid Then
    >
    >InstanceToWnd = test_hwnd
    >
    >Exit Do
    >
    >End If
    >
    >End If
    >
    >'retrieve the next window
    >
    >test_hwnd = GetWindow(test_hwnd, GW_HWNDNEXT)
    >
    >Loop
    >
    >End Function
    >
    >Private Sub Form_Load()
    >
    >'KPD-Team 1999
    >
    >'URL: http://www.allapi.net/
    >
    >'E-Mail: KPDTeam@Allapi.net
    >
    >Dim Pid As Long
    >
    >'Lock the window update
    >
    >LockWindowUpdate GetDesktopWindow
    >
    >'Execute notepad.Exe
    >
    >Pid = Shell("c:\windows\notepad.exe", vbNormalFocus)
    >
    >If Pid = 0 Then MsgBox "Error starting the app"
    >
    >'retrieve the handle of the window
    >
    >mWnd = InstanceToWnd(Pid)
    >
    >'Set the notepad's parent
    >
    >SetParent mWnd, Me.hwnd
    >
    >'Put the focus on notepad
    >
    >Putfocus mWnd
    >
    >'Unlock windowupdate
    >
    >LockWindowUpdate False
    >
    >End Sub
    >
    >Private Sub Form_Unload(Cancel As Integer)
    >
    >'Unload notepad
    >
    >DestroyWindow mWnd
    >
    >'End this program
    >
    >TerminateProcess GetCurrentProcess, 0
    >
    >End Sub
    >
    >
    >
    >"Kishore" <kispatel@nettaxi.com> wrote in message
    >news:3c0ee8f9$1@147.208.176.211...
    >>
    >> Hi, I have an MDI application which currently has several modules, all

    in
    >> a standard EXE application. The application exe (compiled as p-code) has
    >> grown big (around 5 MB) and the application has become slower. I am

    >preparing
    >> to add another module which I anticipate will make the executable even

    >bigger
    >> (and probably slower).
    >>
    >> I have considered another alternative as adding the new module as an

    >ActiveX
    >> DLL which will comprise of all its classes and the UI forms. I plan to

    >reference
    >> the DLL from the main application and instantiate the classes and invoke
    >> the forms. My testing has been successful so far, except for one problem.
    >> When I add the forms in the DLL as MDIChild forms, it gives an error

    >saying
    >> that no MDI parent form was found. My MDI parent form is a part of the

    >main
    >> application, but it does not consider the MDI child forms in the DLL as

    >its
    >> own child forms. When I make the MDI child property in the DLL forms as

    >False,
    >> it works fine, except that then I cannot use the forms of the new module
    >> in an MDI environment. Any suggestions...
    >>
    >> The basic key issues here are :
    >> 1. Does the size of an application (standard exe) matter for its

    >performance
    >> and its responsiveness or does VB dynamically load what is needed ?
    >> 2. Is it a good idea to include UI forms in an ActiveX DLL componenet

    ?
    >> 3. If I include the UI forms in ActiveX DLL, how do I make them behave

    as
    >> the MDI child forms of the MDI parent form in the main client application
    >> ?
    >>
    >> Thanks a lot in advance for the pointers.
    >>
    >>

    >
    >



  6. #6
    Kishore Guest

    Re: UI forms in ActiveX component


    Thanks Thomas for your help.

    Actually, my concerned forms has OLE component which VB does not allow to
    be put on a UserControl/UserDocument. I wonder if there is any other alternate
    option in these circumstances.

    "Thomas Eyde" <thomas.eyde@online.no> wrote:
    >An easier approach which is also supported by VB6:
    > 1. Convert all childforms to user controls
    > 2. Create one empty childform in the exe(that is without any controls)
    > 3. Load a new form and dynamicly add the user control which represent
    >this form.
    >
    >/Thomas
    >
    >"Kishore" <kispatel@nettaxi.com> wrote in message
    >news:3c0ee8f9$1@147.208.176.211...
    >> 3. If I include the UI forms in ActiveX DLL, how do I make them behave

    as
    >> the MDI child forms of the MDI parent form in the main client application

    >
    >
    >



  7. #7
    Join Date
    Dec 2013
    Posts
    24
    Very impressive discussion, and I also wonder is there any good guide for using UI form control?

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center