Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Open other Application From Dialogue

Open other Application From Dialogue

Scheduled Pinned Locked Moved C / C++ / MFC
tutorialc++help
10 Posts 5 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • C Offline
    C Offline
    camuoi288
    wrote on last edited by
    #1

    I have a Dialogue and a Button "Open".I want when i click on "Open" Button,an other application will open.I know MFC guide to use CreatProcess Function but i don't know how to add this function into "Open" Clicked event.:(.Please help me. Example i have:

    void CThunghiemDlg::OnButtonOpen()
    {
    // TODO: Add your control notification handler code here

    }

    L V L S 4 Replies Last reply
    0
    • C camuoi288

      I have a Dialogue and a Button "Open".I want when i click on "Open" Button,an other application will open.I know MFC guide to use CreatProcess Function but i don't know how to add this function into "Open" Clicked event.:(.Please help me. Example i have:

      void CThunghiemDlg::OnButtonOpen()
      {
      // TODO: Add your control notification handler code here

      }

      L Offline
      L Offline
      Lost User
      wrote on last edited by
      #2

      :confused: I think the above comment makes it fairly clear what you need to do. Just add the code to run the external application. Or have I misunderstood your question?

      The best things in life are not things.

      C 1 Reply Last reply
      0
      • C camuoi288

        I have a Dialogue and a Button "Open".I want when i click on "Open" Button,an other application will open.I know MFC guide to use CreatProcess Function but i don't know how to add this function into "Open" Clicked event.:(.Please help me. Example i have:

        void CThunghiemDlg::OnButtonOpen()
        {
        // TODO: Add your control notification handler code here

        }

        V Offline
        V Offline
        venkatmakam
        wrote on last edited by
        #3

        Check this Article, A newbie's elementary guide to spawning processes[^] Creating a process, and then killing it[^]

        http://www.mono-project.com/Main\_Page

        1 Reply Last reply
        0
        • C camuoi288

          I have a Dialogue and a Button "Open".I want when i click on "Open" Button,an other application will open.I know MFC guide to use CreatProcess Function but i don't know how to add this function into "Open" Clicked event.:(.Please help me. Example i have:

          void CThunghiemDlg::OnButtonOpen()
          {
          // TODO: Add your control notification handler code here

          }

          L Offline
          L Offline
          Legor
          wrote on last edited by
          #4

          What exactly don't you know? As you said it you'd have to add the code for creating a process in the button click event handler.

          C 1 Reply Last reply
          0
          • L Legor

            What exactly don't you know? As you said it you'd have to add the code for creating a process in the button click event handler.

            C Offline
            C Offline
            camuoi288
            wrote on last edited by
            #5

            Example i want to call InternetExplorer.exe when i click on "Open" button,so what code i need add to "void CthunghiemDlg :: OnOpen". Because CreateProcess is function return Bool Value.

            1 Reply Last reply
            0
            • L Lost User

              :confused: I think the above comment makes it fairly clear what you need to do. Just add the code to run the external application. Or have I misunderstood your question?

              The best things in life are not things.

              C Offline
              C Offline
              camuoi288
              wrote on last edited by
              #6

              My question is how to call a application (example FireFox.exe) when i click in "Open" Button on Dialogue.I don't know use CreateProcess in function : "void CthunghiemDlg::OnOpen" because CreateProcess is function return Bool Value,and with what value of this function is a application called?

              L 1 Reply Last reply
              0
              • C camuoi288

                My question is how to call a application (example FireFox.exe) when i click in "Open" Button on Dialogue.I don't know use CreateProcess in function : "void CthunghiemDlg::OnOpen" because CreateProcess is function return Bool Value,and with what value of this function is a application called?

                L Offline
                L Offline
                Lost User
                wrote on last edited by
                #7

                camuoi288 wrote:

                .I don't know use CreateProcess

                All explained here[^].

                camuoi288 wrote:

                because CreateProcess is function return Bool Value

                This is merely a value to tell you whether CreateProcess() succeeded or not.

                The best things in life are not things.

                1 Reply Last reply
                0
                • C camuoi288

                  I have a Dialogue and a Button "Open".I want when i click on "Open" Button,an other application will open.I know MFC guide to use CreatProcess Function but i don't know how to add this function into "Open" Clicked event.:(.Please help me. Example i have:

                  void CThunghiemDlg::OnButtonOpen()
                  {
                  // TODO: Add your control notification handler code here

                  }

                  S Offline
                  S Offline
                  ShilpiP
                  wrote on last edited by
                  #8

                  Simple Example of CreateProcess

                  //Global Variable
                  DWORD g_nRetVal = 0;
                  DWORD g_nWaitCode = 0;
                  HANDLE g_hWaited = NULL;

                  DWORD WINAPI RunUtils(void *pParam) {
                  LPCTSTR szExe = TEXT("Path of executable");
                  LPTSTR szParams = TEXT(" /d C:");
                  HANDLE hEvent = NULL;
                  PROCESS_INFORMATION ProcessInfo;
                  ZeroMemory(&ProcessInfo, sizeof(ProcessInfo));
                  STARTUPINFO StartupInfo;
                  ZeroMemory(&StartupInfo, sizeof(StartupInfo));
                  StartupInfo.cb = sizeof(StartupInfo);
                  StartupInfo.dwFlags = STARTF_USESHOWWINDOW;
                  StartupInfo.wShowWindow = SW_HIDE;
                  hEvent = CreateEvent(NULL, TRUE, FALSE, NULL);
                  if (CreateProcess(szExe, szParams, NULL, NULL, FALSE, CREATE_NEW_CONSOLE, NULL, NULL, &StartupInfo, &ProcessInfo)) {
                  g_nWaitCode = WaitForSingleObject(ProcessInfo.hProcess, INFINITE);
                  switch (g_nWaitCode) {
                  case WAIT_OBJECT_0:
                  GetExitCodeProcess(ProcessInfo.hProcess, &g_nRetVal);
                  break;

                  		case WAIT\_FAILED:
                  			g\_nWaitCode = GetLastError();
                  			break;
                  	}
                  	::CloseHandle(ProcessInfo.hProcess);
                  	::CloseHandle(ProcessInfo.hThread);
                  	
                  	ResetEvent(hEvent);
                  
                  	HWND hWnd = (HWND) pParam;
                  	SendMessage(hWnd, WM\_USER\_THREAD\_WAITED, 0, 0);
                  }
                  return 0;
                  

                  }

                  void CThunghiemDlg::OnButtonOpen()
                  {
                  // TODO: Add your control notification handler code here
                  HANDLE hExecThread = NULL;
                  if(m_bCleanUp)
                  {
                  hExecThread = CreateThread(NULL, 0, &RunUtils, (LPVOID) m_hWnd, 0, NULL);
                  }
                  }

                  You can do the same by using ShellExecute

                  void CThunghiemDlg::OnButtonOpen()
                  {
                  ShellExecute(NULL, "open", "path of executable", NULL, NULL, SW_SHOWNORMAL);

                  }

                  "Every Little Smile can touch Somebody's Heart... May we find Hundreds of Reasons to Smile Everyday... and May WE be the Reason for someone else to smile always!" (ICAN)

                  C 1 Reply Last reply
                  0
                  • S ShilpiP

                    Simple Example of CreateProcess

                    //Global Variable
                    DWORD g_nRetVal = 0;
                    DWORD g_nWaitCode = 0;
                    HANDLE g_hWaited = NULL;

                    DWORD WINAPI RunUtils(void *pParam) {
                    LPCTSTR szExe = TEXT("Path of executable");
                    LPTSTR szParams = TEXT(" /d C:");
                    HANDLE hEvent = NULL;
                    PROCESS_INFORMATION ProcessInfo;
                    ZeroMemory(&ProcessInfo, sizeof(ProcessInfo));
                    STARTUPINFO StartupInfo;
                    ZeroMemory(&StartupInfo, sizeof(StartupInfo));
                    StartupInfo.cb = sizeof(StartupInfo);
                    StartupInfo.dwFlags = STARTF_USESHOWWINDOW;
                    StartupInfo.wShowWindow = SW_HIDE;
                    hEvent = CreateEvent(NULL, TRUE, FALSE, NULL);
                    if (CreateProcess(szExe, szParams, NULL, NULL, FALSE, CREATE_NEW_CONSOLE, NULL, NULL, &StartupInfo, &ProcessInfo)) {
                    g_nWaitCode = WaitForSingleObject(ProcessInfo.hProcess, INFINITE);
                    switch (g_nWaitCode) {
                    case WAIT_OBJECT_0:
                    GetExitCodeProcess(ProcessInfo.hProcess, &g_nRetVal);
                    break;

                    		case WAIT\_FAILED:
                    			g\_nWaitCode = GetLastError();
                    			break;
                    	}
                    	::CloseHandle(ProcessInfo.hProcess);
                    	::CloseHandle(ProcessInfo.hThread);
                    	
                    	ResetEvent(hEvent);
                    
                    	HWND hWnd = (HWND) pParam;
                    	SendMessage(hWnd, WM\_USER\_THREAD\_WAITED, 0, 0);
                    }
                    return 0;
                    

                    }

                    void CThunghiemDlg::OnButtonOpen()
                    {
                    // TODO: Add your control notification handler code here
                    HANDLE hExecThread = NULL;
                    if(m_bCleanUp)
                    {
                    hExecThread = CreateThread(NULL, 0, &RunUtils, (LPVOID) m_hWnd, 0, NULL);
                    }
                    }

                    You can do the same by using ShellExecute

                    void CThunghiemDlg::OnButtonOpen()
                    {
                    ShellExecute(NULL, "open", "path of executable", NULL, NULL, SW_SHOWNORMAL);

                    }

                    "Every Little Smile can touch Somebody's Heart... May we find Hundreds of Reasons to Smile Everyday... and May WE be the Reason for someone else to smile always!" (ICAN)

                    C Offline
                    C Offline
                    camuoi288
                    wrote on last edited by
                    #9

                    I want to ask: "m_bCleaup variable and WN_USER_THREAD_WAITED variable".How are they declared?and how to use them?

                    S 1 Reply Last reply
                    0
                    • C camuoi288

                      I want to ask: "m_bCleaup variable and WN_USER_THREAD_WAITED variable".How are they declared?and how to use them?

                      S Offline
                      S Offline
                      ShilpiP
                      wrote on last edited by
                      #10

                      no need to use these variable.

                      "Every Little Smile can touch Somebody's Heart... May we find Hundreds of Reasons to Smile Everyday... and May WE be the Reason for someone else to smile always!" (ICAN)

                      1 Reply Last reply
                      0
                      Reply
                      • Reply as topic
                      Log in to reply
                      • Oldest to Newest
                      • Newest to Oldest
                      • Most Votes


                      • Login

                      • Don't have an account? Register

                      • Login or register to search.
                      • First post
                        Last post
                      0
                      • Categories
                      • Recent
                      • Tags
                      • Popular
                      • World
                      • Users
                      • Groups