MFC Dialog application
-
Dear All, Is there any way to create global objects to all the classes in the MFC dialog based application ? I want to use the object of one class from the other class, but I want to create the object only once. The object created for each class should be a singleton object. Please help me. Thanks in advance.
And what is your trouble about? You may use static members or (as you already are aware) the singleton design pattern. BTW: the (in)famous
theApp
object is a (wizard created) sample of a globalMFC
object. :)If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke
[My articles] -
Dear All, Is there any way to create global objects to all the classes in the MFC dialog based application ? I want to use the object of one class from the other class, but I want to create the object only once. The object created for each class should be a singleton object. Please help me. Thanks in advance.
Hi Bhanu, It's not clear from your question as to what exactly do you want. May be you tell what exactly is your problem and I'm sure people over here will be suggest you the best way to go about solving it.
It is a crappy thing, but it's life -^ Carlo Pallini
-
Dear All, Is there any way to create global objects to all the classes in the MFC dialog based application ? I want to use the object of one class from the other class, but I want to create the object only once. The object created for each class should be a singleton object. Please help me. Thanks in advance.
bhanu_8509 wrote:
Is there any way to create global objects
Yes
bhanu_8509 wrote:
The object created for each class should be a singleton object.
Yes, that is a way to create a global object. However the Singleton pattern is well known to be overused/abused. Prefer other patterns such as MVC and Factory creational patterns.
led mike
-
Hi Bhanu, It's not clear from your question as to what exactly do you want. May be you tell what exactly is your problem and I'm sure people over here will be suggest you the best way to go about solving it.
It is a crappy thing, but it's life -^ Carlo Pallini
Rajesh R Subramanian wrote:
I'm sure people over here
So true: did you notice today we have the 'bestest' [^]? :-D
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke
[My articles] -
bhanu_8509 wrote:
Is there any way to create global objects
Yes
bhanu_8509 wrote:
The object created for each class should be a singleton object.
Yes, that is a way to create a global object. However the Singleton pattern is well known to be overused/abused. Prefer other patterns such as MVC and Factory creational patterns.
led mike
led mike wrote:
Prefer other patterns such as MVC and Factory creational patterns.
Even better, prefer KISS pattern[^] and avoid design patterns altogether.
-
led mike wrote:
Prefer other patterns such as MVC and Factory creational patterns.
Even better, prefer KISS pattern[^] and avoid design patterns altogether.
Surely you're joking Mr.Feynman Trifunovic! :-D
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke
[My articles] -
And what is your trouble about? You may use static members or (as you already are aware) the singleton design pattern. BTW: the (in)famous
theApp
object is a (wizard created) sample of a globalMFC
object. :)If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke
[My articles]My exact problem is that, I am using four dialog in my MFC application. I want to open the a dialog from another dialog. I am using OnCancel() for closing the current dialog and use DoModal() to open the other dialog. If I do like this for more no. of times then I got assertion and I found that this happens due to memory overflow due to the recursive call of DoModal(). I want to create global (single) objects for all classes and using those objects I need to hide the window and show the window instead of using OnCancel and DoModal. But I am not so experienced in defining global objects and static objects. Please help me with some samples. P.S : I dont want to use Property sheet or Tabbed dialogs or MDI. Thanks in advance
-
My exact problem is that, I am using four dialog in my MFC application. I want to open the a dialog from another dialog. I am using OnCancel() for closing the current dialog and use DoModal() to open the other dialog. If I do like this for more no. of times then I got assertion and I found that this happens due to memory overflow due to the recursive call of DoModal(). I want to create global (single) objects for all classes and using those objects I need to hide the window and show the window instead of using OnCancel and DoModal. But I am not so experienced in defining global objects and static objects. Please help me with some samples. P.S : I dont want to use Property sheet or Tabbed dialogs or MDI. Thanks in advance
bhanu_8509 wrote:
I want to open the a dialog from another dialog.
This may be easily done using modal dialog boxes (i. e.
DoModal()
), all that you need is the proper communication of each dialog with the common parent window (see this nice toxcct's article about [^]). :)If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke
[My articles] -
Rajesh R Subramanian wrote:
I'm sure people over here
So true: did you notice today we have the 'bestest' [^]? :-D
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke
[My articles]:laugh: Thanks for the funniestest link. :)
It is a crappy thing, but it's life -^ Carlo Pallini
-
:laugh: Thanks for the funniestest link. :)
It is a crappy thing, but it's life -^ Carlo Pallini
Iain is indeed fantastic! (or 'The fantastestic' ?!?!) :)
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke
[My articles]