Messagebox
-
hi every one ,
UINT scaningFile(LPVOID lpvoid)
{
CmovProgress *parent = static_cast <CmovProgress *>(lpvoid);
CRepair_Pana Repair;
h_parentWnd = parent->GetSafeHwnd();
closefile = TRUE;
Repair.RepairMov(g_sourcePathofReferencefile,parent->GetSafeHwnd());InterlockedExchange (&bexecution, FALSE); SetEvent(g\_hWorkEvent); parent->PostMessage(WM\_DESTROY, 0 , 0); return 0;
}
this my thread from here am calling the core class member function Repair(CString sz_path,HWND h_wnd) in this i have one more sub function. when am trying to display message box in Repair function with handle
::MessageBox(h_wnd,_T("Please select a healthy movie file "),_T("Information"),MB_ICONINFORMATION);
it coming Active state but same thing which i do for the sub function saving (HWND h_wnd) it coming in inactive state this not getting close on clicking one time its take two to three click to get close Help out of this ..... Best Regards SARFARAZ
-
hi every one ,
UINT scaningFile(LPVOID lpvoid)
{
CmovProgress *parent = static_cast <CmovProgress *>(lpvoid);
CRepair_Pana Repair;
h_parentWnd = parent->GetSafeHwnd();
closefile = TRUE;
Repair.RepairMov(g_sourcePathofReferencefile,parent->GetSafeHwnd());InterlockedExchange (&bexecution, FALSE); SetEvent(g\_hWorkEvent); parent->PostMessage(WM\_DESTROY, 0 , 0); return 0;
}
this my thread from here am calling the core class member function Repair(CString sz_path,HWND h_wnd) in this i have one more sub function. when am trying to display message box in Repair function with handle
::MessageBox(h_wnd,_T("Please select a healthy movie file "),_T("Information"),MB_ICONINFORMATION);
it coming Active state but same thing which i do for the sub function saving (HWND h_wnd) it coming in inactive state this not getting close on clicking one time its take two to three click to get close Help out of this ..... Best Regards SARFARAZ
Why is the owner (the first parameter of
::MessageBox(..)
) important and may not beNULL
? :)They sought it with thimbles, they sought it with care; They pursued it with forks and hope; They threatened its life with a railway-share; They charmed it with smiles and soap. :)
-
hi every one ,
UINT scaningFile(LPVOID lpvoid)
{
CmovProgress *parent = static_cast <CmovProgress *>(lpvoid);
CRepair_Pana Repair;
h_parentWnd = parent->GetSafeHwnd();
closefile = TRUE;
Repair.RepairMov(g_sourcePathofReferencefile,parent->GetSafeHwnd());InterlockedExchange (&bexecution, FALSE); SetEvent(g\_hWorkEvent); parent->PostMessage(WM\_DESTROY, 0 , 0); return 0;
}
this my thread from here am calling the core class member function Repair(CString sz_path,HWND h_wnd) in this i have one more sub function. when am trying to display message box in Repair function with handle
::MessageBox(h_wnd,_T("Please select a healthy movie file "),_T("Information"),MB_ICONINFORMATION);
it coming Active state but same thing which i do for the sub function saving (HWND h_wnd) it coming in inactive state this not getting close on clicking one time its take two to three click to get close Help out of this ..... Best Regards SARFARAZ
Accessing gui functions from more than one thread is not a good practice. A gui element (window/control) belongs to a process, and to a thread and a module inside that process. What happens in your case is that you have main gui with its message loop on your main thread, and your messagebox function starts another gui loop on the other thread and god knows what happens with focus management in this case, not to mention that a messagebox is meant to be modal and in your case it isn't! You should ask the main (gui) thread to manipulate the gui for you by placing a job in its message queue and waiting for that job to finish. In windows you can do that by sending a message for example to your main window with WM_USER+XXX message. The main thread in your main window can handle the message and pop up a messagebox on the main thread. (Note: SendMessage() puts a message to the message queue of the thread of the window and block the execution of the current thread until the other (gui) thread executes the message. PostMessage() just places the message in the queue of the other thread and returns immediately.) You can write a multithreaded MessageBox() function for yourself that can be called from any threads and does the thing I described above. For longer gui tasks that must be performed from the middle of your worker thread code you should either use PostMessage() with a WM_USER+XXX message that brings up a modal dialog on the gui thread to do the job (and returns from the WM_USER+XXX message only after this), or if you can not perform the gui task immediately where you handle the WM_USER+XXX message then do this: Use PostMessage() to send the job with its parameters to your gui thread to its main window, there you can do the gui related stuff and after it you can send the results to the worker thread somehow - for example by declaring a blocking message queue implementation in your worker thread. While the gui is working the worker thread can block on the blocking message queue waiting for the result of the gui task. Before you start putting in some complicated inter-thread interactions to you program you should consider doing the gui job, and starting the thread only after this with ready-made parameters! EDIT: You are parenting two popup windows that belong to different threads. This is already stinking, never seen such and wouldn't be surprised if that would be illegal. Use always one thread to create and manipulate gui objects! EDIT: Popping up a messagebox from a thread at a random point is also
-
hi every one ,
UINT scaningFile(LPVOID lpvoid)
{
CmovProgress *parent = static_cast <CmovProgress *>(lpvoid);
CRepair_Pana Repair;
h_parentWnd = parent->GetSafeHwnd();
closefile = TRUE;
Repair.RepairMov(g_sourcePathofReferencefile,parent->GetSafeHwnd());InterlockedExchange (&bexecution, FALSE); SetEvent(g\_hWorkEvent); parent->PostMessage(WM\_DESTROY, 0 , 0); return 0;
}
this my thread from here am calling the core class member function Repair(CString sz_path,HWND h_wnd) in this i have one more sub function. when am trying to display message box in Repair function with handle
::MessageBox(h_wnd,_T("Please select a healthy movie file "),_T("Information"),MB_ICONINFORMATION);
it coming Active state but same thing which i do for the sub function saving (HWND h_wnd) it coming in inactive state this not getting close on clicking one time its take two to three click to get close Help out of this ..... Best Regards SARFARAZ
Another sidenote if you are using MFC: If you create gui elements (windows, etc..) from another thread its a problem because MFC installs hooks on newly created gui stuff and registers this-and-that to its internal structures that are not thread safe and you can cause all kind of diseases!
-
Accessing gui functions from more than one thread is not a good practice. A gui element (window/control) belongs to a process, and to a thread and a module inside that process. What happens in your case is that you have main gui with its message loop on your main thread, and your messagebox function starts another gui loop on the other thread and god knows what happens with focus management in this case, not to mention that a messagebox is meant to be modal and in your case it isn't! You should ask the main (gui) thread to manipulate the gui for you by placing a job in its message queue and waiting for that job to finish. In windows you can do that by sending a message for example to your main window with WM_USER+XXX message. The main thread in your main window can handle the message and pop up a messagebox on the main thread. (Note: SendMessage() puts a message to the message queue of the thread of the window and block the execution of the current thread until the other (gui) thread executes the message. PostMessage() just places the message in the queue of the other thread and returns immediately.) You can write a multithreaded MessageBox() function for yourself that can be called from any threads and does the thing I described above. For longer gui tasks that must be performed from the middle of your worker thread code you should either use PostMessage() with a WM_USER+XXX message that brings up a modal dialog on the gui thread to do the job (and returns from the WM_USER+XXX message only after this), or if you can not perform the gui task immediately where you handle the WM_USER+XXX message then do this: Use PostMessage() to send the job with its parameters to your gui thread to its main window, there you can do the gui related stuff and after it you can send the results to the worker thread somehow - for example by declaring a blocking message queue implementation in your worker thread. While the gui is working the worker thread can block on the blocking message queue waiting for the result of the gui task. Before you start putting in some complicated inter-thread interactions to you program you should consider doing the gui job, and starting the thread only after this with ready-made parameters! EDIT: You are parenting two popup windows that belong to different threads. This is already stinking, never seen such and wouldn't be surprised if that would be illegal. Use always one thread to create and manipulate gui objects! EDIT: Popping up a messagebox from a thread at a random point is also
hi , am very new to MFC . what i actually did ,i want explain you . see i have different class UI cprogress here i am trying to update the progress bar according to some work is going on in back ground . this i did by creating thread in Cprogress class itself.in cprogress class m calling the core repair class, in repair class am sending the user define message for updating the progress ctl.when i want to cancel it am suspending the thread and trying to display the massageBox its appearing in inactive form it wont get exit on 1 click.the cancel event is in cprogress class it self.am used the postmessage(wm_destroy,0,0) to destroy the all the controls
-
hi , am very new to MFC . what i actually did ,i want explain you . see i have different class UI cprogress here i am trying to update the progress bar according to some work is going on in back ground . this i did by creating thread in Cprogress class itself.in cprogress class m calling the core repair class, in repair class am sending the user define message for updating the progress ctl.when i want to cancel it am suspending the thread and trying to display the massageBox its appearing in inactive form it wont get exit on 1 click.the cancel event is in cprogress class it self.am used the postmessage(wm_destroy,0,0) to destroy the all the controls
This is how you have to implement some kind of parallel task on a thread with progressbar and cancel button: You setup the thread and start it to do its work. The worker thread posts progress updates to your gui by sending WM_USER+XXX message and an int parameter that is the progress, you should use PostMessage() and not SendMessage() to prevent your thread from waiting for your window to process the WM_USER+XXX message that sets the state of the progressbar. If you want to cancel the task from your gui thread then you should set a cancel flag for your worker thread and then you should poll this flag from your worker thread and stop doing the work if its set. Before exiting your worker thread you should send a WM_USER+YYY message to the gui thread indicating that the work has been cancelled.
-
This is how you have to implement some kind of parallel task on a thread with progressbar and cancel button: You setup the thread and start it to do its work. The worker thread posts progress updates to your gui by sending WM_USER+XXX message and an int parameter that is the progress, you should use PostMessage() and not SendMessage() to prevent your thread from waiting for your window to process the WM_USER+XXX message that sets the state of the progressbar. If you want to cancel the task from your gui thread then you should set a cancel flag for your worker thread and then you should poll this flag from your worker thread and stop doing the work if its set. Before exiting your worker thread you should send a WM_USER+YYY message to the gui thread indicating that the work has been cancelled.
same thing i did but the problem is with my massagebox m_Thd->SuspendThread(); if(::MessageBox(h_parentWnd,_T("Do you want to stop scanning process?"), _T("Confirm"), MB_ICONQUESTION|MB_YESNO) == IDYES) { //MessageBox() closefile = FALSE; m_Thd->ResumeThread(); InterlockedExchange (&bexecution, 0); Movfileisvalid = FALSE; successoffile = FALSE; //bexecution = FALSE; } //else m_Thd->ResumeThread(); i place the massage box in if(condition) this massage box getting inactive state.once i click the cancel the thread will suspended state if its true then i have flag and resume thread to release the memory and to finish the thread .every thing is working fine but the problem is with the message box not getting close with one click i dont know what do please help me out
-
same thing i did but the problem is with my massagebox m_Thd->SuspendThread(); if(::MessageBox(h_parentWnd,_T("Do you want to stop scanning process?"), _T("Confirm"), MB_ICONQUESTION|MB_YESNO) == IDYES) { //MessageBox() closefile = FALSE; m_Thd->ResumeThread(); InterlockedExchange (&bexecution, 0); Movfileisvalid = FALSE; successoffile = FALSE; //bexecution = FALSE; } //else m_Thd->ResumeThread(); i place the massage box in if(condition) this massage box getting inactive state.once i click the cancel the thread will suspended state if its true then i have flag and resume thread to release the memory and to finish the thread .every thing is working fine but the problem is with the message box not getting close with one click i dont know what do please help me out
Well, if you did what I recommended then I dont understand why is your code full of with suspendthread and resumethread, moreover this code isn't enough for us to point out whats wrong with your code, we need the surroundings of this messagebox code plus the codepiece from the thread that triggers this messagebox. If you have a modal messagebox in your program implemented correctly then it can become inactive only if the activation goes to the window of another application.