|
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
|
|
|
|
|
map RectMap; <- error
typedef unsigned key_type; <- any type you want
std::map<key_type, SRect> RectMap; <- OK
SRect sr = {iX, iY, iW, iH}; <- should work
RectMap[iID] = sr;
OR
RectMap[iID] = {iX, iY, iW, iH}; <- should work
Only write something like RectMap[iID]->iX if you are storing pointers to type sRect in the map; which would be bad and stuped unless you have a really good reason for doing so.
If you are storing pointers ( std::map<key_type, SRect*> ) in the map, then you will need to write a method to free the memory pointed to by all those elements before you allow the map to be destroyed. If you are storing the actual data instead ( std::map<key_type, SRect> ), then the clean up will be automatic when the map is destroyed.
To recap:
... BAD ...
std::map<key_type, SRect*> RectMap; <- bad
RectMap[key] = new SRect(iX, iY, iW, iH); <- this is why it is bad
void cleanup_before_destruction() <- and this is why it is bad
{
std::map<key_type, SRect*>::iterator i;
for( i = RectMap.begin(); i != RectMap.end(); ++i )
delete *i;
}
... GOOD ...
std::map<key_type, SRect> RectMap; <- good
SRect sr(iX, iY, iW, iH);
RectMap[key] = sr;
INTP
"Program testing can be used to show the presence of bugs, but never to show their absence."Edsger Dijkstra
|
|
|
|
|
Hi Friends
Please see the following code
<br />
wstring str1 = L"Test";<br />
wchar_t* buffer = new wchar_t[str1.length()+2];<br />
wcscpy(buffer, str1.c_str());<br />
Now here How much bytes extra I need to allocate for buffer for '\0' terminating character?
+2 or +1?
- Vikram S
|
|
|
|
|
You only need one extra element to hold '\0' because you're allocating with type wchar_t which is two bytes in size
-Sarath.
"Great hopes make everything great possible" - Benjamin Franklin
|
|
|
|
|
|
compiler will itself take care of sizeof NULL, you just have to allocate only 1 extra space to wchar_t
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow Never mind - my own stupidity is the source of every "problem" - Mixture
cheers,
Alok Gupta
VC Forum Q&A :- I/ IV
Support CRY- Child Relief and You
|
|
|
|
|
Hi,
I want to create a service which will launch a application which has GUI. I would like this application as a interactive with user. Is there any way by which I can create service.
Thanks
SNI
SNI
|
|
|
|
|
User the CreateProcessAsUser to launch such an application.
Service run in high privilege and so such apps must be launched with the security token of an interactive user.
In Vista interactive services are not allowed.
«_Superman_»
|
|
|
|
|
The CreateService documentation[^] mentions the SERVICE_INTERACTIVE_PROCESS flag for the dwServiceType flag, which seems applicable?
There's also this page[^], which talks about interactive services?
Does that help?
|
|
|
|