handle to a window created by createprocess
-
I have used createProcess to run a process in a new window using CREATE_NEW_CONSOLE flag, Can any one help to get the handle to the console that i have created so as to close that window. code: CreateProcess(_T("\\windows\\ceplayer.exe"),_T("c:\\folder\\new.wmv"), NULL, NULL, FALSE, CREATE_NEW_CONSOLE, NULL, NULL, NULL, &processInfo); Thanks in Advance
-
I have used createProcess to run a process in a new window using CREATE_NEW_CONSOLE flag, Can any one help to get the handle to the console that i have created so as to close that window. code: CreateProcess(_T("\\windows\\ceplayer.exe"),_T("c:\\folder\\new.wmv"), NULL, NULL, FALSE, CREATE_NEW_CONSOLE, NULL, NULL, NULL, &processInfo); Thanks in Advance
You can use EnumWindows() or EnumThreadWindows() to enumerate top level windows and GetWindowThreadProcessid() to check if specific window is created by your process (processInfo.dwProceddId)
Slavisa
-
You can use EnumWindows() or EnumThreadWindows() to enumerate top level windows and GetWindowThreadProcessid() to check if specific window is created by your process (processInfo.dwProceddId)
Slavisa
Thanks Slavisa, I tried it. but it does nothing i donno why.. Could u please help me further with my code below: (I want to close the console that created within 3 seconds but it is not moving into that if part (bold)) CreateProcess(_T("\\windows\\iesample.exe"),imFullPath, NULL, NULL, FALSE, CREATE_NEW_CONSOLE, NULL, NULL, NULL, &processInfo1); Sleep(3000); EnumWindows(&EnumProc,processInfo1.dwProcessId); BOOL CALLBACK EnumProc(HWND hwnd, LPARAM param) { DWORD id = GetWindowThreadProcessId(hwnd, NULL); if (id == (DWORD)param) { DestroyWindow(hwnd); return false; } return true; }
-
Thanks Slavisa, I tried it. but it does nothing i donno why.. Could u please help me further with my code below: (I want to close the console that created within 3 seconds but it is not moving into that if part (bold)) CreateProcess(_T("\\windows\\iesample.exe"),imFullPath, NULL, NULL, FALSE, CREATE_NEW_CONSOLE, NULL, NULL, NULL, &processInfo1); Sleep(3000); EnumWindows(&EnumProc,processInfo1.dwProcessId); BOOL CALLBACK EnumProc(HWND hwnd, LPARAM param) { DWORD id = GetWindowThreadProcessId(hwnd, NULL); if (id == (DWORD)param) { DestroyWindow(hwnd); return false; } return true; }
The return value of
GetWindowThreadProcessId
is the thread Id and not the process Id. If you want the process Id, use the second parameter like so.DWORD dwProcessId = 0;
GetWindowThreadProcessId(hwnd, &dwProcessId);
if (dwProcessId == (DWORD)param)«_Superman_» I love work. It gives me something to do between weekends.
-
Thanks Slavisa, I tried it. but it does nothing i donno why.. Could u please help me further with my code below: (I want to close the console that created within 3 seconds but it is not moving into that if part (bold)) CreateProcess(_T("\\windows\\iesample.exe"),imFullPath, NULL, NULL, FALSE, CREATE_NEW_CONSOLE, NULL, NULL, NULL, &processInfo1); Sleep(3000); EnumWindows(&EnumProc,processInfo1.dwProcessId); BOOL CALLBACK EnumProc(HWND hwnd, LPARAM param) { DWORD id = GetWindowThreadProcessId(hwnd, NULL); if (id == (DWORD)param) { DestroyWindow(hwnd); return false; } return true; }
I think it is better to send WM_CLOSE to the window instead of calling DestroyWindow().
Slavisa
-
I have used createProcess to run a process in a new window using CREATE_NEW_CONSOLE flag, Can any one help to get the handle to the console that i have created so as to close that window. code: CreateProcess(_T("\\windows\\ceplayer.exe"),_T("c:\\folder\\new.wmv"), NULL, NULL, FALSE, CREATE_NEW_CONSOLE, NULL, NULL, NULL, &processInfo); Thanks in Advance
I suspect you've to use
EnumThreadWindows
[^], passing, asdwThreadId
argument, thedwThreadId
member of thePROCESS_INFORMATION
struct filled byCreateProcess
function. It's just a guess: the test is up to you. :)If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke
[My articles] -
The return value of
GetWindowThreadProcessId
is the thread Id and not the process Id. If you want the process Id, use the second parameter like so.DWORD dwProcessId = 0;
GetWindowThreadProcessId(hwnd, &dwProcessId);
if (dwProcessId == (DWORD)param)«_Superman_» I love work. It gives me something to do between weekends.
Friens i used GetWindowThreadProcessId(hwnd, &dwProcessId); and also PostMessage(hwnd,WM_CLOSE,0); but it is not moving into that if loop still if(dwprocessid == DWORD(param)) i could not figure it out what i need to do now or IS there any other way to get the handle of the window seeking ur help....
-
I suspect you've to use
EnumThreadWindows
[^], passing, asdwThreadId
argument, thedwThreadId
member of thePROCESS_INFORMATION
struct filled byCreateProcess
function. It's just a guess: the test is up to you. :)If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke
[My articles]Friens i used GetWindowThreadProcessId(hwnd, &dwProcessId); and also PostMessage(hwnd,WM_CLOSE,0); but it is not moving into that if loop still if(dwprocessid == DWORD(param)) i could not figure it out what i need to do now or IS there any other way to get the handle of the window seeking ur help....
-
Friens i used GetWindowThreadProcessId(hwnd, &dwProcessId); and also PostMessage(hwnd,WM_CLOSE,0); but it is not moving into that if loop still if(dwprocessid == DWORD(param)) i could not figure it out what i need to do now or IS there any other way to get the handle of the window seeking ur help....
Well, since you just want to close the program you could use TerminateProcess(hProcess, 0);
Slavisa
-
Well, since you just want to close the program you could use TerminateProcess(hProcess, 0);
Slavisa
I am sorry not exactly i want to close the process slavisa i need to close that window alone and should open the next command line say next.wmv in that place
-
Well, since you just want to close the program you could use TerminateProcess(hProcess, 0);
Slavisa
A hammer is another option. :)
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke
[My articles] -
A hammer is another option. :)
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke
[My articles]I am sorry i could get what does A hammer is.. could you please throw some light on this area..
-
I am sorry i could get what does A hammer is.. could you please throw some light on this area..
Hammer [^]. :)
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke
[My articles] -
Hammer [^]. :)
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke
[My articles]I am in a serious deputation buddy...
-
I am in a serious deputation buddy...
vijaywithu wrote:
I am in a serious deputation buddy...
You are a Member of Parliament? :rolleyes:
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke
[My articles]