Valhalla Legends Forums Archive | Visual Basic Programming | How to load an application in a window in vb6

AuthorMessageTime
CrAz3D
I am trying to load multiple instances of my bot into a single window, creating somewhat of a bot that has profile loading capabilites, but through a plugin.

My main bot has all of the connections, I would just like to be able to create an ActiveX DLL that will hold the multiple bots all together nicely.

Any ideas of how to go about this would be apreciated, thanks very much.
January 3, 2005, 11:44 PM
Myndfyr
I don't know offhand (because I don't have the VB6 environment in front of me) what is available in VB6, but you could create an ActiveX control that manages all of the necessary information for a connection.  I did something similar -- the chat window/user lists/send box was all put together in a custom control, and each control was bound to a tab page.
January 3, 2005, 11:49 PM
CrAz3D
I thought about doing something like tabbed pages, but then I would have to edit my main bot, I'm trying to stay away from that as much as possible.  Maybe I could create bot as an ActiveX EXE?...anyone know if that might work?

EDIT:
I've never used SphtBot extensively, but I just looked @ ProfileLauncher & it seems that that is what I'll end up doing.  Quite a dandy idea Spht has there.  Hope he doesn't mind me borrowing his awesomeness.
January 4, 2005, 12:22 AM
Myndfyr
[quote author=CrAz3D link=topic=10113.msg94252#msg94252 date=1104798124]
I thought about doing something like tabbed pages, but then I would have to edit my main bot, I'm trying to stay away from that as much as possible.  Maybe I could create bot as an ActiveX EXE?...anyone know if that might work?
[/quote]

I don't believe that an EXE would be the way to go.  COM is intended to provide multilanguage interoperability through libraries -- while an EXE is also a library, you're somewhat defeating the purpose.  I don't know if VB6 allows you to export COM objects through an EXE, so maybe it won't make a difference.
January 4, 2005, 2:17 AM
UserLoser.
Could use a MDI dialog with MDI child dialogs for each profile, that's how I do it.
January 4, 2005, 4:14 AM
CrAz3D
That's what I'd like to do, but the what I want to be the child is in a totally different project & is already compiled functioning without the MDI form.  The MDI form would be the plugin.
January 4, 2005, 4:19 AM
Stealth
You could do it by using SetParent on a bunch of newly-executed instances of the part you have compiled and working, perhaps passing the children command line arguments telling them what profile file or folder they should be reading out of?

Or I misinterpreted what you said.
January 4, 2005, 4:47 AM
CrAz3D
Well, that sounds like what I'm looking for...just not so sure about setting a regular form as the parent of my compiled form/program.

Currently what I have is my main bot compiled & running, then I load the plugin which has a basic class module & a Form.  The form loads on startup & I try to set the child/parent relationship bye this:
[code]SetParent PlugY(NameToIndex("Form1")).hWnd, Form1.hWnd[/code]
PlugY(NameToIndex("Form1")) is the bot's Form1 hosted in the plugin (I think).

When I run the code, I recieve:

RunTime 438
Object Doesn't Support this method or property.


My problem is retrieving the hWnd from the bot's Form1, I'm quite sure that is where my problem is at.



Thanks all for the help!
January 4, 2005, 5:08 AM
CrAz3D
Ok, figured out for the most part...just a little more playing around to do & it should work.

With a combination of FindWindow, MoveWindow, & SetParent I have been able to put my bot into the plugin form, however I'm about to try to use find window without the entire/correct window name PRAYING that I can stil find the window.

[code]Dim Form1hWnd As Long, OldhWnd As Long
Dim BotPath As String
BotPath = Left(App.Path, Len(App.Path) - 8)

Shell BotPath & "Xenogenic.exe"

Form1hWnd = FindWindow(vbNullString, "Xenogenic")
OldhWnd = SetParent(Form1hWnd, Form1.hwnd)
MoveWindow Form1hWnd, 0, -20, 400, 300, 1[/code]

Thanks SO much



EDIT: A new problem has arisen from my awesome w/eness.
The bot opens, but then I guess it takes too long to open the SetParent() code tries to find the new bot before it actually opens.  So I end up with the bot openning into the taskbar again...I'd like it to go straight to the Parent form.  Any ideas on what I can do to slow down the Parent form?  (It works when I try the SetParent after the bot is already sitting in the taskbar)
January 4, 2005, 5:25 AM
CrAz3D
*bump*

*points to new problem in above post that I editted instead of posted*

;)  ::)
January 4, 2005, 10:38 PM
Stealth
Is your main form an MDI form? In the test app I wrote a long time ago (I was experimenting with interprocess communication) the main form was just an empty MDI form and all the children were separate individual forms.
January 5, 2005, 5:20 AM
CrAz3D
My main form is a regular single form.  I can get the bot to go in to the new parent when I run the find/setparent code after I physically see that the bot has loaded, but if I run it right after i "shell" the bot it won't find the bot's window.
January 5, 2005, 4:35 PM
Stealth
I dug up the experimental interprocess communication code I had written. Interesting stuff.

First off, it uses a function apparently from vb-helper.com to shell and retrieve the hWnd of children:

[code]' Return the window handle for an instance handle.
Public Function InstanceToWnd(ByVal target_pid As Long) As Long
    Dim test_hwnd As Long
    Dim test_pid As Long
    Dim test_thread_id As Long

    ' Get the first window handle.
    test_hwnd = FindWindow(ByVal 0&, ByVal 0&)

    ' Loop until we find the target or we run out
    ' of windows.
    Do While test_hwnd <> 0
        ' See if this window has a parent. If not,
        ' it is a top-level window.
        If GetParent(test_hwnd) = 0 Then
            ' This is a top-level window. See if
            ' it has the target instance handle.
            test_thread_id = GetWindowThreadProcessId(test_hwnd, test_pid)

            If test_pid = target_pid Then
                ' This is the target.
                InstanceToWnd = test_hwnd
                Exit Do
            End If
        End If

        ' Examine the next window.
        test_hwnd = GetWindow(test_hwnd, GW_HWNDNEXT)
    Loop
End Function[/code]

I then store, in an array of user-defined types, the old parent and hwnd of each form that's loaded. (I return the child forms to their old parent before telling them to close via IPC.) For testing purposes, the array was fixed-size, but it could easily be made scalable or converted to a collection of class objects.

[code]Public Sub NewInstance(Optional ByVal Path As String)
    Dim pid As Long

    pid = Shell(IIf(LenB(Path) > 0, Path, "C:\Visual Studio\E2\MEx.exe"), vbNormalFocus)
   
    If pid = 0 Then
        Debug.Print "Error starting instance at " & Path & "."
        Exit Sub
    End If

    Children(0).hWnd = InstanceToWnd(pid)
    Children(0).oldParent = SetParent(Children(0).hWnd, frmMain.hWnd)
End Sub[/code]

Seems to hook in the new window without any problem. HTH
January 5, 2005, 11:13 PM
CrAz3D
Thanks very much Stealth, I'll look through that & see what I can't do about it.
January 6, 2005, 12:10 AM
NetNX
Well i think i understand what you are trying todo... If you are trying to have multiple bots you might want to create a control that could be used the way CSB is but just include it with your program and dont compile it too DLL so people dont just steal ur dll and use it as their own... and then have it set to do something like

[code]
on error goto err:
Public function LoadNewBot(CNFG as string) as boolean
Dim FrmNewBot as New FrmBot '// frmbot is a blank bot from or mdi from
FrmNewBot.load CNFG '// load selected part of the config to load...
FrmNewBot.show
FrmNewBot.addchat vbwhite, CNFG, vbyellow, " configuration loaded on new window"
LoadNewBot = true
err:
End Fuction
[/code]
January 6, 2005, 3:53 PM
Stealth
[quote author=NetNX link=topic=10113.msg94446#msg94446 date=1105026782]
Well i think i understand what you are trying todo... If you are trying to have multiple bots you might want to create a control that could be used the way CSB is but just include it with your program and dont compile it too DLL so people dont just steal ur dll and use it as their own... and then have it set to do something like

[code]
on error goto err:
Public function LoadNewBot(CNFG as string) as boolean
Dim FrmNewBot as New FrmBot '// frmbot is a blank bot from or mdi from
FrmNewBot.load CNFG '// load selected part of the config to load...
FrmNewBot.show
FrmNewBot.addchat vbwhite, CNFG, vbyellow, " configuration loaded on new window"
LoadNewBot = true
err:
End Fuction
[/code]
[/quote]

I don't think that that's relevant at all to what he's trying to do. He wants to load a separately-compiled project into an existing one and make it look as though it was part of the existing one to begin with. Your code will just load a new instance at runtime of a form within one project.

Remember. When your tab key huts itself, it's a "Desperate Cry for Help". Comfort it by using it in your code. ;)
January 6, 2005, 10:02 PM
TheMinistered
You could use an activex dll as a 'plugin' of sorts to accomplish this, I think.  What you would do, is load the plugin and pass it a reference to the winsock object.
January 7, 2005, 10:28 PM
CrAz3D
Ok people, just stop posting if you're not going to read the rest of the posts. 

[quote]I don't think that that's relevant at all to what he's trying to do. He wants to load a separately-compiled project into an existing one and make it look as though it was part of the existing one to begin with. [/quote]

I'm just trying to load another instance of my bot into this new window over & over.
January 7, 2005, 11:38 PM
NetNX
Instant message me on aim later id love to help :-)

as for my tab key i didnt copy and paste that out of anything i just made it up for the situation
January 14, 2005, 4:02 PM

Search