Problems using CDialogEx class that don't occu

2019-05-26 13:37发布

1.- H ello. After searching in a lot of sites and forums all this week I found the point of the problem I was having. The problem is that when I create a New MFC project in Visual C++, if I set the Application type as "Dialog Based" and let the respective dialog class derive from its default CDialogEx, then the problem shows immediately compiling and executing the program without modifying any of the code (I don't know if you could try this in your machine).

2.-The wired behavior is that with the dialog window active, if I click on a free space in the task bar (and even in another not maximized window), then the borders (including the title bar) of the window of the dialog-based applications stays as "focused" (not-grayed), being that clicking on the task bar or in another window that does not cover completely my application window then my application window should kind of lose the focus.

3.-I realize this after a lot of code, because I discovered this behavior using a CFileDialog class, because when I create (DoModal) a CFileDialog instance, then my application window loses the focus (gets "grayed) when the file dialog opens (as should be) but when the file dialog finishes, the borders of my window stays grayed (which is not correct), and it stays that way until I minimize and restore my window, or I switch to another window and return to my window.

4.-I discovered that the problem was in inheriting from the CDialogEx class, because I created a New project from scratch (as I described in paragraph 1), to see if it was me who modified something that made my program behave wrong, and it turns out that the new project behaves as I described in paragraph 2.

5.-The good new is that I tried creating a new project but this time inheriting from CDialog instead of CDialogEx. And for my surprise is that this new program behaves correctly, I mean, the wired behavior described in paragraph 2 is no present in this new project. As I described in paragraph 3, another of my problems was with the file dialog (CFileDialog class), fortunately changing the code of my project to inherit from CDialog, instead of CDialogEx, solved this problem too. I mean, the problem was the CDialogEx class.

6.-I decided to write this question and also provide the information that I discovered because when I was searching I saw much people in different forums having the same problem without getting a solution. I want to mention that I tried all the advises provided in the forums and, as for they, nothing worked for me.

7.-As I said, one solution is to change the inheritance from CDialogEx to CDialog. But my question is if you know something I should do to make my program behave correctly under the CDialogEx class, because I prefer to use the new interfaces and not the old ones. I also want to know if you experiment the same problem as me in your visual studio or not.

I hope my information and your answers are useful to others. Thank you very much for your answers.

0条回答
登录 后发表回答