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. Starting .exe...

Starting .exe...

Scheduled Pinned Locked Moved C / C++ / MFC
question
10 Posts 6 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.
  • M Offline
    M Offline
    macmac38
    wrote on last edited by
    #1

    Hello, how can i start another app from my application? After this i like to call the F4 Button? Thanks in advance, Mark

    L R D 3 Replies Last reply
    0
    • M macmac38

      Hello, how can i start another app from my application? After this i like to call the F4 Button? Thanks in advance, Mark

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

      ShellExecute() to start the other exe. To send a keystroke you might SendMessage(WM_KEYDOWN, ...) to the other application.

      1 Reply Last reply
      0
      • M macmac38

        Hello, how can i start another app from my application? After this i like to call the F4 Button? Thanks in advance, Mark

        R Offline
        R Offline
        Ryan Binns
        wrote on last edited by
        #3

        The simplest way is to use ShellExecute().

        ShellExecute(NULL, NULL, _T("myprog.exe"), NULL, SW_SHOWNORMAL);

        Look at the docs on ShellExecute() to find out what the parameters do and how to use them. To find out whether it is successful or not, ShellExecute() returns a value >32 if it is successful, and <=32 if it is not. Hope this helps, Ryan Being little and getting pushed around by big guys all my life I guess I compensate by pushing electrons and holes around. What a bully I am, but I do enjoy making subatomic particles hop at my bidding - Roger Wright (2nd April 2003, The Lounge)
        Punctuality is only a virtue for those who aren't smart enough to think of good excuses for being late - John Nichol "Point Of Impact"

        1 Reply Last reply
        0
        • M macmac38

          Hello, how can i start another app from my application? After this i like to call the F4 Button? Thanks in advance, Mark

          D Offline
          D Offline
          Dominik Reichl
          wrote on last edited by
          #4

          macmac38 wrote: how can i start another app from my application?

          BOOL CreateProcess(
          LPCTSTR lpApplicationName,
          // pointer to name of executable module
          LPTSTR lpCommandLine, // pointer to command line string
          LPSECURITY_ATTRIBUTES lpProcessAttributes, // process security attributes
          LPSECURITY_ATTRIBUTES lpThreadAttributes, // thread security attributes
          BOOL bInheritHandles, // handle inheritance flag
          DWORD dwCreationFlags, // creation flags
          LPVOID lpEnvironment, // pointer to new environment block
          LPCTSTR lpCurrentDirectory, // pointer to current directory name
          LPSTARTUPINFO lpStartupInfo, // pointer to STARTUPINFO
          LPPROCESS_INFORMATION lpProcessInformation // pointer to PROCESS_INFORMATION
          );

          macmac38 wrote: After this i like to call the F4 Button? You want to call the F4 button? I'm not sure what you mean... You can kill the process using the TerminateProcess function (you got the handle from CreateProcess). If you want to simulate a press to F4 you can use the SendInput or keybd_event functions. -Dominik


          _outp(0x64, 0xAD); and __asm mov al, 0xAD __asm out 0x64, al do the same... but what do they do?? ;)

          M 1 Reply Last reply
          0
          • D Dominik Reichl

            macmac38 wrote: how can i start another app from my application?

            BOOL CreateProcess(
            LPCTSTR lpApplicationName,
            // pointer to name of executable module
            LPTSTR lpCommandLine, // pointer to command line string
            LPSECURITY_ATTRIBUTES lpProcessAttributes, // process security attributes
            LPSECURITY_ATTRIBUTES lpThreadAttributes, // thread security attributes
            BOOL bInheritHandles, // handle inheritance flag
            DWORD dwCreationFlags, // creation flags
            LPVOID lpEnvironment, // pointer to new environment block
            LPCTSTR lpCurrentDirectory, // pointer to current directory name
            LPSTARTUPINFO lpStartupInfo, // pointer to STARTUPINFO
            LPPROCESS_INFORMATION lpProcessInformation // pointer to PROCESS_INFORMATION
            );

            macmac38 wrote: After this i like to call the F4 Button? You want to call the F4 button? I'm not sure what you mean... You can kill the process using the TerminateProcess function (you got the handle from CreateProcess). If you want to simulate a press to F4 you can use the SendInput or keybd_event functions. -Dominik


            _outp(0x64, 0xAD); and __asm mov al, 0xAD __asm out 0x64, al do the same... but what do they do?? ;)

            M Offline
            M Offline
            macmac38
            wrote on last edited by
            #5

            Yep, i can call the .exe now when i press a button in my app. What i like to do is to simulate the pressing of F4 after this. Because this starts a macro in the opened .exe. I cannot understand the help for these functions you gave me and do not know which code to use for F4(Hardwareadress, number..???) Do u have a code snip? Thanks, Mark

            L 1 Reply Last reply
            0
            • M macmac38

              Yep, i can call the .exe now when i press a button in my app. What i like to do is to simulate the pressing of F4 after this. Because this starts a macro in the opened .exe. I cannot understand the help for these functions you gave me and do not know which code to use for F4(Hardwareadress, number..???) Do u have a code snip? Thanks, Mark

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

              SendMessage(wndOfStartedApp, WM_KEYDOWN, VK_F4, 0); The first parameter is the HWND of the app you just started. Instead of WM_KEYDOWN you might also try WM_KEYUP.

              M 1 Reply Last reply
              0
              • L Lost User

                SendMessage(wndOfStartedApp, WM_KEYDOWN, VK_F4, 0); The first parameter is the HWND of the app you just started. Instead of WM_KEYDOWN you might also try WM_KEYUP.

                M Offline
                M Offline
                macmac38
                wrote on last edited by
                #7

                mmh, i use NULL for HWND when i start the app. Nothing happens.. Thanks, Mark

                J 1 Reply Last reply
                0
                • M macmac38

                  mmh, i use NULL for HWND when i start the app. Nothing happens.. Thanks, Mark

                  J Offline
                  J Offline
                  Joan M
                  wrote on last edited by
                  #8

                  It is normal: the HWND defines which window will receive the message, then if you send the KeyPress to a null window... you should start your app, then find the window of that app and after that send the message there... I think that you can also do it better, and in order to do so, you should take a look at CreateProcess(...). hope this helps.

                  https://www.robotecnik.com freelance robots, PLC and CNC programmer.

                  M 1 Reply Last reply
                  0
                  • J Joan M

                    It is normal: the HWND defines which window will receive the message, then if you send the KeyPress to a null window... you should start your app, then find the window of that app and after that send the message there... I think that you can also do it better, and in order to do so, you should take a look at CreateProcess(...). hope this helps.

                    M Offline
                    M Offline
                    macmac38
                    wrote on last edited by
                    #9

                    But how can i find the window of that app? It is a commercial one. By the way i think i have to wait till the app is up before i send the message there? Thanks, Mark

                    B 1 Reply Last reply
                    0
                    • M macmac38

                      But how can i find the window of that app? It is a commercial one. By the way i think i have to wait till the app is up before i send the message there? Thanks, Mark

                      B Offline
                      B Offline
                      basementman
                      wrote on last edited by
                      #10

                      If you launch it by using the CreateProcess api, one of the parameters is a PROCESS_INFORMATION structure. This gets filled in with the THREAD HANDLE of the primary thread for the newly lauched app. After the CreateProcess call returns, wait for the app to initialize by calling WaitForInputIdle(). When this returns, then you should be able to simulate a keystroke with the PostThreadMessage api, passing the new app's main thread handle as the parameter. Good Luck!  onwards and upwards...

                      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