|
If you're on XP+ and the file is on an NTFS volume, you can use SetFileShortName() .
|
|
|
|
|
Can someone give me a real, WORKING - example(code) of how to "CreateDirectory" , "CopyFile" and "ChangeDirectory" in MFC.
I know how to use these "verbs/tokens" in non-MFC programs, but they aren't available to you in MFC; because you can't "#include <window.h>" in MFC.
So how do you do the same things in MFC. Example code PLEASE!
A C++ programming language novice, but striving to learn
|
|
|
|
|
windows.h is very much included in MFC.
Here's a working sample
::CreateDirectory(_T("C:\\TESTTEST"), NULL);
HANDLE hFile = ::CreateFile(_T("C:\\TESTTEST\\test.tst"), GENERIC_WRITE, FILE_SHARE_WRITE, NULL, CREATE_NEW, FILE_ATTRIBUTE_NORMAL, NULL);
::CloseHandle(hFile);
::CopyFile(_T("C:\\TESTTEST\\test.tst"), _T("C:\\test.tst"), TRUE);
::SetCurrentDirectory(_T("C:\\TESTTEST"));
|
|
|
|
|
Larry Mills Sr wrote: because you can't "#include <window.h>" in MFC.
Not true. MFC is a wrapper on Win32, you call any Win32 API you like. Sounds like you have another problem ?
Christian Graus - C++ MVP
|
|
|
|
|
Apparently <windows.h> is already included by MFC headers (AFXV_W32.H).
Regards
|
|
|
|
|
Thanks. Everyday I learn and learn and learn; but sometimes I forget what I learned.
I never realized that windows.h was included in MFC, so dumb me tried to do everything I wanted to do without using any API functions. You've just made my programming life much, much simpler,
Again thanks.
A C++ programming language novice, but striving to learn
|
|
|
|
|
Hi all,
in my application (MFC MDI Document/View) I use a datagrid and a chart control, each of them in a static splitter pane. Now, I want to provide a different view on my data and therefor I want to open a new child with a "different" view class (derived from CFormView) while the first view is still open. The menu which is displayed should depend on the View which is currently active.
Can anybody give me a hint and show me the pitfalls?
Thank you,
Frank.
|
|
|
|
|
Hi All,
This seems such a simple problem, I am embarrassed to ask for help, but I just can't seem to get the syntax correct for the CopyFile command. My application builds a vector of CStrings containing commands in format Copyfile( "source file", "dest file", FALSE ), using double quotes around the file specifications in case there are embedded spaces. The following is one of the commands:
CopyFile( "C:\Documents and Settings\rfickling\My Documents\Expense Report Form.xls", "Expense Report Form.xls", FALSE );
All of these commands fail with an error code of 123, which indicates invalid call syntax. What is wrong here? Can anyone help me with this dumb little problem?
Thanks,
Royce
|
|
|
|
|
RoyceF wrote: CopyFile( "C:\Documents and Settings\rfickling\My Documents\Expense Report Form.xls", "Expense Report Form.xls", FALSE );
Don't you escape slashes?
|
|
|
|
|
Yes, in the CString.Format() method call you do:
CString str;<br />
str.Format( "C:\\Documents and Settings\\rfickling\\My Documents\\Expense Report Form.xls" );
I am actually formatting these file specs into CString variables so that it looks like the following:
strSrc = "C:\Documents and Settings\rfickling\My Documents\Expense Report Form.xls"; <br />
strDst = "Expense Report Form.xls"<br />
So the command in C++ syntax is:
CopyFile( strSrc, strDst, FALSE );
This should work, but I get a 123 error.
|
|
|
|
|
I think the problem is the target file name. You are giving just a filename, so Windows tries to create the file in the current directory.
And what's the current directory?
Try giving a targetname with a complete path, if possible.
Or make sure the current directory is set to where you want the file to be copied to.
SetCurrentDirectory();
Alcohol. The cause of, and the solution to, all of life's problems - Homer Simpson
|
|
|
|
|
The following code works fine on my computer (Win2k):
CString strSrc, strDst;
strSrc.Format( "C:\\Documents and Settings\\Carlo\\My Documents\\Donald Duck.txt" );
strDst.Format( "Donald Duck.txt" );
if ( CopyFile( strSrc, strDst, FALSE )==FALSE)
{
}
|
|
|
|
|
Error code 123 is "The filename, directory name, or volume label syntax is incorrect."
Does this help narrow it down?
*EDIT* You shouldn't have to add any double quotes because of spaces.
-- modified at 18:10 Wednesday 22nd November, 2006
|
|
|
|
|
RoyceF wrote: CopyFile(
instead of this use ShFileOperation
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
cheers,
Alok Gupta
VC Forum Q&A :- I/ IV
Support CRY- Child Relief and you
|
|
|
|
|
Thanks for the help, guys. I found that my problem was using the double quotes around the file paths and not specifiying a filename in the 2nd parameter.
Royce
|
|
|
|
|
I recently had some code sent to me by a user of one of my articles that improved the functionality of my article. The code is designed to work with VC8. But as I want the code to work on VC6 and up I have to put guards around it. So my quuestion is what version of VC introduced the __FUNCTION__ macro and what version introduced the __noop keyword?
You may be right I may be crazy -- Billy Joel --
Within you lies the power for good, use it!!!
|
|
|
|
|
I believe __FUNCTION__ was first introduced in VC7, which was my final straw to upgrade from VC6. As for the __noop , I'm not sure.
-- modified at 15:16 Wednesday 22nd November, 2006
__noop also added in VC7
|
|
|
|
|
Thanks
I am assuming you mean VC7.0 (2002), not VC7.1 (2003)
You may be right I may be crazy -- Billy Joel --
Within you lies the power for good, use it!!!
|
|
|
|
|
PJ Arends wrote: I am assuming you mean VC7.0 (2002)
Probably a little late, but yes
|
|
|
|
|
Is there a way to add more than one event handler in VC++ 2003 like we could do in VC++ 6.0?
Adding multiple OnUpdate handlers for my menus is really getting me down as it insists on resetting the tree ctrl and the grid in the dock bar in VC++ 2003.
Basically, is there a trick to prevent the tree or grid from resetting after each addition?
|
|
|
|
|
Huh?
bob16972 wrote: Is there a way to add more than one event handler in VC++ 2003 like we could do in VC++ 6.0?
Event handlers for what events?
bob16972 wrote: Adding multiple OnUpdate handlers for my menus is really getting me down as it insists on resetting the tree ctrl and the grid in the dock bar in VC++ 2003.
How are OnUpdate handlers related to tree and grid controls?
bob16972 wrote: Basically, is there a trick to prevent the tree or grid from resetting after each addition?
Each addition of what?
Sorry, I have no idea what you are asking
|
|
|
|
|
Sorry, I'm referring to the VC++ 2003 IDE.
The tree I'm referring to is the ClassView tree.
The grid I'm referring to is the grid in the properties dockbar.
I'm adding Event handlers to respond to menu events. I choose a class (i.e. CFrameWnd derived class like CMainFrame) in ClassView, select the "events" button in the "Properties" dock bar which shows a grid containing all the Events I can choose to write a handler for. Then I choose to add an OnUpdate handler for one of my menu's submenu items (identifying it via it's Resource Symbol).
My handler code is added to the class' files and the "Properties" dockbar goes blank (No grid showing anymore). This requires me to do it all over again for the next menu event handler...etc...
*************************
In Visual C++ 6.0, we were able to add many of the menu event handlers, pretty much at the same time using the same instance of ClassWizard. We could just select a class in the wizard and double click as many event handlers as we wanted, then hit OK and they'd be added to the class.
*************************
Is it possible to add more than one handler at a time like this in VC++ 2003?
|
|
|
|
|
Now I got it, thanks I had a feeling it was that....didn't make sense for code.
That drives me nuts...I wish I could help. I'll be watching to see if someone has a solution
though!
Mark
|
|
|
|
|
Hi there,
I have an application that is receiving messages from some mobile devices from eight different locations through GPRS using UDP sockets, and I am supposed to send the messages to the 2nd application using TCP/Ip sockets some how that there will be no confusion for the response that comes from the 2nd application that I am supposed to transfer to the device that has sent the original message. For example if I can have the same Ip address and use 8 different ports for that to send to the 2nd application and receive the response back. Th question is how can I do that without creating 8 sockets?
Appreciates any idea
|
|
|
|
|
I think your two choices are
1) Use 8 separate TCP/IP sockets, 1 for each mobile source.
2) Use one TCP/IP socket connection and wrap the UDP datagram in a packet containing a header that
indicates which mobile source the message came from. The same way a TCP packet wraps an IP
packet.
Mark
|
|
|
|