Open other Application From Dialogue
-
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}
-
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}
-
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}
-
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}
-
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.
-
: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.
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?
-
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?
-
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}
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)
-
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)
-
I want to ask: "m_bCleaup variable and WN_USER_THREAD_WAITED variable".How are they declared?and how to use them?