|
Nice explanation, you get a 5.
Regards,
Alvaro
Well done is better than well said. -- Benjamin Franklin
(I actually prefer medium-well.)
|
|
|
|
|
And to only think that 2 years ago I couldn't even spell c++ I really owe it all to CP!
(well deserves some credit too...)
- Nitron
"Those that say a task is impossible shouldn't interrupt the ones who are doing it." - Chinese Proverb
|
|
|
|
|
Now hold on a second.
You said:
int x = 5; // initializes a variable int to value
int* px = &x; // initializes a "pointer to int"
But that's not exactly true.
int x;
int *y = x;
Now y holds the physical address for x - the dereference "&" is contradictory. To dereference, LATER ON, you could say &y. So if you said:
int* y = &x;
You would actually get a compilation error because you're trying to assign a memory location to an integer variable. The & character dereferences a variable and that's why you see variables being passed as parameters to functions like so:
void mod(int &x, int &y)
{ x=x%y return;}
This actually changes the value of the memory location at x without having to return the value at the end of the function.
|
|
|
|
|
wait wait wait...
first, you mis-quoted:
David Southard wrote:
int x = 5; // initializes a variable int to value
int* px = &x; // initializes a "pointer to int"
what I said was
int* px = &x;
------- --
| |
| |- read "Address of x"
|
|- read "a variable 'px' of type 'pointer to int'"
This is in fact different to what you said:
David Southard wrote:
The & character dereferences a variable and that's why you see variables being passed as parameters to functions like so:
void mod(int &x, int &y)
This (int& x) is not a "pointer to int" but is in fact a "reference to int".
Consider the function:
func(CString* pszString, CString& szAnotherString)
{
pszString->Format("A String");
szAnotherString.Format("Some String);
}
note that the "pointer to string" (pszString) requires pointer notation for operations, however the reference to the string (szAnotherString) is just that: a "reference" to (not a copy of) the origional string.
My term "de-referencing" is not to be confused with a "reference to". That is why I am picky where and when I put the * and & modifiers on things. When I declare a pointer to a type, I always put the * modifier at the end of the type. And likewise when I declare a reference. This is different than when I de-reference a pointer or get the "address of" something else. Try this in a console app:
int main(int argc, char* argv[])
{
int x = 5;
printf("\nThe value x initially has the value %d", x);
unsigned long physical_address_of_x = reinterpret_cast<unsigned long>(&x);
int& reference_to_x = x;
int* pointer_to_x = reinterpret_cast<int*>(physical_address_of_x);
printf("\n\nWe are now setting reference_to_x = 12\n");
reference_to_x = 12;
printf("\nThe value x is located at 0x%X and now has the value %d.", physical_address_of_x, x);
printf("\nThe reference to x is located at 0x%X and has the value %d.", &reference_to_x, reference_to_x);
printf("\nThe pointer to x is located at 0x%X and points to location 0x%X.", &pointer_to_x, pointer_to_x);
printf("\nThe pointer to x, when de-referenced yeilds the value %d\n\n", *pointer_to_x);
return 0;
}
I hope that clears things up.
- Nitron
"Those that say a task is impossible shouldn't interrupt the ones who are doing it." - Chinese Proverb
|
|
|
|
|
David Southard wrote:
int x;
int *y = x;
Now y holds the physical address for x - the dereference "&" is contradictory. To dereference, LATER ON, you could say &y. So if you said:
int* y = &x;
You would actually get a compilation error because you're trying to assign a memory location to an integer variable.
BTW, the reverse is true. int* y = &x is valid, int* y = x is not. (Well, as long as you aren't using VB anyway )
- Nitron
"Those that say a task is impossible shouldn't interrupt the ones who are doing it." - Chinese Proverb
|
|
|
|
|
Dear all member,
I read messages on GDI+ and find it interesting, butt I cannot try it out. The reason is that I cannot download 200 MB SDK from Microsoft with my 28.8 KB.
Can anyone help? Please send me a zip file with all the needed file for GDI+ programming.
Many thanks,
|
|
|
|
|
Repeating what I told you before you posted this again, it does not work. There are people who have done this and you can find them with google, but you'll end up back at my articles asking why it won't run smoothly. You really need to get the full SDK on CD from Microsoft. It's something you need anyhow, unless you have VS.NET ( in which case you would not need anything and would not be asking ), or you want to write software targetted at Windows 95. It won't take long to find another API call you wish you could use, but cannot because you need the PSDK.
Christian
No offense, but I don't really want to encourage the creation of another VB developer. - Larry Antram 22 Oct 2002
C# will attract all comers, where VB is for IT Journalists and managers - Michael P Butler 05-12-2002
Again, you can screw up a C/C++ program just as easily as a VB program. OK, maybe not as easily, but it's certainly doable. - Jamie Nordmeyer - 15-Nov-2002
|
|
|
|
|
I got the SDK CD from MS for $US 8.95 shipping included. It took about a week for them to mail it to me.
Why don't you try that?
Jeff Patterson
Programmers speak in Code.
http://www.anti-dmca.org[^]
|
|
|
|
|
Hi,
I just want to change the tooltip text for window close button.I can't find anything in the resource.From where the text is been taken for that?
Regards
Neha
|
|
|
|
|
Majid Shahabfar wrote:
In fact how can I create a file in a folder that I don't have write permission?
How can you drink water from a glass that does not have any water?
Mazy
"And the carpet needs a haircut, and the spotlight looks like a prison break
And the telephone's out of cigarettes, and the balcony is on the make
And the piano has been drinking, the piano has been drinking...not me...not me-Tom Waits
|
|
|
|
|
Im pretty decent when it comes to c++ programming, but im working on my first windows program right now and i cant, for the life of me, figure out how to take what the user enters in an edit box and hold the data in a string. im sure theres a function that does it somewhere, i just dont know it. could someone help me out please?
|
|
|
|
|
There are two, GetWindowText() and GetDlgItemText() . You'll probably find the second one easier. You pass it the handle to the edit's parent window (which is usually a dialog, thus the name of the API) and the ID of the edit control itself, along with a character buffer. The API stores the text in the buffer.
--Mike--
Friday's GoogleFight results: Britney Spears 2,190,000 - Erica Weichers 23
1ClickPicGrabber - Grab & organize pictures from your favorite web pages, with 1 click!
My really out-of-date homepage
Sonork-100.19012 Acid_Helm
|
|
|
|
|
Michael Dunn wrote:
Britney Spears 2,190,000 - Erica Weichers 23
LOL !!! What's GoogleFight ? Did you try Kate Winslet ?
Christian
No offense, but I don't really want to encourage the creation of another VB developer. - Larry Antram 22 Oct 2002
C# will attract all comers, where VB is for IT Journalists and managers - Michael P Butler 05-12-2002
Again, you can screw up a C/C++ program just as easily as a VB program. OK, maybe not as easily, but it's certainly doable. - Jamie Nordmeyer - 15-Nov-2002
|
|
|
|
|
Christian Graus wrote:
LOL !!! What's GoogleFight ? Did you try Kate Winslet ?
It's a humor site where you give it two key words/phrases, and it Googles for them both and reports the # of hits for each one. The one with more hits wins.
This particular fight was inspired by someone saying Britney Spears was hotter than Erica Weichers, which is of course utter bollocks, but the Web doesn't seem to agree.
--Mike--
Friday's GoogleFight results: Britney Spears 2,190,000 - Erica Weichers 23
1ClickPicGrabber - Grab & organize pictures from your favorite web pages, with 1 click!
My really out-of-date homepage
Sonork-100.19012 Acid_Helm
|
|
|
|
|
Michael Dunn wrote:
This particular fight was inspired by someone saying Britney Spears was hotter than Erica Weichers
Who would SAY such a thing ? She's pretty skanky though. My grandmother (1 190 000 results) beats her too.
Christian
No offense, but I don't really want to encourage the creation of another VB developer. - Larry Antram 22 Oct 2002
C# will attract all comers, where VB is for IT Journalists and managers - Michael P Butler 05-12-2002
Again, you can screw up a C/C++ program just as easily as a VB program. OK, maybe not as easily, but it's certainly doable. - Jamie Nordmeyer - 15-Nov-2002
|
|
|
|
|
Christian Graus wrote:
She's pretty skanky though
If you mean Erica, you'd better take it back. <homer hand-position="waving-fist">take it...</homer>
--Mike--
Friday's GoogleFight results: Britney Spears 2,190,000 - Erica Weichers 23
1ClickPicGrabber - Grab & organize pictures from your favorite web pages, with 1 click!
My really out-of-date homepage
Sonork-100.19012 Acid_Helm
|
|
|
|
|
WEll Mike, because it's you, I'm willing to consider that it just wasn't a very good photo, but that's as far as I can go, OK ?
Christian
No offense, but I don't really want to encourage the creation of another VB developer. - Larry Antram 22 Oct 2002
C# will attract all comers, where VB is for IT Journalists and managers - Michael P Butler 05-12-2002
Again, you can screw up a C/C++ program just as easily as a VB program. OK, maybe not as easily, but it's certainly doable. - Jamie Nordmeyer - 15-Nov-2002
|
|
|
|
|
Christian Graus wrote:
My grandmother (1 190 000 results) beats her too.
Lol . Some pictures of her ?
I hurt so bad inside
I wish you could see the world through my eyes
It stays the same
I just wanna laugh again
|
|
|
|
|
That's really cool. Way too many people seem to start with Windows programming without learning any C++ first.
If you're using VC6 then you hit CTRL-W to bring up the class wizard, and in the second tab, you can set variables for a class. There are two options, you can create a variable which holds a string or a number, or a control variable. If you use the former, you end up with a CString ( or an int, etc ) that holds your value. You call UpdateData(FALSE); to populate the variable, and UpdateData(TRUE); to put the variables value into the control. I prefer to create a control, which also means you can hide/move/change it, and then to get the value out you do something like this:
CString sEdit;
m_MyEdit.GetWindowText(sEdit);
And SetWindowText puts the value into the control from the CString.
Christian
No offense, but I don't really want to encourage the creation of another VB developer. - Larry Antram 22 Oct 2002
C# will attract all comers, where VB is for IT Journalists and managers - Michael P Butler 05-12-2002
Again, you can screw up a C/C++ program just as easily as a VB program. OK, maybe not as easily, but it's certainly doable. - Jamie Nordmeyer - 15-Nov-2002
|
|
|
|
|
Now imagine, just for one second, what would have happened if Microsoft had decided to add just a few extra operators to the CEdit class:
CEdit& operator=(const CString& strText);
CEdit& operator=(int nText);
CEdit& operator=(double dText);
operator CString() const;
operator int() const;
operator double() const;
Then we could do things like:
m_editCtrl = "This value";
m_editCtrl = 123;
functionWhichTakesACStringParam(m_editCtrl);
int nValue = m_editCtrl + 10;
Oh well, we can only dream of what could have been. It's just amazing how much easier VB developers could have picked VC++ if Microsoft had really exploited the power of C++ inside MFC.
Regards,
Alvaro
Well done is better than well said. -- Benjamin Franklin
(I actually prefer medium-well.)
|
|
|
|
|
I'd settle for GetWindowText returning the string so you could concatenate operations. What you're suggesting would be so cool as to be unheard of.....
Christian
No offense, but I don't really want to encourage the creation of another VB developer. - Larry Antram 22 Oct 2002
C# will attract all comers, where VB is for IT Journalists and managers - Michael P Butler 05-12-2002
Again, you can screw up a C/C++ program just as easily as a VB program. OK, maybe not as easily, but it's certainly doable. - Jamie Nordmeyer - 15-Nov-2002
|
|
|
|
|
Ahhh, the power of C++. This can easily be accomplished with a simple subclass.
CEditEx& CEditEx::operator =(const CString& str)
{
SetWindowText(str);
return *this;
}
CEditEx& CEditEx::operator =(int nText)
{
CString str;
str.Format(_T("%d"), nText);
SetWindowText(str);
return *this;
}
CEditEx& CEditEx::operator =(double dText)
{
CString str;
str.Format(_T("%0.6f"), dText);
SetWindowText(str);
return *this;
}
CEditEx::operator int() const
{
CString str;
GetWindowText(str);
TCHAR *temp;
return (_tcstol(str, &temp, 10));
}
CEditEx::operator double() const
{
CString str;
GetWindowText(str);
TCHAR *temp;
return (_tcstod(str, &temp));
}
CEditEx::operator CString() const
{
CString str;
GetWindowText(str);
return str;
} I am sure this could be improved (error checking etc.) but you get the idea.
CPUA 0x5041
Sonork 100.11743 Chicken Little
"So it can now be written in stone as a testament to humanities achievments "PJ did Pi at CP"." Colin Davies
Within you lies the power for good - Use it!
|
|
|
|
|
PJ, u 'da man! I've been doing the 'ol GetWindowText() and atof() and this and that forever... I'm gonna implement something like this first thing monday morning... (Have you done an article on it yet?) (hint, hint...)
- Nitron
"Those that say a task is impossible shouldn't interrupt the ones who are doing it." - Chinese Proverb
|
|
|
|
|
Nitron wrote:
Have you done an article on it yet?
No I haven't. I didn't actually think of this until Alvaro and Christian said how cool it would be. And then I thought "why not? sounds simple enough". Maybe Alvaro would be a better candidate to write an article as it was his idea originally.
CPUA 0x5041
Sonork 100.11743 Chicken Little
"So it can now be written in stone as a testament to humanities achievments "PJ did Pi at CP"." Colin Davies
Within you lies the power for good - Use it!
|
|
|
|
|
PJ Arends wrote:
This can easily be accomplished with a simple subclass
But thats the point: Microsoft did fail to perform even so basic things.
Instead they devised such useless crap as DDX/DDV.
--
"My opinions may have changed, but not the fact that I am right."
Found in the sig of Herbert Kaminski
|
|
|
|
|