Results 1 to 6 of 6

Thread: run program in your from ?!

  1. #1

    Thread Starter
    New Member
    Join Date
    Apr 2010
    Posts
    9

    run program in your from ?!

    Hi Guys

    Is there any way to run windows program like c:\WINDOWS\system32\calc.exe inside my form

    For example:

    This is my form I want to run the calc inside my form !!? is it possible Pls help me with the code how to do it !?



    Please advice

  2. #2
    Former Admin/Moderator MartinLiss's Avatar
    Join Date
    Sep 1999
    Location
    San Jose, CA
    Posts
    33,431

    Re: run program in your from ?!

    VB Code:
    1. Option Explicit
    2. Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
    3. Private Declare Function SetParent Lib "user32" (ByVal hWndChild As Long, ByVal hWndNewParent As Long) As Long
    4.  
    5. Private Sub Form_Load()
    6.  
    7. Dim lngHandle As Long
    8.  
    9. Picture1.AutoRedraw = True
    10. Shell "c:\WINDOWS\system32\calc.exe", vbNormalFocus
    11. lngHandle = FindWindow(vbNullString, "Calculator")
    12. SetParent lngHandle, Picture1.hwnd
    13. End Sub

  3. #3
    Former Admin/Moderator MartinLiss's Avatar
    Join Date
    Sep 1999
    Location
    San Jose, CA
    Posts
    33,431

    Re: run program in your from ?!

    Or maybe better

    VB Code:
    1. Option Explicit
    2. Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
    3. Private Declare Function SetParent Lib "user32" (ByVal hWndChild As Long, ByVal hWndNewParent As Long) As Long
    4. Private Declare Function MoveWindow Lib "user32" (ByVal hwnd As Long, ByVal x As Long, ByVal y As Long, ByVal nWidth As Long, ByVal nHeight As Long, ByVal bRepaint As Long) As Long
    5. Private Declare Function GetWindowRect Lib "user32" (ByVal hwnd As Long, lpRect As RECT) As Long
    6.  
    7. Private Type RECT
    8.     Left As Long
    9.     Top As Long
    10.     Right As Long
    11.     Bottom As Long
    12. End Type
    13.  
    14.  
    15. Private Sub Form_Load()
    16.  
    17. Dim lngHandle As Long
    18. Dim rec As RECT
    19.  
    20. Picture1.AutoRedraw = True
    21. Form1.ScaleMode = vbPixels
    22. Shell "c:\WINDOWS\system32\calc.exe", vbNormalFocus
    23. lngHandle = FindWindow(vbNullString, "Calculator")
    24. GetWindowRect lngHandle, rec
    25. SetParent lngHandle, Picture1.hwnd
    26. Picture1.Width = rec.Right - rec.Left
    27. Picture1.Height = rec.Bottom - rec.Top
    28. ' The first 5 parameters are required but weonly care about the 1st three
    29. MoveWindow lngHandle, 0, 0, Picture1.Width, Picture1.Height, 1
    30. End Sub

  4. #4

    Thread Starter
    New Member
    Join Date
    Apr 2010
    Posts
    9

    Re: run program in your from ?!

    Thanks a lot .. just I want to save that presented program which is running there in Picture1 as image in c:\running.jpg

    Pls help me in this thing ..

  5. #5

  6. #6

    Thread Starter
    New Member
    Join Date
    Apr 2010
    Posts
    9

    Re: run program in your from ?!

    ok I'm using that code to capture the picturec.1 .. but how to can I save it in as c:\running.jpg

    http://www.vbforums.com/showthread.php?t=331889

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