Loading an Image from file

joe_pool_is

Contributor
Joined
Jan 18, 2004
Messages
507
Location
Longview, TX [USA]
Looking at the VS 2005 Express example for C++ "How to Modify the Size of Placement of a Picture at Run Time":

private:
void StretchPic()
{
// Stretch the picture to fit the control.
pictureBox1->SizeMode = PictureBoxSizeMode::StretchImage;
// Load the picture into the control.
// You should replace the bold image
// in the sample below with an icon of your own choosing.
pictureBox1->Image = Image::FromFile(String::Concat(
System::Environment::GetFolderPath(
System::Environment::SpecialFolder::Personal),
"\\Image.gif"));
}


Does not work. I can find the image ok, but the filename starts with "C:\Documents and ..." but the compiler breaks at the "C" (first letter).

Any idea why this example doesn't work?
 
Escape sequences? The backslach begins an escape sequence. \r is carrige return. \n is newline. For each backslash you want to place in a string, type in two: \\.
C#:
System::String path = "C:\\Documents and settings\\things and stuff\\file.exension"
 
marble_eater said:
Escape sequences? The backslach begins an escape sequence. \r is carrige return. \n is newline. For each backslash you want to place in a string, type in two: \\.
C#:
System::String path = "C:\\Documents and settings\\things and stuff\\file.exension"
Yes! I spent some time on this last night, and also came to this conclusion.

Why would Microsoft's example spit out strings that C++ can not use, namely GetFolderPath()? Do they typically show example code that has not been tested?

I don't suppose C++ has some built in function (that is compatible with MFC, STL, CLR, WIN32, etc.) for taking a string and doubling every "\" that it comes across, does it?
 
Not sure if it works in C++ (don't have it installed on the PC to test either) but in C# if you prefix the string with an @ symbol then it doesn't escape anything.
 
Back
Top