|
Hello,
I'm looking for the easiest way to find the folder of a file. I have a string that represent the path to a file, something like:
C:\Temp\Test\File1.txt
From that path I want to retrieve the folder of the file, which is:
C:\Temp\Test\
Ok, so far so good, not very difficult to do. But now, the path can also be relative, so it can take one of the following form:
File.txt (if the file is in the working directory)<br />
..\Test\File1.txt
The purpose is to append to the resulting string another filename or folder:
C:\Temp\Test\OutputDir\
Is there any simple way of doing that (without having to check every possible case) ? Maybe something like opening the file and then from that retrieve its folder...
Any suggestion are welcome
|
|
|
|
|
Create an absolute or full path name for the specified relative path name.
char *_fullpath(
char *absPath,
const char *relPath,
size_t maxLength
);
wchar_t *_wfullpath(
wchar_t *absPath,
const wchar_t *relPath,
size_t maxLength
);
Each of these functions returns a pointer to a buffer containing the absolute path name (absPath). If there is an error (for example, if the value passed in relPath includes a drive letter that is not valid or cannot be found, or if the length of the created absolute path name (absPath) is greater than maxLength) the function returns NULL.
Love Forgives--Love Gives--Jesus is Love <marquee direction="up" height="50" scrolldelay="1" step="1" scrollamount="1" style="background-color:'#44ccff'">
--Owner Drawn
--Nothing special
--Defeat is temporary but surrender is permanent
--Never say quits
--Jesus is Lord
|
|
|
|
|
Thaks
That's funny because I just figured it out how to do it (the same as you) and I wanted to post a message here to explain.
And to complete what you said, I can then call _splitpath to retrieve the drive letter and combining it to the directory path to obtain what I'm looking for.
But thanks for your answer
|
|
|
|
|
I was going to give you a sample code.
Because of you I got something to learn. He he. That's why I go hunting in these forums. He he
Love Forgives--Love Gives--Jesus is Love <marquee direction="up" height="50" scrolldelay="1" step="1" scrollamount="1" style="background-color:'#44ccff'">
--Owner Drawn
--Nothing special
--Defeat is temporary but surrender is permanent
--Never say quits
--Jesus is Lord
|
|
|
|
|
Cedric Moonen wrote: I'm looking for the easiest way to find the folder of a file.
Programmers are LAZY.
Love Forgives--Love Gives--Jesus is Love <marquee direction="up" height="50" scrolldelay="1" step="1" scrollamount="1" style="background-color:'#44ccff'">
--Owner Drawn
--Nothing special
--Defeat is temporary but surrender is permanent
--Never say quits
--Jesus is Lord
|
|
|
|
|
Owner drawn wrote: Programmers are LAZY.
This is sooo true
|
|
|
|
|
(if the file is in the
working directory)
Use GetModuleHandle as ur console Module and File.txt are same Directory
never say die
|
|
|
|
|
You can also use PathRemoveFileSpec() to separate the pathname from the filename. Use PathRelativePathTo() for your second requirement.
"The words of God are not like the oak leaf which dies and falls to the earth, but like the pine tree which stays green forever." - Native American Proverb
|
|
|
|
|
Thank u Sir
never say die
|
|
|
|
|
I am writing an image process program. I want to cut or copy some text with font information from other software, such as MS Word, Excel etc . In my program, the text will be draw on screen with same font. So I need to get the font information from clipboard, what should I do?
Thanks.
|
|
|
|
|
You may use the GetClipboardData() API call to get the clipboard data . I do not know how you may get font information from the clipboard.
Regards,
Rajesh R. Subramanian
You have an apple and me too. We exchange those and We have an apple each.
You have an idea and me too. We exchange those and We have two ideas each.
|
|
|
|
|
WM_ASKCBFORMATNAME
Love Forgives--Love Gives--Jesus is Love <marquee direction="up" height="50" scrolldelay="1" step="1" scrollamount="1" style="background-color:'#44ccff'">
--Owner Drawn
--Nothing special
--Defeat is temporary but surrender is permanent
--Never say quits
--Jesus is Lord
|
|
|
|
|
Since there isn't just one clipboard format, you'll need to look for data and parse it. For example, Word puts RTF and HTML data on the clipboard; either of those can be parsed to find the font. I just tried with Word 2K and the relevant HTML is:
<span style='font-size:10.0pt;mso-bidi-font-size:12.0pt;
font-family:"Book Antiqua";mso-fareast-font-family:"Times New Roman";
mso-bidi-font-family:"Times New Roman";mso-ansi-language:EN-US;mso-fareast-language:
EN-US;mso-bidi-language:AR-SA'>Hello, Bob!</span> which shows the font was Book Antiqua 10 pt. If you haven't already, check out my ClipSpy[^] article so you can see exactly what data gets put on the clipboard.
--Mike--
Visual C++ MVP
LINKS~! Ericahist | NEW!! PimpFish | CP SearchBar v3.0 | C++ Forum FAQ
I even hear the Windows "OMG I booted up fine" sound.
-- Paul Watson diagnosing hardware problems.
|
|
|
|
|
Thank you , I think this is helpful, I will try.
|
|
|
|
|
1.
like window caption icon
first: mouse left button down the menu popup
second: the menu not close, mouse left button down the menu close
third: goto first
i handle the WM_LBUTTONDOWN, and TrackPopupMenu a menu, but second left button down the menu close, but popup menu too.
2.how let the menu popup auto adjust popup point, like the caption menu popup.
-- modified at 4:47 Friday 6th January, 2006
|
|
|
|
|
I am sorry, I dont get it.
Cheers,
Sebastian
--
Contra vim mortem non est medicamen in hortem.
|
|
|
|
|
|
HOW WHAT wrote: 1.
like window caption icon
first: mouse left button down the menu popup
second: the menu not close, mouse left button down the menu close
third: goto first
i handle the WM_LBUTTONDOWN, and TrackPopupMenu a menu, but second left button down the menu close, but popup menu too.
HOW WHAT wrote: how let the menu popup auto adjust popup point, like the caption menu popup.
This one's lot better.
Take a look in MSDN documentation for TrackPopupMenu. You will get a list of values for uFlags parameter. These are the ones that decide where it pops up.
It also has flags to decide whether to animate the menu or not.
Love Forgives--Love Gives--Jesus is Love <marquee direction="up" height="50" scrolldelay="1" step="1" scrollamount="1" style="background-color:'#44ccff'">
--Owner Drawn
--Nothing special
--Defeat is temporary but surrender is permanent
--Never say quits
--Jesus is Lord
|
|
|
|
|
you -> warmheatedness
"This one's lot better." what mean?
|
|
|
|
|
I think you mean this:
When we double-click at the left-most position on a window's title-bar, the default action takes place. In case of explorer, the window closes.
That is: Click on it once, the pop-up menu shows up half a second later, but double-click on it, the window closes.
Now you want to do the default action when the user double-clicks on the icon.
Set a variable to true on first mouse-click, and start the timer. You could set the timer, like 500 ms. When the time expires and the timer function runs, it sets the variable back to false, kills the timer, and shows the menu.
Now if the user clicks, then before the timer function can run, he clicks again, then you kill the timer, set the variable back to false, and do the default action: Like in case of explorer: 'close the window' etc.
I hope I understood you, and I hope you understood this.
this is this.
|
|
|
|
|
|
Now I think I know what you mean.
You want to dismiss the popup sys-menu when the user clicks in the area again, 'when the menu is showing'.
I don't how to do that, but you could search on that: "dismiss sys-menu" or "How to find out if the sys-menu is visible". I am too lazy right now.
Or you could remove the Title-bar from the application, and custom-draw the Title-bar yourself. Then it would be very easy to handle the menu stuff.
Try the following: (If it is even possible ??)
You could set a variable to true when the sys-menu shows, and set it to false when window loses focus, or user clicks somewhere else, or uses the keyboard to dismiss the menu etc. Now if the user clicks again, then check that variable. If it is already true, then try to close the menu using some technique. (You have to first be able to tell whether the sysmenu is showing or not to continue on this path. Then later find some way to dismiss it).
this is this.
|
|
|
|
|
In an application, a blunt window got opened and i'm not able to close it. everytime i use the application, i accedently open this window, which stays adamantly and i had to use Taskmanager everytime to close it.(closes the entire app). now i used spy++ to get the handle of the window, and in my program i sent like
HWND Hand = (HWND)0x002106C8;
SendMessage(Hand,WM_QUIT,0,0);
And in the Spy++ i'm able trace the message is being received by the window. but its not giving up. its still staying there. How to close it forcibly? someone tell me ..its still there i need to kill it.
"But your mind is very complex, very tricky. It makes simple things complicated. -- that's its work. And for centuries it has been trained for only one thing: to make things so complicated that your life becomes impossible."- Osho
<marquee scrollamount="1" scrolldelay="1" direction="up" height="10" step="1">--[V]--
|
|
|
|
|
try with WM_SYSCOMMAND and wparam as SC_CLOSE
like
PostMessage (WM_SYSCOMMAND, SC_CLOSE, 0)
worked???
|
|
|
|
|
its still there. the message received by the application is WM_NCDESTROY.
"But your mind is very complex, very tricky. It makes simple things complicated. -- that's its work. And for centuries it has been trained for only one thing: to make things so complicated that your life becomes impossible."- Osho
<marquee scrollamount="1" scrolldelay="1" direction="up" height="10" step="1">--[V]--
|
|
|
|