|
Prakash is talking to me. What is ur problem
You have an apple and me too. We exchange those and We have an apple each.
You have an idea and me too. We exchange those and We have two ideas each.
|
|
|
|
|
i had been reading this thread. i thought PreTranslateMessage() is better. i always use that only. he told anybody using PreTranslateMessage() is pissed. so i replied.
|
|
|
|
|
Aljechin he told anybody using PreTranslateMessage() is pissed.
talk about misinterpretation.
-Prakash
|
|
|
|
|
wow, cool down, i didnt say using pretranslate message is a bad way of using it, Like I said it would all depend on the design of the dialog.
-Prakash
|
|
|
|
|
Yeah, but the "x" button and the system menu close functions don't work then.
Steve
|
|
|
|
|
Exactly! That is what I am talking about and trying to explain, but he is talking something else. Either he is not understanding what we tell or he does not know it or he understands it, but just wants to argue. Leave him there.
Regards,
Rajesh R. Subramanian
You have an apple and me too. We exchange those and We have an apple each.
You have an idea and me too. We exchange those and We have two ideas each.
|
|
|
|
|
Have you ever made a pie before?
-Prakash
|
|
|
|
|
|
Hi Mike,
Is handling the PreTranslateMessage() better or the one which you have given is better? How? My opinion is that when you write code inside the OnCancel() it will modify the functionality of the cancel button (and the close button of the window) too! Which in turn will stop the dialog from closing somehow.. Should another button be added to close then? Is this approach right? I am asking because I am a big fan of you and I need the reason behind your approach in this matter.
Regards,
Rajesh R. Subramanian
You have an apple and me too. We exchange those and We have an apple each.
You have an idea and me too. We exchange those and We have two ideas each.
|
|
|
|
|
In general, the higher-up the call stack that you can make a change, the better. Doing it on OnCancel() is as high up as you can go. The reasoning being, the higher-up layers are less likely to change between versions of MFC (thus breaking your code), and higher-up changes are easier for others to maintain.
PreTranslateMessage() deals with the raw messages, you may perhaps run into weird cases regarding key states, shift states, and so on.
--Mike--
Visual C++ MVP
LINKS~! Ericahist | NEW!! PimpFish | CP SearchBar v3.0 | C++ Forum FAQ
|
|
|
|
|
Hey Michael,
Is there a way to identify how OnCancel message was called? i.e. by clicking on the button or pressing the ESC key.
thanks
-Prakash
|
|
|
|
|
I've never had to do this myself, but if there is a difference, it would be in the WM_COMMAND parameters - you could compare what wParam and lParam are in those two cases, and then you'd know what you check for.
--Mike--
Visual C++ MVP
LINKS~! Ericahist | NEW!! PimpFish | CP SearchBar v3.0 | C++ Forum FAQ
|
|
|
|
|
Michael Dunn wrote: In general, the higher-up the call stack that you can make a change, the better.
Very good. But if it does not just solve the purpose, then I do not think it it is a sin to move a little lower into the stack! I read this same solution in your FAQ also. But it just is not the way to do it.
Doing this will stop the dialog from closing by clicking the cancel button or the X button even. However it may prevent the dialog from closing on 'Escape' button press. But to solve a problem, I do not want to run into other problems.
<bold>How will i ever close the dialog then?</bold> Add another button for it? Huh?
Michael Dunn wrote: you may perhaps run into weird cases regarding key states, shift states, and so on.
Nothing weird. Shift state is readily available at GetKeyState(). I strongly believe that you would edit your FAQ also. Think on it!
Regards,
Rajesh R. Subramanian.
You have an apple and me too. We exchange those and We have an apple each.
You have an idea and me too. We exchange those and We have two ideas each.
-- modified at 2:03 Wednesday 25th January, 2006
|
|
|
|
|
I have read in a couple of places that unions should not be used unless its very essential!
I do not understand why? sometimes I create unions with many struct in it.
Does any one has any idea on why unions should not be prefered ?
-Prakash
|
|
|
|
|
Unions are not "type" safe since the same data element can be represented by two different types.
a programmer traped in a thugs body
|
|
|
|
|
ky_rerun wrote: Unions are not "type" safe since the same data element can be represented by two different types.
Well that is whole purpose of unions, plus there are many other data types which are not type safe.
-Prakash
|
|
|
|
|
ky_rerun wrote: Unions are not "type" safe since the same data element can be represented by two different types.
i guess you have a good point
check here http://www.weirdrealm.com/prog/cppstds.html[^]
it says,
Unions
Avoid unions, as they defeat strong type-checking and are very difficult to verify in a debugger.
-Prakash
|
|
|
|
|
Members of unions cannot have an incomplete type, type void, or function type. Therefore members cannot be an instance of the union but can be pointers to the union type being declared.
A union type declaration is a template only. Memory is not reserved until the variable is declared.
If a union of two types is declared and one value is stored, but the union is accessed with the other type, the results are unreliable. For example, a union of float and int is declared. A float value is stored, but the program later accesses the value as an int. In such a situation, the value would depend on the internal storage of float values. The integer value would not be reliable.
|
|
|
|
|
vallikumar wrote: A union type declaration is a template only. Memory is not reserved until the variable is declared.
? Not sure what you are trying to say.
Memory allocation (actually, setting a new high-water mark for the stack) for all stack variables is deferred until the start of the block they are declared in.
It sounds like you are trying to say that mem alloc is different for unions than for int's, struct's, ...
The size of a union is known at compile time (just like a struct) - it is the size of the largest member.
...cmk
Save the whales - collect the whole set
|
|
|
|
|
I general, the purpose of a union is to save space. Say you're storing data for a fruit and you have 3 types: Apples, Oranges and Pears. The representaion of these three fruits is distinct and a fruit can only be 1 of these types. Consider a struct that embodies this design:
struct Fruit
{
Type m_Type;
Apple m_Apple;
Orange m_Orange;
Pear m_Pear;
};
If we using this to save our fruit data to disc only one of the three types would actually contain valid data - The space occupied by the others is wasted. We can improve on this by using a union.
struct Fruit
{
Type m_Type;
union
{
Apple m_Apple;
Orange m_Orange;
Pear m_Pear;
} m_Data
};
With this format we don't waste as much space - the size of the union m_Data is the size of its largest member and all members occupy the same memory.
As the previous posters indicated - This saving comes at a price - Danger!
Steve
|
|
|
|
|
Stephen Hewitt wrote: This saving comes at a price - Danger!
What Danger!
Jesus Loves <marquee direction="up" height="40" scrolldelay="1" step="1" scrollamount="1" style="background:#aabbcc;border-bottom:thin solid 1px #6699cc">
--Owner Drawn
--Nothing special
--Defeat is temporary but surrender is permanent
--Never say quits
--Jesus is Lord
|
|
|
|
|
Hard to spot casts:
union Voodoo
{
int m_Number;
IUnknown* m_pUnk;
};
Voodoo v;
v.m_Number = 5;
v.m_pUnk->AddRef();
What happens here is effectively something like the following:
reinterpret_cast<IUnknown*>(5)->AddRef();
In fact this is an old "C" trick used to perform casts which are otherwise illegal.
Steve
|
|
|
|
|
|
the other simple method is u can process the items on the fly...
Stephen Hewitt wrote: union { Apple m_Apple; Orange m_Orange; Pear m_Pear; } m_Data
for eg as mentioned above u can use 3 types of fruits....
read the quantity of apples for each vendor eg. v1.apple v2.apple and perform the calculations...then v1.orange,v2.orange...(since u don't need v1.apple again)and do the calculations..in that way u can perform computations and re-use the memory
this is just one specific instance though
hope that helps
|
|
|
|
|
hi everybody
how to use function of CDC::GetCharWidth()HH
thanks in andvance!!
nothing
|
|
|
|