im using visual studio 2010.im new to this.i have a button and a text box. i want to enter a string in the text box.eg:"hello". and if i click the button it should count the number of characters in the string and return the value..eg: in this case "hello" ,when i click the button it should count each letter and display the value "5"(string "hello" contains 5 characters).can any1 help me by sending the exact code?
If it's blinking when you set the text to the same thing over and over, use AfxSetWindowText(). It checks to see what the current text is and only does the SetWindowText if the text is different than the current text.
I'd like to have a piece of code executed upon definite end of a program. atexit() is not appropriate because there may be some code executed when destructing static objects and this function does things beforehand.
#include "..."class dummy
...code here is executed before main()
...code here is executed after main()
void main( void )
...do some stuff
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"You can easily judge the character of a man by how he treats those who can do nothing for him." - James D. Miles
Thanks for all replies. Anyway, the solution requires quite tricky programming.
Heng Xiangzhong wrote:
for example, i want execute a piece of code behind the all of objects' destruct function is invoked.
...and is right.
I would say it looks much more difficult than using simple atexit() function and I wonder why. Probably it belonged to early C standard libraries and no one invented anything better at C++ times.
I'm not sure whether dll is a solution because the same question remains: if I'd like to execute some code after all static objects in dll are disposed, I'd come to the same point of interest.
Let met think.
If you don't think it is complex, hook is a good solution for this.
You can hook the ExitProcess API in win32 by inline, IAT or something you can do.
Because a process exits in windows through invoke the ExitProcess by itself, so after CRT lib destructs all the objects,
it will invoke ExitProcess, at that time, the control flow will give you a chance to execute your code.
If you don't know how to complete it, I can give a piece of code that i wrote before.
I set break point, and I found if I use commented statements, compiler popups exception.
But I think both commented statements ,and non comment statements
are same.both use constructor to construct a temporary object.
I am testing the constructor call with the code below:
A(int n = 0)
A(const A& a)
A a(2), b(1);
const A c(a);
const A &d = c;
const A e = b; //Note 1
b = d; //Note 2: I am confused here
Everything is OK with me.
But there is one point that I cannot understand is that: At the line "b = d" (Note 2), why the copy constructor is not called while at the line "const A e = b" (Note 2) the constructor is called?
I expect that at line Note 2, the copy constructor will be called to copy the value of "c" (referenced by "d") to "b", but it doesn't happen.