| Forum Home | ||||
| Press F1 | ||||
| Thread ID: 38856 | 2003-10-20 12:51:00 | Visual Basic (v6) running other Apps. | Brain_Cell_Anon (261) | Press F1 |
| Post ID | Timestamp | Content | User | ||
| 185161 | 2003-10-20 12:51:00 | Whatcha all! :D I'm just trying to find out if there is any code in VB v6 that will allow me to run multiple applications, one after another, ie the 'new' vb program will run app. no. one, then when app. one has 'self finished' it starts app. two, and when that 'self finishes' it starts app three etc. etc.... you get the idea, a? ;\ OR I suppose another thing I could be asking is....... is there a program that does that already?? :O I await any answers with interest. :D Regards, the Cell |
Brain_Cell_Anon (261) | ||
| 185162 | 2003-10-20 18:46:00 | I have a Delphi component which does that... but not in VB. | Dolby Digital (160) | ||
| 185163 | 2003-10-20 20:54:00 | Im sure it can be done but knowing when an application is finished is the hard part. Sounds like something that could be done with a batch file. What apps are you starting? | parry (27) | ||
| 185164 | 2003-10-21 01:55:00 | OK this is a difficult problem to solve . . . now i know it can be done easily in C++ (more access of windows), now i have no idea with VB . You'll need to make an API call to find the instance of the window . Now we need to think about this . . . btw my VB knowledge is limited so we'll be learning this at the same time . . . First create a new project with a standard form To run a program use the shell command i . e dim foo foo = shell("C:\Windows\Notepad . exe",1) where the 1 means normal window Now onto the API call from windows, this is for window states, instances lada lada la, if you don't know VB too well then don't worry TOO much about understanding this, i kind of do, but hey its only declarations First, set up a new module ('Project', 'add module') Now shove in the following code into it Option Explicit 'API's Function Declarations Private Declare Function IsWindow Lib "user32" (ByVal hwnd As Long) As Long Private Declare Function GetWindowLong Lib "user32" Alias "GetWindowLongA" ( _ ByVal hwnd As Long, _ ByVal nIndex As Long) As Long Private Declare Function PostMessage Lib "user32" Alias "PostMessageA" ( _ ByVal hwnd As Long, _ ByVal wMsg As Long, _ ByVal wParam As Long, _ ByVal lParam As Long) As Long Public Declare Function FindWindow Lib "user32" Alias "FindWindowA" ( _ ByVal lpClassName As Any, _ ByVal lpWindowName As String) As Long 'API Constants Public Const GWL_STYLE = -16 Public Const WS_DISABLED = &H8000000 Public Const WM_CANCELMODE = &H1F Public Const WM_CLOSE = &H10 Now this is the API call, it looks very nice, now ignore it and lets figure out how to use this . In order to use the data in this module you will need to set up a function, now i figure you understand functions (think calculus), anyways this is the sort of code you'll need Public Function CheckStatus(name As String) Dim Status As Long Status = FindWindow(0&, name) If Status = 0 Then MsgBox "Notepad not running" Else MsgBox "Notepad running" End If End Function where you pass the name to the function as a string, more on where this variable comes from later, but now we'll learn how to use it . . . Using the status variable we use the FindWindow function (see: API declaration) to find weather a program with a certain title is running, this runs by FindWindow(&0, name) where &0 is the class name, dont worry bout this, just leave as zero, and name is passed from the actual form (again more on this later), just know that it searches for the title and then follows through with an 'if statement' Now we've past the difficult stuff we get onto the front end of the program . . . the dialog etc . . . in the form, create two buttons 'Run' and 'Status', stick this as the code for the run button Private Sub Run_Click() Dim foo foo = Shell("C:\windows\notepad . exe", 1) End Sub This just runs notepad using shell command mentioned at the top . . . now onto the status button Private Sub Status_Click() Dim Status As Long Dim progname As String progname = "Untitled - Notepad" Status = CheckStatus(progname) End Sub Now you'll need some understanding of functions, it passes the progname "Untitled = Notepad" to the CheckStatus Function . You get this from the title of the program so currently for Pressf1 it would be "PressF1 - New Zealand's PC World self-help forum - Microsoft Internet Explorer' You could simplify that of course by using string manipulation, working backwards from the end of the string so you just pick up the 'Microsoft Internet Explorer' part . this is where the name thing comes into use in the actual function, if you don't understand functions look on the net, they are an important part of VB programming and understanding them is essential, along with sub-routines . . . **************************************** Well now that you can run a program, and find the status for the program . So i think you can figure it out from there, when the app is not running just set it to run the next one Happy coding, coke helps ;) - David |
DangerousDave (697) | ||
| 185165 | 2003-10-21 01:57:00 | whoa looking at that, its a lot of text ;) If you need anymore help just ask and i'll help if i can - David |
DangerousDave (697) | ||
| 185166 | 2003-10-22 07:08:00 | Dolby_Digital. I would be very interested in 'seeing' that. :-) I'm not sure if I would need something installed though!!?!?! I'm not 'up' with Delphi AT ALL!! ?:| Any old road up, when you're ready I'll be awaiting! :D Regards the Cell PS I did say I'd try almost any thing! :8} |
Brain_Cell_Anon (261) | ||
| 185167 | 2003-10-22 11:27:00 | parry! I thank you 4 your post. Looking at DangerousDaves post I'm taking a lie down now!!! :_| But I will have a 'play' with Mr DDs code and see if I can't cog it up a bit in the true tradition of some one who wants spare parts after taking something apart!!! :D With limited knowledge of other programing languages ( I can get by in VB, Java, JavaScript, HTML and most other European languages :p ) I do think you may be right and perhaps a batch file is the way, unless this Delphi component from Dolby_Digital is a 'goer'!!? Regards once again, the Cell |
Brain_Cell_Anon (261) | ||
| 185168 | 2003-10-22 11:47:00 | Mr DD. I'm fairly interested in this C++ as I believe it's 'sort of' a kin to Java. Based on object orientated coding, or some such!!? :| When you say "....it can be done easily in C++...." does that mean if I was to check out some tutorials on C++ I may be able to do something to what I'm after? :-) I forgot when answering parry to say that the apps. in question are compression demos I found on the net. From my limited research (so far) every year in Europe (Denmark I think) there is a huge techno get together called "The Party". One part of it is where computer 'brains' get it on and compress something like 10 to 15 mins. of techno music with full on 3D animation in to a 64KB file. Something like 30,000 to one compression technique!!!!!!! No idea how they do it. Now I have half a dozen of them and would like to run them consecutively as it's good music and good viewing. B-) So maybe this alters the whole thread now? Hope you guys are still 'watching' this thread and can still help (or want to for that matter :8} )!!!??? I'll be ya best friend!!! :x Any old chimney sweep, regards, the Cell |
Brain_Cell_Anon (261) | ||
| 185169 | 2003-10-22 19:03:00 | Hiya, yeah C++ is pretty difficult, i spent at least a year (spare time after school) learning just the basics of the language e . g . pointers, references, arrays, OOP, blah blah blah . Windows is a big step because it requires a working knowledge of OOP etc etc, put it this way, to display one form like in VB requires a couple of hundred lines of code because you manually have to enter instance of the program, priority, and all this other random stuff . I prefer C++ over VB as you have more control over the computer . . . VB limits you to windows, while C++ gives you access most stuff though . I said it could be done easily in C++ because i know how to find all instances of a window etc, basically i knew how to code it . I don't use VB much, only for computers at school, but now that i've figured out about API calls it could be possible in VB with a bit of work on your part . Java is very similar to C++, in that it bases itself heavily on OOP, but i still don't really like the style of it . Oh well i might learn it for the sake that i have a Java mobile phone and i might be able to make some little games for it . . . If your still interested in learning C++ goto google and look for 'teach yourself C++ in 21 days e-book', its now free to download because it is about 10 years old but i found it very good to learn from, provided you have some knowledge of programming . - David p . s . do you have linkies to those 64kb music files???! |
DangerousDave (697) | ||
| 1 | |||||