DoModal not returning.
-
Hi, I have created a 'please wait' dialog which is loaded when a user clicks on a button. A new thread is launched to load the button so the main thread can continue what it is doing. The button code;
CPleaseWait *dlgWait = new CPleaseWait(this); AfxBeginThread(PleaseWaitThread, dlgWait);
Then in the new thread;CPleaseWait dlg = (CPleaseWait*)lpParam; dlg.DoModal(); return 0;
It is very simple code, which I have had working before. The problem is that when called, DoModal never returns, so the dialog doesnt get displayed (it doesnt get as far as InitDialog). The main thread continues running however. If I place a 'return;' directly after the AfxBeginThread() then the dialog DOES display. If I place 'while(1) Sleep(100);' (or any other code) after the AfxBeginThread() then it does not return. I have narrowed the problem down to a particular line (510) within 'dlgcore.cpp'// disable parent (before creating dialog) HWND hWndParent = PreModal(); AfxUnhookWindowCreate(); BOOL bEnableParent = FALSE; if (hWndParent && hWndParent != ::GetDesktopWindow() && ::IsWindowEnabled(hWndParent)) { ::EnableWindow(hWndParent, FALSE); /////// <--- THIS HANGS FOREVER bEnableParent = TRUE; }
Creating a modeless dialog does not fix the problem - Create() does not reurn instead. Does anyone have any ideas as to what the problem could be? Please advise. Thank you! -
Hi, I have created a 'please wait' dialog which is loaded when a user clicks on a button. A new thread is launched to load the button so the main thread can continue what it is doing. The button code;
CPleaseWait *dlgWait = new CPleaseWait(this); AfxBeginThread(PleaseWaitThread, dlgWait);
Then in the new thread;CPleaseWait dlg = (CPleaseWait*)lpParam; dlg.DoModal(); return 0;
It is very simple code, which I have had working before. The problem is that when called, DoModal never returns, so the dialog doesnt get displayed (it doesnt get as far as InitDialog). The main thread continues running however. If I place a 'return;' directly after the AfxBeginThread() then the dialog DOES display. If I place 'while(1) Sleep(100);' (or any other code) after the AfxBeginThread() then it does not return. I have narrowed the problem down to a particular line (510) within 'dlgcore.cpp'// disable parent (before creating dialog) HWND hWndParent = PreModal(); AfxUnhookWindowCreate(); BOOL bEnableParent = FALSE; if (hWndParent && hWndParent != ::GetDesktopWindow() && ::IsWindowEnabled(hWndParent)) { ::EnableWindow(hWndParent, FALSE); /////// <--- THIS HANGS FOREVER bEnableParent = TRUE; }
Creating a modeless dialog does not fix the problem - Create() does not reurn instead. Does anyone have any ideas as to what the problem could be? Please advise. Thank you!You're using a worker thread to create a user interface object? Personally I dont see the need for a thread at all. On Button Click: Disable the main window. Create and show a modeless please wait dialog. Do work. Destroy the modeless please wait dialog. Enable the main window.
-
Hi, I have created a 'please wait' dialog which is loaded when a user clicks on a button. A new thread is launched to load the button so the main thread can continue what it is doing. The button code;
CPleaseWait *dlgWait = new CPleaseWait(this); AfxBeginThread(PleaseWaitThread, dlgWait);
Then in the new thread;CPleaseWait dlg = (CPleaseWait*)lpParam; dlg.DoModal(); return 0;
It is very simple code, which I have had working before. The problem is that when called, DoModal never returns, so the dialog doesnt get displayed (it doesnt get as far as InitDialog). The main thread continues running however. If I place a 'return;' directly after the AfxBeginThread() then the dialog DOES display. If I place 'while(1) Sleep(100);' (or any other code) after the AfxBeginThread() then it does not return. I have narrowed the problem down to a particular line (510) within 'dlgcore.cpp'// disable parent (before creating dialog) HWND hWndParent = PreModal(); AfxUnhookWindowCreate(); BOOL bEnableParent = FALSE; if (hWndParent && hWndParent != ::GetDesktopWindow() && ::IsWindowEnabled(hWndParent)) { ::EnableWindow(hWndParent, FALSE); /////// <--- THIS HANGS FOREVER bEnableParent = TRUE; }
Creating a modeless dialog does not fix the problem - Create() does not reurn instead. Does anyone have any ideas as to what the problem could be? Please advise. Thank you!I think you are mixing the parent between threads, what about having the new CPleaseWait with (NULL) ??
Greetings. -------- M.D.V. If something has a solution... Why do we have to worry about?. If it has no solution... For what reason do we have to worry about? Help me to understand what I'm saying, and I'll explain it better to you “The First Rule of Program Optimization: Don't do it. The Second Rule of Program Optimization (for experts only!): Don't do it yet.” - Michael A. Jackson ;)
-
Hi, I have created a 'please wait' dialog which is loaded when a user clicks on a button. A new thread is launched to load the button so the main thread can continue what it is doing. The button code;
CPleaseWait *dlgWait = new CPleaseWait(this); AfxBeginThread(PleaseWaitThread, dlgWait);
Then in the new thread;CPleaseWait dlg = (CPleaseWait*)lpParam; dlg.DoModal(); return 0;
It is very simple code, which I have had working before. The problem is that when called, DoModal never returns, so the dialog doesnt get displayed (it doesnt get as far as InitDialog). The main thread continues running however. If I place a 'return;' directly after the AfxBeginThread() then the dialog DOES display. If I place 'while(1) Sleep(100);' (or any other code) after the AfxBeginThread() then it does not return. I have narrowed the problem down to a particular line (510) within 'dlgcore.cpp'// disable parent (before creating dialog) HWND hWndParent = PreModal(); AfxUnhookWindowCreate(); BOOL bEnableParent = FALSE; if (hWndParent && hWndParent != ::GetDesktopWindow() && ::IsWindowEnabled(hWndParent)) { ::EnableWindow(hWndParent, FALSE); /////// <--- THIS HANGS FOREVER bEnableParent = TRUE; }
Creating a modeless dialog does not fix the problem - Create() does not reurn instead. Does anyone have any ideas as to what the problem could be? Please advise. Thank you! -
Hi, I have created a 'please wait' dialog which is loaded when a user clicks on a button. A new thread is launched to load the button so the main thread can continue what it is doing. The button code;
CPleaseWait *dlgWait = new CPleaseWait(this); AfxBeginThread(PleaseWaitThread, dlgWait);
Then in the new thread;CPleaseWait dlg = (CPleaseWait*)lpParam; dlg.DoModal(); return 0;
It is very simple code, which I have had working before. The problem is that when called, DoModal never returns, so the dialog doesnt get displayed (it doesnt get as far as InitDialog). The main thread continues running however. If I place a 'return;' directly after the AfxBeginThread() then the dialog DOES display. If I place 'while(1) Sleep(100);' (or any other code) after the AfxBeginThread() then it does not return. I have narrowed the problem down to a particular line (510) within 'dlgcore.cpp'// disable parent (before creating dialog) HWND hWndParent = PreModal(); AfxUnhookWindowCreate(); BOOL bEnableParent = FALSE; if (hWndParent && hWndParent != ::GetDesktopWindow() && ::IsWindowEnabled(hWndParent)) { ::EnableWindow(hWndParent, FALSE); /////// <--- THIS HANGS FOREVER bEnableParent = TRUE; }
Creating a modeless dialog does not fix the problem - Create() does not reurn instead. Does anyone have any ideas as to what the problem could be? Please advise. Thank you!Mr Simple wrote:
CPleaseWait dlg = (CPleaseWait*)lpParam; dlg.DoModal();
This looks odd. Try:
CPleaseWait *dlg = (CPleaseWait *) lpParam;
dlg->DoModal();
"Normal is getting dressed in clothes that you buy for work and driving through traffic in a car that you are still paying for, in order to get to the job you need to pay for the clothes and the car and the house you leave vacant all day so you can afford to live in it." - Ellen Goodman
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
-
Hi, I have created a 'please wait' dialog which is loaded when a user clicks on a button. A new thread is launched to load the button so the main thread can continue what it is doing. The button code;
CPleaseWait *dlgWait = new CPleaseWait(this); AfxBeginThread(PleaseWaitThread, dlgWait);
Then in the new thread;CPleaseWait dlg = (CPleaseWait*)lpParam; dlg.DoModal(); return 0;
It is very simple code, which I have had working before. The problem is that when called, DoModal never returns, so the dialog doesnt get displayed (it doesnt get as far as InitDialog). The main thread continues running however. If I place a 'return;' directly after the AfxBeginThread() then the dialog DOES display. If I place 'while(1) Sleep(100);' (or any other code) after the AfxBeginThread() then it does not return. I have narrowed the problem down to a particular line (510) within 'dlgcore.cpp'// disable parent (before creating dialog) HWND hWndParent = PreModal(); AfxUnhookWindowCreate(); BOOL bEnableParent = FALSE; if (hWndParent && hWndParent != ::GetDesktopWindow() && ::IsWindowEnabled(hWndParent)) { ::EnableWindow(hWndParent, FALSE); /////// <--- THIS HANGS FOREVER bEnableParent = TRUE; }
Creating a modeless dialog does not fix the problem - Create() does not reurn instead. Does anyone have any ideas as to what the problem could be? Please advise. Thank you!Thanks folks. Using "new CPleaseWait(NULL);" didn't fix the problem, oh, and I was using dlg->DoModal (as opposed to .DoModdal) it was a typo as the machine I am coding on isnt networked :-) I ended up using the modeless after disabling the main form, as suggested. I have another question, not too important anymore, but would be handy to know. Inside the InitDialog() I had a new thread which alters the contents of a label to show the search hasnt crashed. It has worked before in the old application (I have just realised that the old problem didnt exist then as it was being used as a splash screen when the app was started, hence no parent). Now, the 'SetWindowText()' to update the label runs once, then doesnt return the second time. I cant look any further into it as no code is available for debugging (other than assembly) meaning it is quicker for me to delete that bit :-) Like i say, its not important now, but any ideas? Thanks for the help everyone, I had been staring at those lines of code for hours!
-
Thanks folks. Using "new CPleaseWait(NULL);" didn't fix the problem, oh, and I was using dlg->DoModal (as opposed to .DoModdal) it was a typo as the machine I am coding on isnt networked :-) I ended up using the modeless after disabling the main form, as suggested. I have another question, not too important anymore, but would be handy to know. Inside the InitDialog() I had a new thread which alters the contents of a label to show the search hasnt crashed. It has worked before in the old application (I have just realised that the old problem didnt exist then as it was being used as a splash screen when the app was started, hence no parent). Now, the 'SetWindowText()' to update the label runs once, then doesnt return the second time. I cant look any further into it as no code is available for debugging (other than assembly) meaning it is quicker for me to delete that bit :-) Like i say, its not important now, but any ideas? Thanks for the help everyone, I had been staring at those lines of code for hours!
Hi, I had problems with something similar in one project. I was using static labels to show variable datas. It worked good sometimes, but not as I wanted. So I changed them with Edits, set the protection to write and erase the border (all in resource editor), then just calling SetWindowText was enough and never failed. BTW, are you erasing the background before sending the message to update screen?
Greetings. -------- M.D.V. If something has a solution... Why do we have to worry about?. If it has no solution... For what reason do we have to worry about? Help me to understand what I'm saying, and I'll explain it better to you “The First Rule of Program Optimization: Don't do it. The Second Rule of Program Optimization (for experts only!): Don't do it yet.” - Michael A. Jackson ;)