|
it was just what I need... thk
SOAD
|
|
|
|
|
You might also want to see about RegisterServiceCtrlHandlerEx. The HandlerEx function is an application-defined callback function used with the RegisterServiceCtrlHandlerEx function. A service program can use it as the control handler function of a particular service. The control handler function is intended to receive notification and return within 2-3 seconds; it should start another thread to perform additional work.
It can receive notifications when a user has logged on and off: SERVICE_CONTROL_SESSIONCHANGE
If dwControl is SERVICE_CONTROL_SESSIONCHANGE, dwEventType can be one of the values specified in the wParam parameter of the WM_WTSSESSION_CHANGE message. All sorts of these parameters indicate if there was a log on or log off or other change to the session.
If dwEventType is SERVICE_CONTROL_SESSIONCHANGE, lpEventData is a WTSSESSION_NOTIFICATION structure.
Use this to determine which session to check.
|
|
|
|
|
Hi all,
Using my application I've found a file path anywhere on my machine and store the full path in a CString variable. That full path, like this,
"F:\\Files\\Read_File.txt"
What I want to do is, find the name of the file(without the extension), and then separate two words Read and File.
I have tried one thing. Use ReverseFind() method of CString class to find the last '\' sign. Then I used the Right() to get the required file name. I can use Right() easily because file name length is always fixed.
<br />
CString ss = "F:\\Files\\ReadFile.txt";<br />
CString aa;<br />
<br />
if(ss.ReverseFind('\\')== 8)<br />
{<br />
AfxMessageBox(ss.Right(12), MB_OK);<br />
aa = ss.Right(12);<br />
}<br />
<br />
if(aa.ReverseFind('.')==8)<br />
{<br />
AfxMessageBox(aa.Left(8), MB_OK);<br />
}<br />
In this way I can separate those two words as well.
Actually this code gives the file name, ReadFile.
But there is a real issue, on the first 'if' condition. First part of the path, that is "F:\\Files" is not fixed. So in the first 'if' condition number 8 can be change depend on the file selection on my PC. How can avoid that.
Thanks
I appreciate your help all the time...
Eranga
|
|
|
|
|
ReverseFind gives you the location in the string of the certain character you are searching for. Using that it can already be flexible regardless of the length of the filename. To get the application name you can use:
aa = ss.Right(ss.GetLength() - (ss.ReverseFind('\\') + 1)); //add 1 to exclude the '\'
with some adjustments, almost the same procedure can be done to get the file name (without the extension)
aa.Left(aa.ReverseFind('.'));
For flexibility you can try to pass the result of ReverseFind to an int first to check if it returns -1 (character not found).
|
|
|
|
|
Ok, I've do it in this way.
<br />
CString ss = "F:\\SRF Resources\\SRF\\G00166_003_01.srf";<br />
<br />
CString aa, bb;<br />
<br />
aa = ss.Right(ss.GetLength() - (ss.ReverseFind('\\') + 1));
AfxMessageBox(aa, MB_OK);<br />
<br />
if(aa.ReverseFind('.') == 13)<br />
{<br />
bb = aa.Left(13);<br />
AfxMessageBox(bb, MB_OK);<br />
}<br />
What is your comments.
I appreciate your help all the time...
Eranga
|
|
|
|
|
Eranga Thennakoon wrote: if(aa.ReverseFind('.') == 13)
{
bb = aa.Left(13);
AfxMessageBox(bb, MB_OK);
}
Even if you have a fixed filename length wouldn't it be better to just use:
<br />
if(aa.ReverseFind('.') != -1)<br />
{<br />
bb = aa.Left(aa.ReverseFind('.'));<br />
AfxMessageBox(bb);<br />
}
It is much more flexible if the filename was changed to another one.
Also, you can just use AfxMessageBox(bb); instead of AfxMessageBox(bb, MB_OK); since the default for AfxMessageBox is the one with OK button anyway.
|
|
|
|
|
Llasus wrote: Even if you have a fixed filename length wouldn't it be better to just use:
Yep, it's better. At the same time I've try another way to do this, but felt so mess. Use Find() to get the last '\' and then read backward to find the name. Try to follow the same way to find '.' and avoid extension. Failed. :->
Llasus wrote: Also, you can just use AfxMessageBox(bb); instead of AfxMessageBox(bb, MB_OK); since the default for AfxMessageBox is the one with OK button anyway.
Thanks pal for the infor. I just used it, because I feel it is completed my code in view. Actually it is useless. I have to type more and more when I used message box. Actually on my testings I used more message boxes to verify my output.
I appreciate your help all the time...
Eranga
|
|
|
|
|
Hi,
for viewing intermediate results I seldom use MessageBox. I prefer either writing to
the console (which is the output pane in Visual Studio while debugging) as printf() does,
and/or writing to a log file. In both cases the advantages are: you don't have to click
OK buttons all the time, and you get to see a lot of intermediate results on consecutive
lines, seems easier to figure out where things start to go wrong.
Anyway, I tend to create a "void log(char*)" function that does the above (and appends
a newline if appropriate).
Luc Pattyn [Forum Guidelines] [My Articles]
this months tips:
- use PRE tags to preserve formatting when showing multi-line code snippets
- before you ask a question here, search CodeProject, then Google
|
|
|
|
|
Thanks pal. Actually lots things I have done on MFC. So that's why I used that way to check weather I'm going wrong or not.
I appreciate your help all the time...
Eranga
|
|
|
|
|
Or use TRACE
Greetings.
--------
M.D.V.
If something has a solution... Why do we have to worry about?. If it has no solution... For what reason do we have to worry about?
Help me to understand what I'm saying, and I'll explain it better to you
|
|
|
|
|
Eranga Thennakoon wrote: Use Find() to get the last '\' and then read backward to find the name. Try to follow the same way to find '.' and avoid extension. Failed.
Why mess with all of this, where there are existing functions that do it for you? Will your code work with other character sets?
"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 have a mess here. I no it is complicated that this way.
CString::Find()
Thing is that, can I used index to get a sub-string. Basically it searches the sub-string which we define. Then gives ASSERT the application.
What is your comments on my thought.
I appreciate your help all the time...
Eranga
|
|
|
|
|
Can you give the snippet of your code which causes the assert error?
|
|
|
|
|
Actually I don't have a code. I asked this based on MSDN example. I try it coding and let you know.
I appreciate your help all the time...
Eranga
|
|
|
|
|
Eranga Thennakoon wrote: Then gives ASSERT the application
what was your string?
|
|
|
|
|
You mean the CString which I used. It's like this, a path of a file.
F:\Resources\Files\G00166_003_01.txt
I appreciate your help all the time...
Eranga
|
|
|
|
|
Eranga Thennakoon wrote: What is your comments.
Your code is inefficient, and makes many assumptions.
"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
|
|
|
|
|
Check the PathStripPath() function
|
|
|
|
|
Thanks pal. But I feel that ReversFind() more easy, because I can use Mid() to extract any sub-string from the file name.
Thanks again.
I appreciate your help all the time...
Eranga
|
|
|
|
|
I'd strongly recommend using the ShellAPI command that David pointed you to.
What about
c:file.txt?
or all sorts of strange notations for filenames you will hardly ever use, but the shell team have handled for you?
Iain.
|
|
|
|
|
Or what about those that are named file.jpg.exe on machines with "Hide extensions for known file types" turned off? The possibilities are not endless, but there are several of them to consider when rolling your own implementation.
"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
|
|
|
|
|
Some people just like that thunking feeling they experience as they keep banging their head upon the wall ...
I can't wait to see what turds float to the surface the moment a customer passes a network file path into that garbled up code!
I also like the code examples you come across that assume the 'path' starts after the semicolon.
Oh, wait the path "\\Dev\Link\Shared\MyFile.Txt" does not have a semicolon, how can this be
|
|
|
|
|
How about PathFindFileName in shlwapi.dll?
Pax Domini sit semper vobiscum
|
|
|
|
|
Thanks pal. But I think dealing with ReversFind() is so easy.
I appreciate your help all the time...
Eranga
|
|
|
|
|
Does anyone know of any open-source code that will allow me to parse a C++ header file for all the class method signatures?
---
Yours Truly, The One and Only!
web: devmentor.org
Design, Code, Test, Deploy
|
|
|
|