Results 1 to 5 of 5

Thread: Easy Quick question on running things

  1. #1

    Thread Starter
    Member Cahlel's Avatar
    Join Date
    Aug 2000
    Location
    Earth (I think)
    Posts
    63

    Question

    How do you run a program from C++? I know how to do it in VB, but I don't know what to use to do it in C++, anything similar to Shell="c:\~~~~\*.exe", vbnormalfocus and such?
    Wisdom is supreme, therefore get wisdom,
    though it costs all you have, get understanding.
    Proverbs 4:7

  2. #2
    Frenzied Member Vlatko's Avatar
    Join Date
    Aug 2000
    Location
    Skopje, Macedonia
    Posts
    1,409
    Use the ShellExecute API. You also need to include windows.h header.
    Code:
    HWND hWnd = FindWindow (NULL,"appname"); //if you don't know the HWND
    ShellExecute(hWnd,"open"  ,"c:\\windows\\notepad.exe",NULL,NULL,SW_SHOW );
    I am become death, the destroyer of worlds.
    mail:[email protected]

    • Visual Basic 6.0 & .NET
    • Visual C++ 6.0 & .NET
    • ASP
    • LISP
    • PROLOG
    • C
    • Pascal

  3. #3
    Frenzied Member Jop's Avatar
    Join Date
    Mar 2000
    Location
    Amsterdam, the Netherlands
    Posts
    1,986
    I think the WinExec api is easier to understand for this task.

    It's in kernel32 and think it's available in C++.

    Here's an example.

    Code:
    WinExec("my.exe", 1);
    // also accepts parameters like my.exe -a -x -s http://vbworld.com
    Ps: Vlatko, I don't think the ShellExecute really needs the hWnd parameter, I used it in VB just by passing 0&, should work too (I'm at my work now so I can't test)

    [Edited by Jop on 01-08-2001 at 12:56 PM]
    Jop - validweb.nl

    Alcohol doesn't solve any problems, but then again, neither does milk.

  4. #4
    Frenzied Member Vlatko's Avatar
    Join Date
    Aug 2000
    Location
    Skopje, Macedonia
    Posts
    1,409
    The hWnd parameter has its own value here. Receiving errors in a form of a message box.

    MSDN:
    Code:
    hwnd 
    Window handle to a parent window. This window receives any message boxes that an application produces. For example, an application may report an error by producing a message box.
    I am become death, the destroyer of worlds.
    mail:[email protected]

    • Visual Basic 6.0 & .NET
    • Visual C++ 6.0 & .NET
    • ASP
    • LISP
    • PROLOG
    • C
    • Pascal

  5. #5
    Frenzied Member Jop's Avatar
    Join Date
    Mar 2000
    Location
    Amsterdam, the Netherlands
    Posts
    1,986
    Thanks! didn't even know that
    Jop - validweb.nl

    Alcohol doesn't solve any problems, but then again, neither does milk.

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