|
I was wondering what the easiest way to get only the filename from the FileName property of the Save/Open dialogs in Visual C++? I've created a string variable and set it to SaveDialog1.FileName but that contains the path AND the filename. I know I could go through and find the first \ from the end of the variable and remove anything before it but there has to be an easier, less time consuming, way of doing this. In Delphi there was a property of the Save/Open dialogs that would automatically return only the filename and not the path, but, as far as I can tell, there is not one for Visual C++. Any help and/or ideas would be greatly appreciated!
Thanks,
Tom Sapp
http://www.sappsworld.com
-- modified at 23:52 Friday 28th October, 2005
|
|
|
|
|
There may be a better way than the following in VC. I don't know, though, as I don't use VC. The following helper functions have worked for me, and you are welcome to them. Maybe somebody else can give us both that better way. 'wString' is a typedef for std::basic_string<tchar>, which becomes std::string, so you can just replace 'wString' with 'std::string', and it should work for you. If you find any errors in this, all I can say is that I never claimed to be perfect.
David
bool rmw::fileExists(const wString & fileName) {
WIN32_FIND_DATA d;
HANDLE file = FindFirstFile(fileName.c_str(), &d);
bool retVal(true);
if (file == INVALID_HANDLE_VALUE) retVal = false;
FindClose(file);
return retVal;
}
wString rmw::getPathFromStr(const wString & str) {
int pos = str.find_last_of(TEXT("\\"));
return wString(str.substr(0, pos));
}
wString rmw::extractFileName(const wString & str) {
int pos = str.find_last_of(TEXT("\\"));
return wString(str.substr(pos+1, str.length()));
}
wString rmw::extractFileExt(const wString & str) {
int pos = str.find_last_of(TEXT("."));
if (pos == -1) return "";
return wString(str.substr(pos, str.length()));
}
wString rmw::trimFileExt(const wString & fileName) {
wString fileExt = rmw::extractFileExt(fileName);
int len = fileExt.length();
return fileName.substr(0, fileName.length()-len);
}
wString rmw::extractFileDir(const wString & fileName) {
int pos(fileName.find_last_of(TEXT("\\")));
wString t = fileName.substr(0, fileName.length()-pos);
return t;
}
(Gotta love that STL!)
Debugging - The high art and magic of cussing errors into 'features'
|
|
|
|
|
char path[_MAX_PATH];
char filename[_MAX_FNAME + _MAX_EXT];
char drive[_MAX_DRIVE];
char dir[_MAX_DIR];
char fname[_MAX_FNAME];
char ext[_MAX_EXT];
_splitpath(path,drive,dir,fname,ext);
_makepath(filename,"","",fname,ext);
Software Zen: delete this;
|
|
|
|
|
I've had SOME success getting rid of compiler errors putting this macro redefinition in the project settings
WINVER=0x0501 _WIN32_WINNT=0x0501 _WIN32_IE=0x0600
but I'm still getting the message
C:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\include\stdlib.h(256): error C2381: 'exit' : redefinition; __declspec(noreturn) differs
C:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\PlatformSDK\Include\Windows.h(24): fatal error C1012: unmatched parenthesis : missing ')'
This only happens when I try to open graphics projects using glut. Any ideas?
Normality is a weakness...
|
|
|
|
|
i want to make a program that will respond to spoken commands from the user to open programs and do other tasks in windows. i dont know how to do any speech recognition programming. i downloaded the microsoft speech sdk 5.1 but dont know where to go from here.
any help that anyone can provide would help greatly. code samples are extremly helpful.
thank you in advance for the help
- Kyle
|
|
|
|
|
|
do you know what header replaced the speech.h in microsofts speech rec. 5.1?
that code doesnt work without it, i get all kinds of errors.
- Kyle
|
|
|
|
|
|
Hi, I can read the input data from the parallel port. I have a thread that is reading continously the parallel port and updating a variable with the data.
I want to know if there is a better way to do it, because I need a quick response in my application (software side).
I have two push buttons connected to the parallel port (parallel port is already configured as bi-direccional) so, I want to detect the order in which I press the buttons, if the combination is correct it will display a message.
Could somebody please help me?
Thanks in advance.
|
|
|
|
|
|
Hello
I'm not sure if this is a beginners forum, but I will start here. I am a beginning C++ student and have a couple of mini-projects invloving fractions that I need some guidance on.
First the assignments:
1. Write a Fraction-Reduction program that takes in any fraction (maybe with denominator not equal to 0 or 1), and reduces it lowest terms. The function prototype will take two integer variables passed by reference.
2. Write a function that takes in any number and returns its whole and fractional parts as outputs. Like 6.44 would return int 6 and float 0.44.
My trouble:
On #1: I understand how reference passing is working, that the variables values in main's variables can be changed by the function. What I cant figure out is how to write something that will find the greatest common factor of any two numbers entered. I understand the math behind it but I cant translate that math to the program, and get it the correct place in main or the function and have it work.
On #2: This problem came from the chapter on reference parameters also. So is there a way to do this problem with the user entering one single float? Or is the trick to cin what the user enters in a format that allows to be updated invidually by reference from a function?
If my code is needed I can post it. If there is another forum I need to be at, please let me know. Thank you sincerely for any help.
JB
|
|
|
|
|
j4express wrote: 2. Write a function that takes in any number and returns its whole and fractional parts as outputs. Like 6.44 would return int 6 and float 0.44.
find the ceil or floor of the no depending on less or greater than zero val, Now you get the integer part, now subtract the original no with the integer part and you get the decimal part.
-prakash
Learning Symbian | Personal views
|
|
|
|
|
#1> This is some really old code laying around in the depths of my harddrive, but it should be exactly what you are looking for. It's not really a programming problem as much as a math problem, luckily Euclidean did all the work for us many years ago.
Euclidean algorithm for finding the Greatest Common Denominator:
void GCD(int &Nume, int &Denom)
{
int a= Nume;
int b= Denom
int temp = a % b;
while (temp > 0)
{
a = b;
b = temp;
temp = a % b;
}
Nume= Nume / b;
Denom= Denom /b;
}
#2> Ok, this one is easier than it seems. So lets say we the float 6.44 from the user. Now the easy part, casting a floating point into an integer will automaticall truncate the number, therefore leaving us with only the whole number, simple subtraction does the rest.
float f1 = 6.44f;
int Int1= (int) f1;
f1= f1 - Int1;
|
|
|
|
|
Hello,
i have downloaded the GGNFS from here: http://www.math.ttu.edu/~cmonico/software/ggnfs/
But when I try to compile I get the following errors:
------ Build started: Project: matbuild, Configuration: Debug Win32 ------
Compiling...
matstuff.c
m:\GNFS\src\matstuff.c(112) : warning C4244: '=' : conversion from 'double' to 's32', possible loss of data
matbuild.c
m:\GNFS\src\matbuild.c(662) : warning C4244: '=' : conversion from '__w64 int' to 's32', possible loss of data
m:\GNFS\src\matbuild.c(708) : warning C4267: '+=' : conversion from 'size_t' to 's32', possible loss of data
m:\GNFS\src\matbuild.c(898) : warning C4267: '=' : conversion from 'size_t' to 's32', possible loss of data
m:\GNFS\src\matbuild.c(908) : warning C4267: '+=' : conversion from 'size_t' to 's32', possible loss of data
m:\GNFS\src\matbuild.c(1012) : warning C4267: '=' : conversion from 'size_t' to 's32', possible loss of data
m:\GNFS\src\matbuild.c(1020) : warning C4267: '+=' : conversion from 'size_t' to 's32', possible loss of data
m:\GNFS\src\matbuild.c(1183) : warning C4244: '=' : conversion from 'double' to 'long', possible loss of data
combparts.c
blanczos64.c
m:\GNFS\src\blanczos64.c(318) : error C2065: 'asm' : undeclared identifier
m:\GNFS\src\blanczos64.c(318) : error C2143: syntax error : missing ';' before 'volatile'
m:\GNFS\src\blanczos64.c(471) : error C2143: syntax error : missing ';' before 'volatile'
m:\GNFS\src\blanczos64.c(570) : warning C4244: '=' : conversion from 'u64' to 'int', possible loss of data
m:\GNFS\src\blanczos64.c(832) : error C2143: syntax error : missing ';' before 'volatile'
m:\GNFS\src\blanczos64.c(884) : error C2143: syntax error : missing ';' before 'volatile'
m:\GNFS\src\blanczos64.c(932) : error C2026: string too big, trailing characters truncated
m:\GNFS\src\blanczos64.c(980) : error C2026: string too big, trailing characters truncated
m:\GNFS\src\blanczos64.c(1029) : error C2026: string too big, trailing characters truncated
m:\GNFS\src\blanczos64.c(1077) : error C2026: string too big, trailing characters truncated
m:\GNFS\src\blanczos64.c(1125) : error C2026: string too big, trailing characters truncated
m:\GNFS\src\blanczos64.c(1175) : error C2026: string too big, trailing characters truncated
m:\GNFS\src\blanczos64.c(1226) : error C2026: string too big, trailing characters truncated
m:\GNFS\src\blanczos64.c(1278) : error C2026: string too big, trailing characters truncated
m:\GNFS\src\blanczos64.c(1331) : error C2026: string too big, trailing characters truncated
m:\GNFS\src\blanczos64.c(1384) : error C2026: string too big, trailing characters truncated
m:\GNFS\src\blanczos64.c(1435) : error C2026: string too big, trailing characters truncated
m:\GNFS\src\blanczos64.c(1488) : error C2026: string too big, trailing characters truncated
m:\GNFS\src\blanczos64.c(1541) : error C2026: string too big, trailing characters truncated
m:\GNFS\src\blanczos64.c(1622) : error C2143: syntax error : missing ';' before 'volatile'
m:\GNFS\src\blanczos64.c(1729) : error C2143: syntax error : missing ';' before 'volatile'
m:\GNFS\src\blanczos64.c(1762) : error C2143: syntax error : missing ';' before 'volatile'
m:\GNFS\src\blanczos64.c(1796) : error C2143: syntax error : missing ';' before 'volatile'
m:\GNFS\src\blanczos64.c(1833) : error C2143: syntax error : missing ';' before 'volatile'
m:\GNFS\src\blanczos64.c(1865) : error C2143: syntax error : missing ';' before 'volatile'
m:\GNFS\src\blanczos64.c(2010) : warning C4244: 'function' : conversion from 'u64' to 'size_t', possible loss of data
m:\GNFS\src\blanczos64.c(2014) : warning C4244: 'function' : conversion from 'u64' to 'size_t', possible loss of data
m:\GNFS\src\blanczos64.c(2020) : warning C4244: 'function' : conversion from 'u64' to 'size_t', possible loss of data
m:\GNFS\src\blanczos64.c(2021) : warning C4244: 'function' : conversion from 'u64' to 'size_t', possible loss of data
m:\GNFS\src\blanczos64.c(2121) : warning C4244: 'function' : conversion from 'u64' to 'size_t', possible loss of data
m:\GNFS\src\blanczos64.c(2125) : warning C4244: 'function' : conversion from 'u64' to 'size_t', possible loss of data
m:\GNFS\src\blanczos64.c(2131) : warning C4244: 'function' : conversion from 'u64' to 'size_t', possible loss of data
m:\GNFS\src\blanczos64.c(2132) : warning C4244: 'function' : conversion from 'u64' to 'size_t', possible loss of data
Generating Code...
Build log was saved at "file://m:\Gnfs\ggnfs.vc\matbuild\Debug\BuildLog.htm"
matbuild - 24 error(s), 17 warning(s)
I have no clue what's wrong. Could anyone help me ?
With best regards,
Benedikt
|
|
|
|
|
RedDragon2k wrote: m:\GNFS\src\blanczos64.c(318) : error C2065: 'asm' : undeclared identifier
I believe you'll need __asm for this.
"Take only what you need and leave the land as you found it." - Native American Proverb
|
|
|
|
|
RedDragon2k wrote: m:\GNFS\src\blanczos64.c(318) : error C2065: 'asm' : undeclared identifier
is that an
asm
{
...
};
block ?
if so, try replacing "asm" with "_asm"
(yeah, what David said)
Cleek | Image Toolkits | Thumbnail maker
-- modified at 15:56 Friday 28th October, 2005
|
|
|
|
|
Hello,
When I leave my computer for 30 minutes, the monitors are turned off (power-save mode), but the computer remains on and ready for networking/serving.
I would like to code a small app to force the monitors/displays to power-saving mode immediately (at the press of a button) while keeping the rest of the system on. Could someone point me in the right direction in the MFC library?
thanks,
JennyP
|
|
|
|
|
How about looking into SPI_SETPOWEROFFACTIVE , seems like what you are after.
|
|
|
|
|
can i do some thing like "On Error Go To" like in visual basic in visual c++?
|
|
|
|
|
you need exceptions, have a look at try and catch
Maximilien Lincourt
Your Head A Splode - Strong Bad
|
|
|
|
|
Looking for a (free) c++ library that contains financial engineering routines. By "financial engineering routines" I don't mean simple functions like mortgage calculators; I'm looking for something that handles Black-Scholes option pricing, etc.
Does anybody have any experience with one that they could recommend? It is proving difficult to locate one and the ones that I do find I don't know how reliable/good they are.
|
|
|
|
|
John Theal wrote: I'm looking for something that handles Black-Scholes option pricing, etc.
Does this help? Here is another.
"Take only what you need and leave the land as you found it." - Native American Proverb
|
|
|
|
|
Thanks David. The CodeProject one I was aware of and it was not quite what I needed. The other one, however, looks quite interesting. Thanks for the help.
|
|
|
|
|
Try looking at the TA-LIB on sourceforge.
|
|
|
|
|
The pdb files that VS6 generates for our programs shows both the function names and the parameters info, but the pdb files in the 'windows symbols' that I downloaded today seem to give only the function name and not the function call parameter info. Am I doing something wrong in windbg or that is how it is? How are these pdb files different?
thanks in advance.
|
|
|
|
|