Dec 4, 2018 at 5:06pm UTC
I need to create a button on my interface on C++ and when someone click on this, open another program. How can i do this? I am using windows.h library
If anyone have a video tutorial for this, please give me the link. Thanks!
Dec 4, 2018 at 5:46pm UTC
I don't know about GUI buttons, but to start another program from your program, check out the
CreateProcess function:
https://docs.microsoft.com/en-us/windows/desktop/api/processthreadsapi/nf-processthreadsapi-createprocessa
For an example of its use, check out:
https://stackoverflow.com/questions/42531/how-do-i-call-createprocess-in-c-to-launch-a-windows-executable
Credit goes to 1800 INFORMATION, I added a full example to it:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
#include <windows.h>
#include <iostream>
int main()
{
char path[] = "C:/Windows/system32/calc.exe" ;
char * cmd = NULL; // command-line arguments
STARTUPINFO info={sizeof (info)};
PROCESS_INFORMATION processInfo;
if (CreateProcess(path, cmd, NULL, NULL, TRUE, 0, NULL, NULL, &info, &processInfo))
{
WaitForSingleObject(processInfo.hProcess, INFINITE);
CloseHandle(processInfo.hProcess);
CloseHandle(processInfo.hThread);
}
else
{
std::cout << "Error: " << GetLastError() << std::endl;
}
}
Last edited on Dec 4, 2018 at 5:46pm UTC
Dec 4, 2018 at 6:51pm UTC
Oh, this helped me soooooo much
Thanks bro!!!
If I have another question, I post here, Thanks again!!