how can I run an external program like ( word , notepad ,... )In C ?
and how can I set a certain size of the window of the external program like ( 300 * 300 ) ?

Try it with function system() which takes string. All written as parameter to this function is like you type in cmd.
For example, system("notepad.exe") should run notepad.

thanks all

Ancient Dragon
can you put the code for run notepad or word ?
because i tried many time but does not work ( i use Visual Studio )

Whether you can specify the new window's size and location will depend on the program you are trying to launch. Some program, apparently like Notepad.exe, do not honor such requests. In this example I created a Windows Forms program. The code below will change its initial x and y upper-left coordinated but the window size does not change.

#include <Windows.h>
#include <iostream>
using std::cout;

int main(int argc, char* argv[])
{
    STARTUPINFO info;
    PROCESS_INFORMATION pinfo;
    memset(&info,0,sizeof(info));
    memset(&pinfo,0,sizeof(pinfo));
    info.cb = sizeof(STARTUPINFO);
    info.dwX = 150;
    info.dwY = 150;
    info.dwXSize = 300;
    info.dwYSize = 600;
    info.dwFlags = STARTF_USEPOSITION|STARTF_USESIZE;

    BOOL rval = CreateProcess("C:\\dvlp\\addressbooki.exe",0,0,0,
        0,0,NULL,NULL,&info,&pinfo);
    if( rval == FALSE)
    {
        char buf[255] = {0};
        DWORD dwError = GetLastError();
        FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM,0,dwError,0,buf,sizeof(buf),0);
        cout << buf << '\n';
        return 1;
    }
    cout << "All ok\n";
   // The next line is optional -- only needed if this program
   // needs to wait until the spawned program has finished initializing
   // itself.
    WaitForInputIdle(pinfo.hProcess,INFINITE);



	return 0;
}

Whether you can specify the new window's size and location will depend on the program you are trying to launch. Some program, apparently like Notepad.exe, do not honor such requests. In this example I created a Windows Forms program. The code below will change its initial x and y upper-left coordinated but the window size does not change.

#include <Windows.h>
#include <iostream>
using std::cout;

int main(int argc, char* argv[])
{
    STARTUPINFO info;
    PROCESS_INFORMATION pinfo;
    memset(&info,0,sizeof(info));
    memset(&pinfo,0,sizeof(pinfo));
    info.cb = sizeof(STARTUPINFO);
    info.dwX = 150;
    info.dwY = 150;
    info.dwXSize = 300;
    info.dwYSize = 600;
    info.dwFlags = STARTF_USEPOSITION|STARTF_USESIZE;

    BOOL rval = CreateProcess("C:\\dvlp\\addressbooki.exe",0,0,0,
        0,0,NULL,NULL,&info,&pinfo);
    if( rval == FALSE)
    {
        char buf[255] = {0};
        DWORD dwError = GetLastError();
        FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM,0,dwError,0,buf,sizeof(buf),0);
        cout << buf << '\n';
        return 1;
    }
    cout << "All ok\n";
   // The next line is optional -- only needed if this program
   // needs to wait until the spawned program has finished initializing
   // itself.
    WaitForInputIdle(pinfo.hProcess,INFINITE);



	return 0;
}

He asked for C, not for C++

Comments
good catch :)
This article has been dead for over six months. Start a new discussion instead.