• We’re currently investigating an issue related to the forum theme and styling that is impacting page layout and visual formatting. The problem has been identified, and we are actively working on a resolution. There is no impact to user data or functionality, this is strictly a front-end display issue. We’ll post an update once the fix has been deployed. Thanks for your patience while we get this sorted.

CDialogs failing to show in MSVS6 MFC C++ program

KevinMU1

Senior member
I'm using Microsoft Visual Studio 6, MFC with C++, and having a really weird problem. I am creating a dialog using Create for a modeless dialog, and sometimes the dialog just doesn't show. I can try twice in a row to do the same action, and the first time it may fail to show and the second time it will show fine. It's not a matter of whether or not the dialog is created... it's always created (I can tell b/c it spawns another thread and I can tell it's running). The visible property is checked, so it's not like it's not always calling ShowWindow(SW_SHOW) in MY code... it should be doing it all the time b/c of that property. Perhaps I could insert a ShowWindow statement manually, but I'd like to know if this is a known bug for I create a workaround, or if this is possibly the symptom of some larger problem.

Any thoughts/ideas? Thanks in advance.
 
I always put in ShowWindow() because that little check-box is pretty easy to mess up with when you're designing the dialog. I can't recall any incidents of the dialog not appearing, so I think it's probably your fault 🙂
 
Could there be a problem with a control on the dialog, or any code in your OnInitDialog handler? i.e. the thread is created but window creation / initialization fails? One example of how this happens is if you have a wrong control ID in your code and don't check for GetDlgItem etc. returning NULL.
 
The dialog is pretty dang simple, and like I said it can have the problem and then not within the SAME RUN of the program, so it's not like the box is getting cleared or I'm changing the code.

About the only thing I do relating to the box itself in InitDialog is use SetIcon.

I think it's a bug in the underlying MFC, but that's just my theory.
 
Originally posted by: KevinMU1
I think it's a bug in the underlying MFC, but that's just my theory.
Possible of course, though I've been using MFC heavily for about 6 years now and have never had a dialog problem that wasn't my own fault. Some TRACE statements and ASSERTs might help, and if you have BoundsChecker you might give a BC build a test run.

 
Is BoundsChecker a program that's part of Visual Studio? I'm not familiar with it. Thanks for the tip though, and I will certainly keep trying to figure out what makes the window not appear.
 
If you call CDialog:😱nCancel it calls EndDialog which makes the dialog invisible but doesn't destroy it. Maybe that's the reason, you need to override OnCancel and call DestroyWindow.

Probably not it though, I'm using V5.0 and just learning.

EJ
 
Back
Top