Why does the following code call the same Dialog box twice? <Long>
-
Why does the following code show the Same Dialog Box twice? The code for the Dialog boxes in inside a dll and the call to the CreateCharacter() is called from the main application. The problem is that the application only shows the first dialog box, even though the "Testing" message box does appear. This tells me that the application is call the correct class, but not showing the correct dialog box. Thanks for any help you can give.
#include "StdAfx.h" #include "ExportedFunctionsCVNChar.h" #include "NewChar1.h" #include "NewChar2.h" DLLEXPORT BOOL CreateNewCharacter() { CNewChar1 dlg; CNewChar2 dlg2; int nResult; nResult = dlg.DoModal(); if(nResult == IDOK) { nResult = dlg2.DoModal(); } return TRUE; } ////////////////////////////////////// NewChar1.h /////////////////////////// class CNewChar1 : public CDialog { // Construction public: CNewChar1(CWnd* pParent = NULL); // standard constructor BOOL OnInitDialog(); // Dialog Data //{{AFX_DATA(CNewChar1) enum { IDD = IDD_NEWCHAR1 }; CComboBox m_cClass; CComboBox m_cRace; CString m_strAL; int m_nCha; CString m_strClass; int m_nCon; int m_nDex; int m_nHitPts; int m_nInt; CString m_strName; CString m_strRace; int m_nStr; int m_nWis; //}}AFX_DATA // Overrides // ClassWizard generated virtual function overrides //{{AFX_VIRTUAL(CNewChar1) protected: virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support //}}AFX_VIRTUAL // Implementation protected: // Generated message map functions //{{AFX_MSG(CNewChar1) // NOTE: the ClassWizard will add member functions here //}}AFX_MSG DECLARE_MESSAGE_MAP() }; ////////////////////////////////// NewChar2.h /////////////////////////////// class CNewChar2 : public CDialog { // Construction public: CNewChar2(CWnd* pParent = NULL); // standard constructor BOOL OnInitDialog(); // Dialog Data //{{AFX_DATA(CNewChar2) enum { IDD = IDD_NEWCHAR2 }; CString m_strGender; CString m_strHand; CString m_strDeity; CString m_strEyeColor; CString m_strHairColor; CString m_strHeight; int m_nWeight; //}}AFX_DATA // Overrides // ClassWizard generated virtual function overrides //{{AFX_VIRTUAL(CNewChar2) protected: virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support //}}AFX_VIRTUAL // Implementation protected: // Generated message map functions //{{AFX_MSG(CNewChar2) // NOTE: the ClassWizard will add member functions here //}}AFX_MS
-
Why does the following code show the Same Dialog Box twice? The code for the Dialog boxes in inside a dll and the call to the CreateCharacter() is called from the main application. The problem is that the application only shows the first dialog box, even though the "Testing" message box does appear. This tells me that the application is call the correct class, but not showing the correct dialog box. Thanks for any help you can give.
#include "StdAfx.h" #include "ExportedFunctionsCVNChar.h" #include "NewChar1.h" #include "NewChar2.h" DLLEXPORT BOOL CreateNewCharacter() { CNewChar1 dlg; CNewChar2 dlg2; int nResult; nResult = dlg.DoModal(); if(nResult == IDOK) { nResult = dlg2.DoModal(); } return TRUE; } ////////////////////////////////////// NewChar1.h /////////////////////////// class CNewChar1 : public CDialog { // Construction public: CNewChar1(CWnd* pParent = NULL); // standard constructor BOOL OnInitDialog(); // Dialog Data //{{AFX_DATA(CNewChar1) enum { IDD = IDD_NEWCHAR1 }; CComboBox m_cClass; CComboBox m_cRace; CString m_strAL; int m_nCha; CString m_strClass; int m_nCon; int m_nDex; int m_nHitPts; int m_nInt; CString m_strName; CString m_strRace; int m_nStr; int m_nWis; //}}AFX_DATA // Overrides // ClassWizard generated virtual function overrides //{{AFX_VIRTUAL(CNewChar1) protected: virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support //}}AFX_VIRTUAL // Implementation protected: // Generated message map functions //{{AFX_MSG(CNewChar1) // NOTE: the ClassWizard will add member functions here //}}AFX_MSG DECLARE_MESSAGE_MAP() }; ////////////////////////////////// NewChar2.h /////////////////////////////// class CNewChar2 : public CDialog { // Construction public: CNewChar2(CWnd* pParent = NULL); // standard constructor BOOL OnInitDialog(); // Dialog Data //{{AFX_DATA(CNewChar2) enum { IDD = IDD_NEWCHAR2 }; CString m_strGender; CString m_strHand; CString m_strDeity; CString m_strEyeColor; CString m_strHairColor; CString m_strHeight; int m_nWeight; //}}AFX_DATA // Overrides // ClassWizard generated virtual function overrides //{{AFX_VIRTUAL(CNewChar2) protected: virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support //}}AFX_VIRTUAL // Implementation protected: // Generated message map functions //{{AFX_MSG(CNewChar2) // NOTE: the ClassWizard will add member functions here //}}AFX_MS
It's hard to read so much code, but at a guess, are the two ID's for the resources the same ? Christian No offense, but I don't really want to encourage the creation of another VB developer. - Larry Antram 22 Oct 2002
C# will attract all comers, where VB is for IT Journalists and managers - Michael P Butler 05-12-2002
Again, you can screw up a C/C++ program just as easily as a VB program. OK, maybe not as easily, but it's certainly doable. - Jamie Nordmeyer - 15-Nov-2002 -
Why does the following code show the Same Dialog Box twice? The code for the Dialog boxes in inside a dll and the call to the CreateCharacter() is called from the main application. The problem is that the application only shows the first dialog box, even though the "Testing" message box does appear. This tells me that the application is call the correct class, but not showing the correct dialog box. Thanks for any help you can give.
#include "StdAfx.h" #include "ExportedFunctionsCVNChar.h" #include "NewChar1.h" #include "NewChar2.h" DLLEXPORT BOOL CreateNewCharacter() { CNewChar1 dlg; CNewChar2 dlg2; int nResult; nResult = dlg.DoModal(); if(nResult == IDOK) { nResult = dlg2.DoModal(); } return TRUE; } ////////////////////////////////////// NewChar1.h /////////////////////////// class CNewChar1 : public CDialog { // Construction public: CNewChar1(CWnd* pParent = NULL); // standard constructor BOOL OnInitDialog(); // Dialog Data //{{AFX_DATA(CNewChar1) enum { IDD = IDD_NEWCHAR1 }; CComboBox m_cClass; CComboBox m_cRace; CString m_strAL; int m_nCha; CString m_strClass; int m_nCon; int m_nDex; int m_nHitPts; int m_nInt; CString m_strName; CString m_strRace; int m_nStr; int m_nWis; //}}AFX_DATA // Overrides // ClassWizard generated virtual function overrides //{{AFX_VIRTUAL(CNewChar1) protected: virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support //}}AFX_VIRTUAL // Implementation protected: // Generated message map functions //{{AFX_MSG(CNewChar1) // NOTE: the ClassWizard will add member functions here //}}AFX_MSG DECLARE_MESSAGE_MAP() }; ////////////////////////////////// NewChar2.h /////////////////////////////// class CNewChar2 : public CDialog { // Construction public: CNewChar2(CWnd* pParent = NULL); // standard constructor BOOL OnInitDialog(); // Dialog Data //{{AFX_DATA(CNewChar2) enum { IDD = IDD_NEWCHAR2 }; CString m_strGender; CString m_strHand; CString m_strDeity; CString m_strEyeColor; CString m_strHairColor; CString m_strHeight; int m_nWeight; //}}AFX_DATA // Overrides // ClassWizard generated virtual function overrides //{{AFX_VIRTUAL(CNewChar2) protected: virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support //}}AFX_VIRTUAL // Implementation protected: // Generated message map functions //{{AFX_MSG(CNewChar2) // NOTE: the ClassWizard will add member functions here //}}AFX_MS
-
Sorry for so much code, but I couldn't figure out how to attach the files to my message. :( The two ids IDD_NEWCHAR1 and IDD_NEWCHAR2 are defined in resource.h as 129 and 130 respectively. If someone can point out how to attach the files I would be more than happy to attach the code to make it easier to read. Thanks again for the help, -Eric
-
Why does the following code show the Same Dialog Box twice? The code for the Dialog boxes in inside a dll and the call to the CreateCharacter() is called from the main application. The problem is that the application only shows the first dialog box, even though the "Testing" message box does appear. This tells me that the application is call the correct class, but not showing the correct dialog box. Thanks for any help you can give.
#include "StdAfx.h" #include "ExportedFunctionsCVNChar.h" #include "NewChar1.h" #include "NewChar2.h" DLLEXPORT BOOL CreateNewCharacter() { CNewChar1 dlg; CNewChar2 dlg2; int nResult; nResult = dlg.DoModal(); if(nResult == IDOK) { nResult = dlg2.DoModal(); } return TRUE; } ////////////////////////////////////// NewChar1.h /////////////////////////// class CNewChar1 : public CDialog { // Construction public: CNewChar1(CWnd* pParent = NULL); // standard constructor BOOL OnInitDialog(); // Dialog Data //{{AFX_DATA(CNewChar1) enum { IDD = IDD_NEWCHAR1 }; CComboBox m_cClass; CComboBox m_cRace; CString m_strAL; int m_nCha; CString m_strClass; int m_nCon; int m_nDex; int m_nHitPts; int m_nInt; CString m_strName; CString m_strRace; int m_nStr; int m_nWis; //}}AFX_DATA // Overrides // ClassWizard generated virtual function overrides //{{AFX_VIRTUAL(CNewChar1) protected: virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support //}}AFX_VIRTUAL // Implementation protected: // Generated message map functions //{{AFX_MSG(CNewChar1) // NOTE: the ClassWizard will add member functions here //}}AFX_MSG DECLARE_MESSAGE_MAP() }; ////////////////////////////////// NewChar2.h /////////////////////////////// class CNewChar2 : public CDialog { // Construction public: CNewChar2(CWnd* pParent = NULL); // standard constructor BOOL OnInitDialog(); // Dialog Data //{{AFX_DATA(CNewChar2) enum { IDD = IDD_NEWCHAR2 }; CString m_strGender; CString m_strHand; CString m_strDeity; CString m_strEyeColor; CString m_strHairColor; CString m_strHeight; int m_nWeight; //}}AFX_DATA // Overrides // ClassWizard generated virtual function overrides //{{AFX_VIRTUAL(CNewChar2) protected: virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support //}}AFX_VIRTUAL // Implementation protected: // Generated message map functions //{{AFX_MSG(CNewChar2) // NOTE: the ClassWizard will add member functions here //}}AFX_MS
Firstly, its not possible to attach a file to a message on the CP boards. As a possible solution, how is the DLL that has these dialog loaded? Is it dynamic? If it is, you may have to use the AFX_MANAGE_STATE() macro or the AfxSetResourceHandle() command to make sure that the correct resources are used when the DoModal() call is performed. Check you application that uses the DLL and see whether it has matching dialog resources using the same resource ID values (i.e. 129/130 as mentioned in the other reply). Roger Allen Sonork 100.10016 This is a multiple choice question, choose wisely Why did the hedgehog cross the road? A: To show he had guts? B: To see his flat mate?
-
Firstly, its not possible to attach a file to a message on the CP boards. As a possible solution, how is the DLL that has these dialog loaded? Is it dynamic? If it is, you may have to use the AFX_MANAGE_STATE() macro or the AfxSetResourceHandle() command to make sure that the correct resources are used when the DoModal() call is performed. Check you application that uses the DLL and see whether it has matching dialog resources using the same resource ID values (i.e. 129/130 as mentioned in the other reply). Roger Allen Sonork 100.10016 This is a multiple choice question, choose wisely Why did the hedgehog cross the road? A: To show he had guts? B: To see his flat mate?
Roger, Thanks for the help. The problem was that in the dll I had the resource ID defined as 129 & 130 as I already indicated. In the main application I also had some resource IDs with the same values. I did not realize that the two applications had to have seperate resource IDs. The dll is statically linked to the main application, is this what caused this problem? If I were to dynamically load the dll would I still run into the same issue? Anyways, thanks for the help! I was able to move on in the project again which I was stuck on for over a week. :( Thanks, -Eric
-
Roger, Thanks for the help. The problem was that in the dll I had the resource ID defined as 129 & 130 as I already indicated. In the main application I also had some resource IDs with the same values. I did not realize that the two applications had to have seperate resource IDs. The dll is statically linked to the main application, is this what caused this problem? If I were to dynamically load the dll would I still run into the same issue? Anyways, thanks for the help! I was able to move on in the project again which I was stuck on for over a week. :( Thanks, -Eric
When you link to an MFC extension DLL, its resources are listed in a resource chain that is searched when looking for one. If its not found in the apps resources, each MFC extension DLL is checked in the order added to the chain until a matching resource is found (if available). This is why you were getting the problem as an existing resource already existed in your app with the same ID. Its just a matter of being cautious. Anyway, glad it solved your problem. Roger Allen Sonork 100.10016 This is a multiple choice question, choose wisely Why did the hedgehog cross the road? A: To show he had guts? B: To see his flat mate?