Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

OPENING APPS. INSIDE A FORM? 1

Status
Not open for further replies.

nwt002

MIS
Jun 16, 2005
58
US
Hello All,

I am interested in creating a utility for my use at work and i was wondering if there is a Control, or if it is even possible, to create a VB app. that can open external applications inside the VB application. The idea is for it to work similar to how Firefox handles webpages, except that instead of tabs for each webpage, i could have a tab for each program. I would like to be able to open, close, and display the more common programs that I use every day within this one VB app just for convenience, and to have less open windows. Please let me know if you need anymore information about what I am trying to do. Any help will be appreciated. Thanks in advance.

Nick
 
....and the task bar in Windows - how would this be any different ??
 
Well, what I am wanting to do will be similar to the task bar, except that it will cut down on the number of windows that I will have open and displayed in the taskbar. I will be able to use the programs that I utilize more often and need open all the time, within one program. Sometimes the task bar gets crowded so it will be easier for me to swap between programs this way.
 
seems like a whole lot of effort for something that could be achieved by simply not opening so many applications.

I'm not trying to be funny but I simply cannot see how the effort it would take to do this would ever be justified by any perceived benefit.....

Any issues with using Alt + [TAB] to switch between task bar items ??
 
Have to totally agree with xlbo.
except that it will cut down on the number of windows that I will have open and displayed in the taskbar.
Why do you think it would do that? You are thinking of keeping these applications locked into the current window of this app? You ask about
that can open external applications inside the VB application. The idea is for it to work similar to how Firefox handles webpages, except that instead of tabs for each webpage, i could have a tab for each program.
You can make a VB app (and please remember that this is the VBA forum NOT the VB forum) that will OPEN applications easily enough. But they open into/with Windows, so each one will.....be in the taskbar.

Hmmmm, Firefox handles webpages like that because....it is a browser. Hmmmmm.

I think it would be possible to do what you ask about but:

a) a lot of work
b) more work

Gerry
 
Several months ago I found a small freeware app on the internet called "Freewheel". Among other things it allowed the user to switch between open applications by first holding the Alt key then scrolling through a list of apps with the mouse wheel.

When the Alt key was held down a small toolbar would appear mid screen with the icons of all open applications. As you spun the mouse whell each app would highlight in turn. All you had to do was simply stop on the one you wanted.

I have never opened more than 7 applications at one time therefore I don't know if this "Freewheel" program would have similar problems you are finding with the task bar. I have since removed "Freewheel" from my system due to compatibility problems with other software.

You may be able to contact the author and discuss methodologies with him.

Good luck.
 
bpeirson,
Thank you very much for your advice. I will look into the app. that you suggested and see if it is what i am looking for. I appreciate your help!
 
Although I've never used it, it may be worth your while to check out the Virtual Desktop Manager PowerToy from Microsoft. Also, just in case you're not aware of it, if you are using XP, you can change the Taskbar properties to Group similar taskbar buttons to reduce the number of buttons shown.
 
Nick,

If you really want to have a go at this, maybe this could get you started

Code:
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: [URL unfurl="true"]http://www.allapi.net/[/URL]
    '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
 

JustinEzequiel,

Wow! That definitly gets me on the right track. I'll have to modify it some to get it to work exactly how I want it to, but this is definitly going to work with what I am doing. A star for you. Thanks a lot for the help. Also, DaveInIowa, thank you for your suggestion.
 
JustinEzequiel,

I have been messing around with the code you posted and trying to modify it to work with the programs that I will be using and i've come across two question.

#1 - One app that I have set the program to run, opens up in the main form sometimes, but sometimes it opens up outside the main form. Do you know what might be the reason for this?

#2 - Am I limited to what applications I can use this code with? One program I am trying to run, opens up outside of the main window everytime. I am using this shell command:
Code:
Pid = Shell("RUNDLL32.EXE URL.DLL,FileProtocolHandler C:\Program Files\TUN\emul\Prism.cwz", vbNormalFocus)

because the app. won't open when i use:
Code:
Pid = Shell("C:\Program Files\TUN\emul\Prism.cwz", vbNormalFocus)
I didn't know if there was an issue with using the first shell command with this code. Thanks again!
Nick
 
Why not simply using the Esker Viewer ?

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
JustinEzequiel,

I finally figured out how to get the app. that kept opening outside the main form(the app. that i reference in question #2 from above), to open inside the main form. I am still having the issue where some apps. are opening outside of the main form some of the time. I would appreciate any ideas that you or anyone may have as to why this may be occuring. Thanks!
 
I am still having the issue where some apps. are opening outside of the main form some of the time.

Nick,

I do not have time to look into this as I am very busy.
You may however want to set delays in between calls to
Shell, SetParent, and PutFocus.

Code:
Private Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)
 
JustinEzequiel,

I tried adding the delay to the code and that appeared to fix all the issues I was having. I also skimmed over the thread you post, and it looks like it could also be very helpful with what I am trying to do. Thanks for all the help!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top