-
September 17th, 2019, 08:02 AM
#16
Re: How to disable/grayed-out the 'X' close button in dialog?
If you are handling the modal dialogue close command, then you have an error in logic as Victor says in post #13. Whatever your code is doing for the modal dialogue close command is not correct. You should be able to debug/trace your modal dilogue close code and find the source of the 'crash' during this code.
All advice is offered in good faith only. All my code is tested (unless stated explicitly otherwise) with the latest version of Microsoft Visual Studio (using the supported features of the latest standard) and is offered as examples only - not as production quality. I cannot offer advice regarding any other c/c++ compiler/IDE or incompatibilities with VS. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/ and can be used without reference or acknowledgement. Also note that I only provide advice and guidance via the forums - and not via private messages!
C++17 Compiler: Microsoft VS2019 (16.4.0)
-
September 17th, 2019, 08:04 AM
#17
Re: How to disable/grayed-out the 'X' close button in dialog?
 Originally Posted by VictorN
Sounds like you code is not good enough to allow closing your dialog cleanly.
You just need to fix your code!
If my code was not clean why is it closing smoothly without crashing after the processing of data is completed fully.
But it crashes only If I try to close the dialog window during the processing of data .
-
September 17th, 2019, 08:10 AM
#18
Re: How to disable/grayed-out the 'X' close button in dialog?
 Originally Posted by 2kaud
If you are handling the modal dialogue close command, then you have an error in logic as Victor says in post #13. Whatever your code is doing for the modal dialogue close command is not correct. You should be able to debug/trace your modal dilogue close code and find the source of the 'crash' during this code.
It is going smooth and after the last line ..it is popping up error message about Access violation reading location 0xfffffffc
Code:
CDialogEx::OnClose();
-
September 17th, 2019, 08:12 AM
#19
Re: How to disable/grayed-out the 'X' close button in dialog?
As of now I am managing to "greying" out the close button of dialog box till my processing is completed.Once everything is done/or if intermediate error happens then I am enabling the "close" button so that user can exit the dialog window.
-
September 17th, 2019, 09:35 AM
#20
Re: How to disable/grayed-out the 'X' close button in dialog?
And what about closing the modal dialog using ENTER, ESCAPE, Ctrl+F4?
Victor Nijegorodov
-
September 17th, 2019, 10:38 AM
#21
Re: How to disable/grayed-out the 'X' close button in dialog?
 Originally Posted by vcdebugger
If my code was not clean why is it closing smoothly without crashing after the processing of data is completed fully.
But it crashes only If I try to close the dialog window during the processing of data .
Is your processing in a thread, or just functions inside the dialog?
Disabling the close button isn't very user friendly. It would be better to interrupt your processing when the close button is pressed, then close the dialog.
Your debugger could likely assist you in determining why it is crashing.
-
September 18th, 2019, 07:28 AM
#22
Re: How to disable/grayed-out the 'X' close button in dialog?
 Originally Posted by GCDEF
Is your processing in a thread, or just functions inside the dialog?
Disabling the close button isn't very user friendly. It would be better to interrupt your processing when the close button is pressed, then close the dialog.
Your debugger could likely assist you in determining why it is crashing.
sorry.. I forgot to mention that those processing is happening in a seperate worker thread... I think that is where the problem is. ANy idea how to fix it..
-
September 18th, 2019, 08:08 AM
#23
Re: How to disable/grayed-out the 'X' close button in dialog?
Also that worker thread calls 2 console application s via Shellexecute which do the processing
-
September 18th, 2019, 10:03 AM
#24
Re: How to disable/grayed-out the 'X' close button in dialog?
 Originally Posted by vcdebugger
sorry.. I forgot to mention that those processing is happening in a seperate worker thread... I think that is where the problem is. ANy idea how to fix it..
It is impossible to recommend any way for fixing without knowing the basic architecture of your application and your implementation of inter-threading communication and synchronization.
Victor Nijegorodov
-
September 18th, 2019, 11:35 AM
#25
Re: How to disable/grayed-out the 'X' close button in dialog?
It sounds like your modal dialog close code isn't properly allowing/signalling threads/processes to terminate cleanly - and waiting until they are. But as Victor says in post #24, this is guesswork without knowing much more detail re the application architecture etc - and you should never guess when coding!
All advice is offered in good faith only. All my code is tested (unless stated explicitly otherwise) with the latest version of Microsoft Visual Studio (using the supported features of the latest standard) and is offered as examples only - not as production quality. I cannot offer advice regarding any other c/c++ compiler/IDE or incompatibilities with VS. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/ and can be used without reference or acknowledgement. Also note that I only provide advice and guidance via the forums - and not via private messages!
C++17 Compiler: Microsoft VS2019 (16.4.0)
-
September 18th, 2019, 12:45 PM
#26
Re: How to disable/grayed-out the 'X' close button in dialog?
Are your separate worker thread(s) directly updating the UI?
-
September 18th, 2019, 11:19 PM
#27
Re: How to disable/grayed-out the 'X' close button in dialog?
 Originally Posted by salem_c
Are your separate worker thread(s) directly updating the UI?
Yes
-
September 19th, 2019, 01:03 AM
#28
Re: How to disable/grayed-out the 'X' close button in dialog?
So, the dialog goes away and some worker thread then tries to update some non-existent UI element and promptly dies.
This is generally regarded as being a big no-no.
https://stackoverflow.com/questions/...ws-thread-safe
https://docs.microsoft.com/en-us/cpp...s?view=vs-2019
That it crashes when you close the dialog could just be the tip of a very large iceberg.
You need to create some inter-thread messaging system, where your worker thread sends say a "progress bar 1 = 20%" to the main UI thread, and the main UI thread itself does the update (and can also check that the dialog still exists).
What other multi-thread sins have you committed, just waiting to come back and bite you at some future time? Maybe your worker threads are busy writing into data structures that your main thread is busy reading from.
You need a PLAN (seriously!) before you add threads to existing code. Every shared function with a side-effect and every bit of shared data needs thinking about. You need a properly designed ownership and responsibility model before you even reach for the keyboard to type in some code. If you're not familiar with all this, then you have lots of studying to do.
If you're up to C++11, then https://en.cppreference.com/w/cpp/thread
Otherwise, your platform API, https://docs.microsoft.com/en-us/win...tion-functions
To be honest, if your code is under some kind of source control, and this "add threads" was a recent change, then I'd definitely suggest creating another branch from your last stable single thread version and starting again.
But if the change was months ago, merged with many other unrelated changes, or you have NO source control, then you really do have your work cut out. The rat's nest of race conditions you've created for yourself will be hard to remove completely.
-
September 19th, 2019, 01:19 AM
#29
Re: How to disable/grayed-out the 'X' close button in dialog?
 Originally Posted by vcdebugger
 Originally Posted by salem_c
Are your separate worker thread(s) directly updating the UI?
Yes
It sounds like a bad design... 
You should access your dialog control only from within the main UI-thread this dialog belongs to. Check it out: Using Worker Threads
Victor Nijegorodov
-
September 19th, 2019, 01:45 AM
#30
Re: How to disable/grayed-out the 'X' close button in dialog?
 Originally Posted by VictorN
It sounds like a bad design... 
You should access your dialog control only from within the main UI-thread this dialog belongs to. Check it out: Using Worker Threads
To avoid that I moved my Progresscontrol and Edit box updates from worker thread to my OnTimer() function of the main dialog box but still it was crashing to some other places where CString's were handled( by the other applications called using SHellExecute from the worker thread - for which I dont have control over).
Now I have removed the worker thread itself from my code and doing everything in the main thread of CDialog itself. But the dialog window freezes now when the processing is happening and when the user click on Onclose ( X) button it will respond later but not crashing!
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
On-Demand Webinars (sponsored)
|