MessageBox not getting Focus
-
Hi, I have an MFC application. I run a thread in middle. After completing the thread i have a message box that popsup. But messagebox doesnt have focus. Can anyone let me know how to get the focus back to message box? Thanks in advance. Code snippet: .... RunCmd("test.bat", SW_SHOW); MessageBox("dfas","fdifd",MB-OK); ..... Test.bat has come command to format disk etc. Regards..
-
Hi, I have an MFC application. I run a thread in middle. After completing the thread i have a message box that popsup. But messagebox doesnt have focus. Can anyone let me know how to get the focus back to message box? Thanks in advance. Code snippet: .... RunCmd("test.bat", SW_SHOW); MessageBox("dfas","fdifd",MB-OK); ..... Test.bat has come command to format disk etc. Regards..
-
Thanks for the reply. But that doesnt have the answer for my problem. After launching a thread and completing the foucus is not going to main window. In a dialog based application, I run: WinExec("test.bat"); Sleep("5000"); MessageBox("sdosn"....); MessageBox is not having focus. If i remove Thread executions in between (WinExec). Then i get the focus properly. Any updates on this.
-
Thanks for the reply. But that doesnt have the answer for my problem. After launching a thread and completing the foucus is not going to main window. In a dialog based application, I run: WinExec("test.bat"); Sleep("5000"); MessageBox("sdosn"....); MessageBox is not having focus. If i remove Thread executions in between (WinExec). Then i get the focus properly. Any updates on this.
Member 3834630 wrote:
WinExec("test.bat");
Firstly I want to say that WinExec function is Obsolete. you should use, CreateProcess() or ShellExecute() to create new process.
Member 3834630 wrote:
MessageBox is not having focus. If i remove Thread executions in between (WinExec). Then i get the focus properly.
Means if you comment out the WinExec() function, your message box is getting the focus and after closing the messagebox, your main dialog is getting the focus?
-
Member 3834630 wrote:
WinExec("test.bat");
Firstly I want to say that WinExec function is Obsolete. you should use, CreateProcess() or ShellExecute() to create new process.
Member 3834630 wrote:
MessageBox is not having focus. If i remove Thread executions in between (WinExec). Then i get the focus properly.
Means if you comment out the WinExec() function, your message box is getting the focus and after closing the messagebox, your main dialog is getting the focus?
Hi, Sorry, I am actually using CreatProcess() only. To make it simple i put WinExec() But after calling CreateProcess() which calls a batch file and after completing the process, i display a MessageBox(sdkjfo..), the MessageBox() gets displayed but doesnt have the focus. Yes, if i comment the CreateProcess() then MessageBox() gets the focus. Regards.
-
Hi, Sorry, I am actually using CreatProcess() only. To make it simple i put WinExec() But after calling CreateProcess() which calls a batch file and after completing the process, i display a MessageBox(sdkjfo..), the MessageBox() gets displayed but doesnt have the focus. Yes, if i comment the CreateProcess() then MessageBox() gets the focus. Regards.
Did you try modifying the code as I mentioned yesterday?
WinExec("test.bat");
Sleep("5000");//Attach foreground window thread
//to our thread
AttachThreadInput(
GetWindowThreadProcessId(
::GetForegroundWindow(),NULL),
GetCurrentThreadId(),TRUE);MessageBox("sdosn"....);
//Detach the attached thread
AttachThreadInput(
GetWindowThreadProcessId(
::GetForegroundWindow(),NULL),
GetCurrentThreadId(),FALSE); -
Did you try modifying the code as I mentioned yesterday?
WinExec("test.bat");
Sleep("5000");//Attach foreground window thread
//to our thread
AttachThreadInput(
GetWindowThreadProcessId(
::GetForegroundWindow(),NULL),
GetCurrentThreadId(),TRUE);MessageBox("sdosn"....);
//Detach the attached thread
AttachThreadInput(
GetWindowThreadProcessId(
::GetForegroundWindow(),NULL),
GetCurrentThreadId(),FALSE);Yes, this worked.. Thank you. If you dont mind, Can you explain why it was earlier failing with out the code and what this code does.
-
Yes, this worked.. Thank you. If you dont mind, Can you explain why it was earlier failing with out the code and what this code does.
Did you read the link I gave you yesterday? Actually in windows XP or later only a thread that own the current active foreground window has the privilege to set another window in foreground. So i guess when you create another process, your application loose the foreground window property
-
Did you read the link I gave you yesterday? Actually in windows XP or later only a thread that own the current active foreground window has the privilege to set another window in foreground. So i guess when you create another process, your application loose the foreground window property
Hi Naveen, This solution is working fine on regular OS (vista, XP) but it is failing on Windows PE environment. Any other to way get the focus? Thanks, Ram