How to spawn CDialog by CWinThread?
-
Hi gentlemen, I am newbie to MFC programming and I have a problem creating a dialog on a separate thread from the main application. My situation is: by clicking an icon on a toolbar, a dialog will be prompted and asking for input. As entered the numbers and clicked "OK", these parameters will be passed to the main application to run in a loop and the result will be displayed. Without threading, the displayed result is obstructed by the dialog and applying the InValidateRect function is not satisfactory since the toolbar now becomes invisible. Now I have create a "CSub" class based on CDialog and a "CDialogThread" class based on CWndThread. My question is, how to instruct the dialog to run on the thread, then how to pass the threaded dialog parameter back to the main application? Thank you very much! :)
-
Hi gentlemen, I am newbie to MFC programming and I have a problem creating a dialog on a separate thread from the main application. My situation is: by clicking an icon on a toolbar, a dialog will be prompted and asking for input. As entered the numbers and clicked "OK", these parameters will be passed to the main application to run in a loop and the result will be displayed. Without threading, the displayed result is obstructed by the dialog and applying the InValidateRect function is not satisfactory since the toolbar now becomes invisible. Now I have create a "CSub" class based on CDialog and a "CDialogThread" class based on CWndThread. My question is, how to instruct the dialog to run on the thread, then how to pass the threaded dialog parameter back to the main application? Thank you very much! :)
From what you explained I do not see any reason of introducing a new thread at least as far as the dialog concerns. Without threading, the displayed result is obstructed by the dialog and applying the InValidateRect function is not satisfactory since the toolbar now becomes invisible. This is not so clear. Why does the toolbar become invisible. What's the relationship between the dialog and InvalidateRect?
-- ===== Arman
-
Hi gentlemen, I am newbie to MFC programming and I have a problem creating a dialog on a separate thread from the main application. My situation is: by clicking an icon on a toolbar, a dialog will be prompted and asking for input. As entered the numbers and clicked "OK", these parameters will be passed to the main application to run in a loop and the result will be displayed. Without threading, the displayed result is obstructed by the dialog and applying the InValidateRect function is not satisfactory since the toolbar now becomes invisible. Now I have create a "CSub" class based on CDialog and a "CDialogThread" class based on CWndThread. My question is, how to instruct the dialog to run on the thread, then how to pass the threaded dialog parameter back to the main application? Thank you very much! :)
Dear, You need not take that much pain to accomplish this. If all you need to inform is a count and some other simple parameters, why dont you put them in the APP, and once you got the parameters from the dialog, AfxGetAPP(), update / set variables and then... your task is done... regards, haribabu
-
From what you explained I do not see any reason of introducing a new thread at least as far as the dialog concerns. Without threading, the displayed result is obstructed by the dialog and applying the InValidateRect function is not satisfactory since the toolbar now becomes invisible. This is not so clear. Why does the toolbar become invisible. What's the relationship between the dialog and InvalidateRect?
-- ===== Arman
Hi Arman, Thank you for your reply. The application is a MDI and the dialog is called by a function of the CView class. After the dialog passes the parameters to this function, it runs a loop which preforms a calculation and display results on the childframe window. I tried to use InvalidateRect(NULL,NULL,true) inside the function before the loop but all the icons on the toolbar disappears and only reappears after the loop completes. If use InvalidateRect(m_hWnd,NULL,true) then the dialog only vanish if I clicked "OK" while the dialog is upon the childframe window. If the dialog is partially away from the childframe window, then it remains appear despite I clicked "OK". I was told that creating a separate processing thread for the dialog will solve the problem but I have little idea on multi threading with MFC. Hope you understand and thank you very much! :)
-
Dear, You need not take that much pain to accomplish this. If all you need to inform is a count and some other simple parameters, why dont you put them in the APP, and once you got the parameters from the dialog, AfxGetAPP(), update / set variables and then... your task is done... regards, haribabu