|
Hi Alok
How are you?I think you are busy.
ThatsAlok wrote: hows life dude!
Well near to terrible!
|
|
|
|
|
Hamid. wrote:
Well near to terrible!
he he he! what happen!
"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/codeProject$$>
|
|
|
|
|
Well I want to leave computer and science computer because I could not find a programming job with C++ even secretary.
|
|
|
|
|
hey why so.. you are genius in c++ programming!
"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/codeProject$$>
|
|
|
|
|
Well I dont know it was a joke or other thing because I dont think Im genius in c++ or even for work with computer if its true why I could'nt find any work,in fact companys dont want to use of c++ they want c# or Delphi for their works except this problem they like to write programs like accountancy or warehousing if someone tells to them that I wrote a program like media player for play video formats they answer is very simple with two words:well,next,but I think you are lucky first you and your people are good programmer second your country is good for programmer.
|
|
|
|
|
See here.
"Normal is getting dressed in clothes that you buy for work and driving through traffic in a car that you are still paying for, in order to get to the job you need to pay for the clothes and the car and the house you leave vacant all day so you can afford to live in it." - Ellen Goodman
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
I am just getting to grips with MFC. I have a basic question I can't quite get the code right.
My application consists of several dialog boxes and a property sheet. I am using WIN XP and Visual Studio 2003
On one of the dialog boxes I have a spare button, say, BUTTON1
When I click on this button, I want to send a Ctrl 1 to the application, that is, I want to emulate a condition, as if a Ctrl 1 has been entered on the keyboard, (but not entered via the keyboard keys, by clicking this button).
How do I do this?
Is it a matter of sending a message from the button function, saying here is Ctrl 1 but how do you code that?
Thanks to anyone who can help
|
|
|
|
|
doorprize wrote: How do I do this?
Have you tried keybd_event() ?
"Normal is getting dressed in clothes that you buy for work and driving through traffic in a car that you are still paying for, in order to get to the job you need to pay for the clothes and the car and the house you leave vacant all day so you can afford to live in it." - Ellen Goodman
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
How about using SendMessage to send the WM_COMMAND message with the ID of the button to the button's parent window, or even better, invoke the handler with a simple function call.
Steve
|
|
|
|
|
doorprize wrote: Is it a matter of sending a message from the button function, saying here is Ctrl 1 but how do you code that?
you could you SendInput api
"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/codeProject$$>
|
|
|
|
|
My thanks to the guys who found the time to help me with this. It led me on a search to look at the ways this could be done. I was thinking C with something like, putchar(c), shows you how little I know about MFC, but to answer my own question, Paul DiLascia has written a great example of using SendInput which others might be interested in. It can be found at:
http://msdn2.microsoft.com/en-us/magazine/cc163867.aspx
|
|
|
|
|
Hello everyone,
The space in string should use heap address memory space, not stack, right? But through debugging, for example,
string str = "hello";
why I can not see the invocation of new operator? Anyone could point out where STL string class allocates space on heap and using which function to allocate please (any other approach other than using new to allocate space on heap?)?
thanks in advance,
George
|
|
|
|
|
Most implementations of std::string have a smallish stack allocated buffer which is used for strings small enough to fit into it. Try assigning a much longer string and see what happens.
<blockquote class="FQ"><div class="FQA">George_George wrote:</div>Anyone could point out where STL string class allocates space on heap</blockquote>
Its done through the allocator. By default for a std::string this will be
allocator<char>
In my version of Visual Studio the actual call to new is around line 44 in the header file "xmemory"
|
|
|
|
|
Hi Josh,
I doubt your below comments. If the space is allocated on stack,
1. How do you deal with global object instance? There is no global stack or something, right?
2. How do you pass one string object instance from one function to another -- safely to ensure address space is valid?
Josh Gray wrote: Most implementations of std::string have a smallish stack
regards,
George
|
|
|
|
|
Hello George,
Im not sure I understand your questions
<blockquote class="FQ"><div class="FQA">George_George wrote:</div>1. How do you deal with global object instance? There is no global stack or something, right?</blockquote>
There is only one stack, you can consider it a global stack I guess
<blockquote class="FQ"><div class="FQA">George_George wrote:</div>2. How do you pass one string object instance from one function to another -- safely to ensure address space is valid?</blockquote>
Its either passed by value in which case the assignment operator of the destination string is invoked, allocating memory if nessasary or its passed by reference in which case the underlying char array is not copied
Think of it like this
class string
{
public:
void assign(char* str)
{
if(strlen(str) < 15)
{
//small string will fit in array on stack
strcpy(smallArray, str, strlen(str));
}
else
{
//to big for stack array so allocate space on heap
strPointer = new char[strlen(str)+1];
strcpy(strPointer, str, strlen(str));
}
}
private:
char smallArray[16];
char* strPointer;
};
|
|
|
|
|
Hi Josh,
Thanks for so much information. Suppose in your code for class string, there are two functions, foo and goo, foo invokes goo. Then,
1. In goo, it allocates a string, small. In your point, it should be on the stack on function goo, right?
2. Goo returns the string by reference to foo;
3. Then foo will refer to some space in goo function stack, which is unwound when goo returns.
Is it safe?
BTW:
Josh Gray wrote: There is only one stack, you can consider it a global stack I guess
I mean the function call stack. You mean there is another global stack? Intereted in that, do you have any recommended links for the memory space?
regards,
George
|
|
|
|
|
There is only one stack. It isued for storing objects as well as holding various memory addresses required for implementing function calls. The stack is a single FILO (first in, last out) data structure.
If you do this
void foo()
{
string& str = goo();
}
string& goo()
{
string myString("George is cool");
return myString;
}
it will fail (some compilers will give a warning)
The reason is that when goo() returns the stack pointer goes back to where it was before the call to goo and anything allocated on the stack by goo will be gone. This will also be true even if you assign a long string and the string class puts it on the heap, the reason is that myString is on the stack and its pointer to the heap will be lost.
|
|
|
|
|
Thanks Josh,
I find the warning of your code in Visual Studio 2008,
warning C4172: returning address of local variable or temporary
But what makes me confused is, as you mentioned if the content is larger than 16 bytes, heap should be used to allocate, right?
But why if I increase the length of thecontent, the same warning exists? My code,
#include <string>
using namespace std;
string& goo()
{
string myString("George is cool 111111111111111111111 11111111111111111111111111111111111");
return myString;
}
void foo()
{
string& str = goo();
}
regards,
George
|
|
|
|
|
You get the warning because myString is on the stack. If it is internally using the heao to store something it doesnt matter. When the method returns myString is lost and with it the pointer to the memory on the heap
You could try
void foo()
{
string myString;
goo(myString);
}
void goo(string& str)
{
str = "George is cool";
}
|
|
|
|
|
Thanks Josh,
Got your idea. My bad before.
regards,
George
|
|
|
|
|
George_George wrote: 1. In goo, it allocates a string, small. In your point, it should be on the stack on function goo, right?
The allocated memory is either going to be from the heap or from the stack.
George_George wrote: Is it safe?
char *goo1( void )
{
char *s = new char[5];
return s;
}
char *goo2( void )
{
char s[5];
return s;
}
string s1 = goo1();
string s2 = goo2();
"Normal is getting dressed in clothes that you buy for work and driving through traffic in a car that you are still paying for, in order to get to the job you need to pay for the clothes and the car and the house you leave vacant all day so you can afford to live in it." - Ellen Goodman
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
Thanks DavidCrow,
My question is answered.
regards,
George
|
|
|
|
|
From my application , I need to load the contents of a reg file programmatically .
I have tried to use Shellexecute supplying the filepath to the reg file however it still prompts me by asking if i need to insert the file into the registry.
I would want to do this silently as the regedit /s option does it silently.
thanks
Engineering is the effort !
|
|
|
|
|
Why not just shellexecute the command you mentioned, "regedit /s file.reg"?
|
|
|
|
|
thats the nice tip i must say!
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
"If it were machines, the pair_programming seem to work, but for humans it is pair_crackdown that seems to work! " - Nisamudheen
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
|
|
|
|