About the path
-
I use class CImage to load & save file. I see that it requires the path with "\\" but when I get the path of the desktop image, it's the path with "\". How can I handle it ? Plz help me :rose:
the \\ is required only when you hard code the \ character, to escape it (so that the single \ doesn't escape the character next to it. but when you get a string, it's already constructed, thus no need for modify it.
[VisualCalc][Binary Guide][CommDialogs] | [Forums Guidelines]
-
the \\ is required only when you hard code the \ character, to escape it (so that the single \ doesn't escape the character next to it. but when you get a string, it's already constructed, thus no need for modify it.
[VisualCalc][Binary Guide][CommDialogs] | [Forums Guidelines]
-
I don't understand. So, I give an example: CImage Image; Image.Load("D:\Test.bmp") <-- can't load Image.Load("D:\\Test.bmp") <-- can load What happens when a function retrieves the path D:\Test.bmp? How can we use it ?
do you understand when I say "hard coding the string" ??? it means when you write the path yourself from within the source code... so typing
Image.Load("D:\\Test.bmp")
is hard coding the path, thus you need to escape the \ char into '\\'. also, writingImage.Load("D:\Test.bmp")
is incorrect because the \ is in fact escaping the character next to it, so the compiler tries to understand '\t' as a single character (and as it exists, it will write it - the tab character - in the string between ':' and 'e'). now, if you get that path from an "Open File" dialog for instance, you wont have to iterate over that string to replace every \ with \\. get it now ?[VisualCalc][Binary Guide][CommDialogs] | [Forums Guidelines]
-
I don't understand. So, I give an example: CImage Image; Image.Load("D:\Test.bmp") <-- can't load Image.Load("D:\\Test.bmp") <-- can load What happens when a function retrieves the path D:\Test.bmp? How can we use it ?
Have you? Try to look at [^]. But you really need a good tutorial on
C
programming language. :)If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke -
I use class CImage to load & save file. I see that it requires the path with "\\" but when I get the path of the desktop image, it's the path with "\". How can I handle it ? Plz help me :rose:
-
I don't understand. So, I give an example: CImage Image; Image.Load("D:\Test.bmp") <-- can't load Image.Load("D:\\Test.bmp") <-- can load What happens when a function retrieves the path D:\Test.bmp? How can we use it ?
capint wrote:
Image.Load("D:\Test.bmp") <-- can't load
Because
D:est.bmp
(or maybeD:<tab>est.bmp
) is what actually gets sent as the argument toLoad()
."Love people and use things, not love things and use people." - Unknown
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
-
you could alternatively use / , most windows functions accept it, and the standard C library functions automatically convert it. \\ is ugly especially in long paths.
-
I still can't understand. I know about escape sequences :^) U mean that the path we receive from window functions is OK ( we don't need to replace although they just have "\"), is that right ?
capint wrote:
U mean that the path we receive from window functions is OK
Yes, because those are not being seen by the compiler. What happens at runtime is completely different.
"Love people and use things, not love things and use people." - Unknown
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
-
capint wrote:
U mean that the path we receive from window functions is OK
Yes, because those are not being seen by the compiler. What happens at runtime is completely different.
"Love people and use things, not love things and use people." - Unknown
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
-
My problem is that. I receive the string from the function SystemParametersInfo and I use that string to load by Image.Load. It doesn't work :(
capint wrote:
It doesn't work
Then something else is wrong. Does the file actually exist? What does
Load()
return?"Love people and use things, not love things and use people." - Unknown
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
-
capint wrote:
It doesn't work
Then something else is wrong. Does the file actually exist? What does
Load()
return?"Love people and use things, not love things and use people." - Unknown
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
All my code is here : TCHAR * Temp; Temp = new TCHAR[100]; CString str; SystemParametersInfo(SPI_GETDESKWALLPAPER,100,Temp,0); CImage Image; str = Temp; Image.Load(str); Image.ReleaseDC(); Image.Save(_T("D:\\Temp\\Desktop.bmp")); I debuged & I saw clearly the path, of course, it exits When I replace str by another string created manually, it works
-
All my code is here : TCHAR * Temp; Temp = new TCHAR[100]; CString str; SystemParametersInfo(SPI_GETDESKWALLPAPER,100,Temp,0); CImage Image; str = Temp; Image.Load(str); Image.ReleaseDC(); Image.Save(_T("D:\\Temp\\Desktop.bmp")); I debuged & I saw clearly the path, of course, it exits When I replace str by another string created manually, it works
Which statement is failing?
"Love people and use things, not love things and use people." - Unknown
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
-
Which statement is failing?
"Love people and use things, not love things and use people." - Unknown
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
-
capint wrote:
Image.Load("D:\Test.bmp") <-- can't load
Because
D:est.bmp
(or maybeD:<tab>est.bmp
) is what actually gets sent as the argument toLoad()
."Love people and use things, not love things and use people." - Unknown
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
DavidCrow wrote:
D:est.bmp (or maybe D:est.bmp)
or even
D:est.bmp
! :-D (BTW I got what you meant, anyway kidding is irresistible to me...)If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke -
No statement is failing. It just doesn't do anything. Actually, when I replace "\" by "/", it works. But I still wonder :sigh:
capint wrote:
No statement is failing.
How are you verifying this?
capint wrote:
Actually, when I replace "\" by "/", it works. But I still wonder
Single slashes (like those used on Unix machines) can be used in place of double backslashes.
"Love people and use things, not love things and use people." - Unknown
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
-
All my code is here : TCHAR * Temp; Temp = new TCHAR[100]; CString str; SystemParametersInfo(SPI_GETDESKWALLPAPER,100,Temp,0); CImage Image; str = Temp; Image.Load(str); Image.ReleaseDC(); Image.Save(_T("D:\\Temp\\Desktop.bmp")); I debuged & I saw clearly the path, of course, it exits When I replace str by another string created manually, it works
You realize, of course, that the path can be up to 260 characters long?
-
DavidCrow wrote:
D:est.bmp (or maybe D:est.bmp)
or even
D:est.bmp
! :-D (BTW I got what you meant, anyway kidding is irresistible to me...)If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke:laugh: You're a such a bad guy.
Nobody can give you wiser advice than yourself. - Cicero .·´¯`·->Rajesh<-·´¯`·. Codeproject.com: Visual C++ MVP
-
:laugh: You're a such a bad guy.
Nobody can give you wiser advice than yourself. - Cicero .·´¯`·->Rajesh<-·´¯`·. Codeproject.com: Visual C++ MVP
I know, buddy! :-D
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke