Results 1 to 26 of 26

Thread: [RESOLVED] Run another program inside a form

  1. #1

    Thread Starter
    Fanatic Member paulorton's Avatar
    Join Date
    Aug 2006
    Location
    West Wales
    Posts
    809

    Resolved [RESOLVED] Run another program inside a form

    I'm trying to launch Acrobat Reader inside a child form of my application (specifically inside a frame on that form). The external program fires up OK but it's not inside my child form (which sits empty behind Acrobat Reader and has to be closed separately after I close Reader).

    If I understood better the code I'm using (it was just cut and pasted from somewhere I forget!) I could sort this myself but I don't unfortunately. Anyone any ideas?

    Here is the code I'm using:

    VB Code:
    1. Option Explicit
    2.  
    3. Private Declare Function SetParent Lib "user32" (ByVal hWndChild As Long, _
    4. ByVal hWndNewParent As Long) As Long
    5.  
    6. Private Declare Function GetClientRect Lib "user32" (ByVal hwnd As Long, _
    7. lpRect As RECT) As Long
    8.  
    9. Private Declare Function MoveWindow Lib "user32" (ByVal hwnd As Long, _
    10. ByVal X As Long, ByVal Y As Long, ByVal nWidth As Long, ByVal nHeight As Long, _
    11. ByVal bRepaint As Long) As Long
    12.  
    13. Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, _
    14. ByVal lpWindowName As String) As Long
    15.  
    16. Private Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" (ByVal hwnd As Long, _
    17. ByVal lpOperation As String, ByVal lpFile As String, ByVal lpParameters As String, _
    18. ByVal lpDirectory As String, ByVal nShowCmd As Long) As Long
    19.  
    20. Private Declare Function DestroyWindow Lib "user32" (ByVal hwnd As Long) As Long
    21.  
    22. Private Type RECT
    23. Left As Long
    24. Top As Long
    25. Right As Long
    26. Bottom As Long
    27. End Type
    28.  
    29. Private lngGetApp As Long
    30.  
    31. Private Sub Form_Unload(Cancel As Integer)
    32.   DestroyWindow lngGetApp
    33. End Sub
    34.  
    35. Private Sub Form_Load()
    36.  
    37.   Dim RectCoord As RECT
    38.   Dim lr As Long
    39.  
    40.   lr = ShellExecute(Frame1.hwnd, "Open", FileToLoad, "", "", vbNormalFocus)
    41.   If (lr < 0) Or (lr > 32) Then
    42.   ' success '
    43.   Else
    44.     MsgBox "Failed to start '" & FileToLoad & "'", vbInformation
    45.   End If
    46.  
    47.   lngGetApp = FindWindow(vbNullString, "Beat Dyslexia/EV guide")
    48.   SetParent lngGetApp, Frame1.hwnd
    49.  
    50.   GetClientRect Frame1.hwnd, RectCoord
    51.   MoveWindow lngGetApp, 0, 0, RectCoord.Right - RectCoord.Left, RectCoord.Bottom - RectCoord.Top, True
    52.  
    53. End Sub
    Paul Orton
    VB6
    Visual Web Developer 2008 Express Edition
    Microsoft Visual Basic 2012 Express

  2. #2
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: Run another program inside a form

    you can use the Acrobat Reader control (pdf.ocx) which you can drop on a VB Form and link up the source file and viola, a pdf file opened on your form. Different versions of Acrobat Reader come with different ocx controls so for 7/8 version of reader its adifferent control name.
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  3. #3

    Thread Starter
    Fanatic Member paulorton's Avatar
    Join Date
    Aug 2006
    Location
    West Wales
    Posts
    809

    Re: Run another program inside a form

    Wow, that sounds promising - I'll go and look for that now and report back if I get a result!

    Thank you!
    Paul Orton
    VB6
    Visual Web Developer 2008 Express Edition
    Microsoft Visual Basic 2012 Express

  4. #4

    Thread Starter
    Fanatic Member paulorton's Avatar
    Join Date
    Aug 2006
    Location
    West Wales
    Posts
    809

    Re: Run another program inside a form

    Looks like this ocx costs money - is that right or do you know of a free version?
    Paul Orton
    VB6
    Visual Web Developer 2008 Express Edition
    Microsoft Visual Basic 2012 Express

  5. #5

    Thread Starter
    Fanatic Member paulorton's Avatar
    Join Date
    Aug 2006
    Location
    West Wales
    Posts
    809

    Re: Run another program inside a form

    I've downloaded the free trial but see it needs the full version of Acrobat to work - does that mean the end-user has to have it, too?

    My requirements are very simple - I simply want to be able to open a pdf in a child form to be able to either view it or print it.

    Is the Smart Print Control (currently version 4.1) worth buying? It claims to be able to print many types of file.
    Paul Orton
    VB6
    Visual Web Developer 2008 Express Edition
    Microsoft Visual Basic 2012 Express

  6. #6
    Hyperactive Member
    Join Date
    Jun 2006
    Posts
    372

    Re: Run another program inside a form

    maybe this is a dumb idea, but acrobat has a plugin that runs within internet explorer. it might be possible to use a webbrowser control to run the plugin. maybe just using navigate2 ("test.pdf"). could work.

    otherwise, youre likely looking at a lot of complicated subclassing...

  7. #7
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: Run another program inside a form

    I have it on both my systems and I only have Acrobat Reader which is free. You may not be able to distribute it but you can include the download link and installation of Reader from the installation of your app.

    If you have Reader 5 or 6 then its pdf.ocx. If you have Reader 7 or 8 then its AcroPDF.dll

    Add the control to your toolbox....
    Project > Components ... > check "Adobe Acrobat 7.0 Control Type Library" > click OK.
    (C:\...\Acrobat\ActiveX\AcroPDF.dll)

    Then drag the pdf control from the toolbox and drop on your form, resize, and supply a pdf file/path to the src property.


    vb Code:
    1. Option Explicit
    2.  
    3. Private Sub Form_Load()
    4.     AcroPDF1.src = "C:\Users\VB-Guru\Documents\VS2005_Walkthroughs.pdf"
    5. End Sub
    Attached Images Attached Images  
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  8. #8

    Thread Starter
    Fanatic Member paulorton's Avatar
    Join Date
    Aug 2006
    Location
    West Wales
    Posts
    809

    Re: Run another program inside a form

    Thanks for that!

    OK, I've put this control on my form and specified the src property but the file won't load. I get the Reader error " File doesn't begin with '%PDF-' ".

    Don't tell me - Adobe doesn't like spaces in the path? I'll test this now but if so this is yet another thing to hate about Adobe and pdf files - grr!
    Paul Orton
    VB6
    Visual Web Developer 2008 Express Edition
    Microsoft Visual Basic 2012 Express

  9. #9

    Thread Starter
    Fanatic Member paulorton's Avatar
    Join Date
    Aug 2006
    Location
    West Wales
    Posts
    809

    Re: Run another program inside a form

    Nope - same error message with "C:\GP1-1.pdf" as the source.
    Anyone any idea what's wrong?
    Paul Orton
    VB6
    Visual Web Developer 2008 Express Edition
    Microsoft Visual Basic 2012 Express

  10. #10
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: Run another program inside a form

    Is the pdf file generated via some other creator and not Acrobat? If so then the pdf file may not be 100% compatible?[/color]
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  11. #11

    Thread Starter
    Fanatic Member paulorton's Avatar
    Join Date
    Aug 2006
    Location
    West Wales
    Posts
    809

    Re: Run another program inside a form

    Quote Originally Posted by RobDog888
    Is the pdf file generated via some other creator and not Acrobat? If so then the pdf file may not be 100% compatible?[/color]
    No, it was created by Acrobat 6. I think, given the difficulty I'm having, I will confine myself to just printing these files (the most important functionality I need by far).

    Unless you can think of something else...
    Paul Orton
    VB6
    Visual Web Developer 2008 Express Edition
    Microsoft Visual Basic 2012 Express

  12. #12
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: Run another program inside a form

    Look at the properties of a pdf file that does not work. There is a PDF tab and under it is the PDF Producer property. What does that say it was created with?
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  13. #13

    Thread Starter
    Fanatic Member paulorton's Avatar
    Join Date
    Aug 2006
    Location
    West Wales
    Posts
    809

    Re: Run another program inside a form

    Acrobat Distiller 5.0 (Windows)

    BTW, I wanted to drop a screenshot of the properties window here but it seems you can only paste an image from a website - or is there another way?
    Paul Orton
    VB6
    Visual Web Developer 2008 Express Edition
    Microsoft Visual Basic 2012 Express

  14. #14
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: Run another program inside a form

    Yes, save it as a file (picture formats) and then attach it to a post using the Manage Attachments button when replying/editing.

    I want to make sure the d's you are testing are valid but looks like they are ok.

    What version of Acrobat Reader do you actually have on your system?
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  15. #15

    Thread Starter
    Fanatic Member paulorton's Avatar
    Join Date
    Aug 2006
    Location
    West Wales
    Posts
    809

    Re: Run another program inside a form

    Adobe Reader 7
    Paul Orton
    VB6
    Visual Web Developer 2008 Express Edition
    Microsoft Visual Basic 2012 Express

  16. #16
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: Run another program inside a form

    Try this example with pdf attached. I wrote it from my xp sp-2 system with Reader 7.0
    Attached Files Attached Files
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  17. #17

    Thread Starter
    Fanatic Member paulorton's Avatar
    Join Date
    Aug 2006
    Location
    West Wales
    Posts
    809

    Re: Run another program inside a form

    Quote Originally Posted by RobDog888
    Try this example with pdf attached. I wrote it from my xp sp-2 system with Reader 7.0
    Thanks for taking all the trouble to do this.

    I've run your code and get the same error message as my own code - "File does not begin with...etc".

    What's even stranger is that the AcroPdf control disappears from the form each time I close down VB and I have to put it back on (it does this with your project as well as mine).

    I used AcroPDF.dll from the ActiveX folder of my Reader 7 installation - is this the file you use on your system?
    Paul Orton
    VB6
    Visual Web Developer 2008 Express Edition
    Microsoft Visual Basic 2012 Express

  18. #18
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: Run another program inside a form

    Yes, and it sounds like its in the same location as mine. Hmm, I'm wondering if you have VS SP-6 installed and any Acrobat updates.
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  19. #19

    Thread Starter
    Fanatic Member paulorton's Avatar
    Join Date
    Aug 2006
    Location
    West Wales
    Posts
    809

    Re: Run another program inside a form

    Quote Originally Posted by RobDog888
    Yes, and it sounds like its in the same location as mine. Hmm, I'm wondering if you have VS SP-6 installed and any Acrobat updates.
    Downloading SP6 as I write...

    I haven't installed any Acrobat updates - I only installed version 7 a few days ago.
    Paul Orton
    VB6
    Visual Web Developer 2008 Express Edition
    Microsoft Visual Basic 2012 Express

  20. #20

    Thread Starter
    Fanatic Member paulorton's Avatar
    Join Date
    Aug 2006
    Location
    West Wales
    Posts
    809

    Re: Run another program inside a form

    Service pack 6 has made no difference.

    Acrobat Reader is version 7.0.0 - downloading 7.0.9 now...
    Paul Orton
    VB6
    Visual Web Developer 2008 Express Edition
    Microsoft Visual Basic 2012 Express

  21. #21
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: Run another program inside a form

    Hmm, the code works and Iknow others using it. I really think there it is something particular about your system setup that may be the issue. I tested it with XP SP-2 andAcrobat Reader 7. And also, Vista RTM with Acrobat Reader 8 and both run the code example fine.
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  22. #22

    Thread Starter
    Fanatic Member paulorton's Avatar
    Join Date
    Aug 2006
    Location
    West Wales
    Posts
    809

    Re: Run another program inside a form

    Just installed the Acrobat update and your code now works.

    Thanks for continuing to listen!
    Paul Orton
    VB6
    Visual Web Developer 2008 Express Edition
    Microsoft Visual Basic 2012 Express

  23. #23
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: Run another program inside a form

    Cool! Glad its working for you now.

    So 7.0 initial install needs an update. Good to know what the issue was. Thanks.
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  24. #24
    Lively Member
    Join Date
    Oct 2006
    Location
    Spain
    Posts
    97

    Re: [RESOLVED] Run another program inside a form

    It has a problem:

    When closing the form, does not close file pdf. How closes the file?

  25. #25
    Lively Member
    Join Date
    Oct 2006
    Location
    Spain
    Posts
    97

    Re: [RESOLVED] Run another program inside a form

    solution:

    In a module:

    Code:
    Option Explicit
    
    Type PROCESSENTRY32
        dwSize As Long
        cntUsage As Long
        th32ProcessID As Long
        th32DefaultHeapID As Long
        th32ModuleID As Long
        cntThreads As Long
        th32ParentProcessID As Long
        pcPriClassBase As Long
        dwFlags As Long
        szexeFile As String * 260
    End Type
    
    Declare Function OpenProcess Lib "kernel32.dll" (ByVal dwDesiredAccess As Long, _
    ByVal blnheritHandle As Long, ByVal dwAppProcessId As Long) As Long
    
    Declare Function ProcessFirst Lib "kernel32.dll" Alias "Process32First" (ByVal hSnapshot As Long, _
    uProcess As PROCESSENTRY32) As Long
    
    Declare Function ProcessNext Lib "kernel32.dll" Alias "Process32Next" (ByVal hSnapshot As Long, _
    uProcess As PROCESSENTRY32) As Long
    
    Declare Function CreateToolhelpSnapshot Lib "kernel32.dll" Alias "CreateToolhelp32Snapshot" ( _
    ByVal lFlags As Long, lProcessID As Long) As Long
    
    Declare Function TerminateProcess Lib "kernel32.dll" (ByVal ApphProcess As Long, _
    ByVal uExitCode As Long) As Long
    
    Declare Function CloseHandle Lib "kernel32.dll" (ByVal hObject As Long) As Long
    
    
    Public Sub KillProcess(NameProcess As String)
    
        Const PROCESS_ALL_ACCESS = &H1F0FFF
        Const TH32CS_SNAPPROCESS As Long = 2&
        Dim uProcess  As PROCESSENTRY32
        Dim RProcessFound As Long
        Dim hSnapshot As Long
        Dim SzExename As String
        Dim ExitCode As Long
        Dim MyProcess As Long
        Dim AppKill As Boolean
        Dim AppCount As Integer
        Dim i As Integer
        Dim WinDirEnv As String
                
               If NameProcess <> "" Then
                  AppCount = 0
        
                  uProcess.dwSize = Len(uProcess)
                  hSnapshot = CreateToolhelpSnapshot(TH32CS_SNAPPROCESS, 0&)
                  RProcessFound = ProcessFirst(hSnapshot, uProcess)
          
                  Do
                    i = InStr(1, uProcess.szexeFile, Chr(0))
                    SzExename = LCase$(Left$(uProcess.szexeFile, i - 1))
                    WinDirEnv = Environ("Windir") + "\"
                    WinDirEnv = LCase$(WinDirEnv)
                
                    If Right$(SzExename, Len(NameProcess)) = LCase$(NameProcess) Then
                       AppCount = AppCount + 1
                       MyProcess = OpenProcess(PROCESS_ALL_ACCESS, False, uProcess.th32ProcessID)
                       AppKill = TerminateProcess(MyProcess, ExitCode)
                       Call CloseHandle(MyProcess)
                    End If
                    RProcessFound = ProcessNext(hSnapshot, uProcess)
                  Loop While RProcessFound
                  Call CloseHandle(hSnapshot)
               End If
    
    End Sub
    In a form:

    Code:
    Option Explicit
    
    Private Sub Command1_Click()
        KillProcess ("AcroRd32.exe")
        Unload Me
    End Sub
    
    Private Sub Form_Load()
        AcroPDF1.src = App.Path & "\Test.pdf"
    End Sub

  26. #26
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: [RESOLVED] Run another program inside a form

    It killed the process automatically for me on my system.
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width