|
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 global MFC 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
|
|
|
|
|
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]
|
|
|
|
|
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' [^]?
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]
|
|
|
|
|
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]
|
|
|
|
|
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.
|
|
|
|
|
Surely you're joking Mr.Feynman Trifunovic!
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]
|
|
|
|
|
I'm doing the GUI calculator now in VC++ 6.0.
and i can detect the number when the user click on the number in GUI.
but now i want to add in the function which is can detect the number when user key in with keyboard..
any suggestion?or got any tutorial about it...
i hv go search in google...but mayb my keyword using is not true,cant get the right information...
|
|
|
|
|
If you're doing a small MFC app, try adding the number keys as accelerators in the resource.
Then handle them as if the are menu presses.
If you have the numbers on the screen as buttons, you could probably use the same code.
Iain.
|
|
|
|
|
map PreTranslateMessage function and check for if( pMsg-gt;message == WM_KEYDOWN )
-Sarath.
"Great hopes make everything great possible" - Benjamin Franklin
|
|
|
|
|
Look up OnKeyDown (and OnKeyUp) I think thats the name given to the method in MFC. The actual message is something like WM_KEYDOWN, so look for both.
INTP
"Program testing can be used to show the presence of bugs, but never to show their absence."Edsger Dijkstra
|
|
|
|
|
If the child controls like button has the focus it will not be delivered parent (dialog)
-Sarath.
"Great hopes make everything great possible" - Benjamin Franklin
|
|
|
|
|
Hi guys,
I'm working at a WebServer project that it receives a lot of HTTP requests,Yet these requests are not belong to a family.
Each HTTP request requires deal with a lot of string, e.g."GET /HELLO%20WORLD/ HTTP 1.1", HELLO%20WORLD/ is some info I really need.But then each request might have a lot of different data which has different formats.
So I wanna know is there some good design patterns or architectures to manage these requests?
Any suggestions are welcome.
|
|
|
|
|
Many of the internet releated specifications are managed by the W3C organization[^]. You should probably begin by becoming familiar with the HTTP/1.1 standards[^]. Your probably not going to find a library specifically designed for web server string parsing.
Best Wishes,
-David Delaune
|
|
|
|
|
Hello guys,
I wanna make a map that contains an integer key and a struct as value type.
struct SRect
{
int iX, iY, iW, iH;
};
map<unsigned int=""> RectMap;
This piece of code compiles fine. However, if I want to insert a pair into the map a runtime error occurs.
void MakeParamRect(int iID, int iX, int iY, int iW, int iH)
{
RectMap[iID]->iX = iX;
RectMap[iID]->iY = iY;
RectMap[iID]->iW = iW;
RectMap[iID]->iH = iH;
}
I've also tried it using the insert() function.
RectMap.insert(make_pair(iID, {iX, iY, iW, iH}));
In this case the struct notation with the curly brackets seems to produce the error (compiler says that a semicolon is missing before the first {).
How can I make this code work, or is a struct not a valid value type for a map (it is valid in my opinion)?
Thanks for your help.
|
|
|
|
|
hello
i am not sure you can put a struct into a map.
if i were you i would change the struct into a class with a copy constructor
regards
|
|
|
|
|
You can't use aggregate syntax (that's the curly bracket stuff) anywhere except a struct/array variable initialiser. However, you certainly can put a struct in a map .
Try the code below - it declares and initialises an SRect variable which it then inserts into the map:
SRect sRect = {iX, iY, iW, iH};
RectMap.insert(make_pair(iID, sRect));
|
|
|
|
|
What is your map definition?
is it
map<int, SRect *> RectMap;
or
map<int, SRect> RectMap;
In the first case, you'll have to insert the structure variable into the map as below :
RectMap[0] = new SRect();
or
SRect s;
RectMap[0] = &s;
i.e. before accessing the variable from map, make sure you've inserted it.
And as you're saying RectMap.insert(make_pair(iID, {iX, iY, iW, iH})); gives compiler error, I'm pretty much sure that your map declaration is as :
std::map<int, SRect *> RectMap;
Better this will help you more...
|
|
|
|
|
I've few confusions.
It's possible to store structure as a value inside map.
std::map<int,srect> mymap;
Austrian_Programmer wrote: void MakeParamRect(int iID, int iX, int iY, int iW, int iH)
{
RectMap[iID]->iX = iX;
RectMap[iID]->iY = iY;
RectMap[iID]->iW = iW;
RectMap[iID]->iH = iH;
}
As per your code, you created the map as
std::map<int,srect*> mymap;
Probably you might be accessing an NULL or invalid pointer.
-Sarath.
"Great hopes make everything great possible" - Benjamin Franklin
|
|
|
|
|
I found out that if I just use the struct and not struct pointers as map value type it's working without making any problems. Anyway, I don't understand why.
In the meantime I also found a few code examples using a struct or a class as map value type, but I didn't see any examples using struct pointers.
|
|
|
|
|
I asked you regarding structure pointer as value because in the function you've mentioned using -> operator instead of . (dot) operator to access the members.
-Sarath.
"Great hopes make everything great possible" - Benjamin Franklin
|
|
|
|