dcsimg
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Page 2 of 3 FirstFirst 123 LastLast
Results 16 to 30 of 36

Thread: How to disable/grayed-out the 'X' close button in dialog?

  1. #16
    2kaud's Avatar
    2kaud is offline Super Moderator Power Poster
    Join Date
    Dec 2012
    Location
    England
    Posts
    6,920

    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)

  2. #17
    Join Date
    May 2009
    Location
    Bengaluru, India
    Posts
    435

    Re: How to disable/grayed-out the 'X' close button in dialog?

    Quote Originally Posted by VictorN View Post
    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 .

  3. #18
    Join Date
    May 2009
    Location
    Bengaluru, India
    Posts
    435

    Re: How to disable/grayed-out the 'X' close button in dialog?

    Quote Originally Posted by 2kaud View Post
    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();

  4. #19
    Join Date
    May 2009
    Location
    Bengaluru, India
    Posts
    435

    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.

  5. #20
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    19,562

    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

  6. #21
    GCDEF is offline Elite Member Power Poster
    Join Date
    Nov 2003
    Location
    Florida
    Posts
    12,555

    Re: How to disable/grayed-out the 'X' close button in dialog?

    Quote Originally Posted by vcdebugger View Post
    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.

  7. #22
    Join Date
    May 2009
    Location
    Bengaluru, India
    Posts
    435

    Re: How to disable/grayed-out the 'X' close button in dialog?

    Quote Originally Posted by GCDEF View Post
    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..

  8. #23
    Join Date
    May 2009
    Location
    Bengaluru, India
    Posts
    435

    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

  9. #24
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    19,562

    Re: How to disable/grayed-out the 'X' close button in dialog?

    Quote Originally Posted by vcdebugger View Post
    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

  10. #25
    2kaud's Avatar
    2kaud is offline Super Moderator Power Poster
    Join Date
    Dec 2012
    Location
    England
    Posts
    6,920

    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)

  11. #26
    Join Date
    Nov 2018
    Posts
    23

    Re: How to disable/grayed-out the 'X' close button in dialog?

    Are your separate worker thread(s) directly updating the UI?

  12. #27
    Join Date
    May 2009
    Location
    Bengaluru, India
    Posts
    435

    Re: How to disable/grayed-out the 'X' close button in dialog?

    Quote Originally Posted by salem_c View Post
    Are your separate worker thread(s) directly updating the UI?
    Yes

  13. #28
    Join Date
    Nov 2018
    Posts
    23

    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.

  14. #29
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    19,562

    Re: How to disable/grayed-out the 'X' close button in dialog?

    Quote Originally Posted by vcdebugger View Post
    Quote Originally Posted by salem_c View Post
    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

  15. #30
    Join Date
    May 2009
    Location
    Bengaluru, India
    Posts
    435

    Re: How to disable/grayed-out the 'X' close button in dialog?

    Quote Originally Posted by VictorN View Post
    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!

Page 2 of 3 FirstFirst 123 LastLast

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Windows Mobile Development Center


Click Here to Expand Forum to Full Width




On-Demand Webinars (sponsored)