|
You asked this question previous did you see my answer?
|
|
|
|
|
I must be some kind of melon head. I'm including <fstream> and don't understand why I can construct an fstream like so
fstream FileDataStream;
FileDataStream.open(fileName, ios::out | ios::ate);
and get things to work
but not
fstream FileDataStream;
FileDataStream.open(fileName, ios::out | ios::noreplace);
because it says
error C2039: 'noreplace' : is not a member of 'basic_ios<char,struct std::char_traits<char=""> >'
I've only looked in the help and checked out "fstream", read the notes about its ctor and seen these flags, I could understand if the 1st one didn't work, I would assume I'm doing something ridiculous, but can't work out how it can recognise some of the mode flags, but not another
If any kind soul can just get me going (I know it tends to be David Crow who comes to the rescue!) I would really appreciate it.
I just want to:
- check if a file (specified by a CString object) exists.
- if it does, I want to nip to the end of the file and start appending data rows
- if it doesn't, I just need to create it, bung in a few lines of header and then put the data rows in it.
I'm embarrassed and ashamed that it's taking me so long to get this to work as I'm sure in days gone by I must have done this a hundred times!
aaarrrggghhhhh!
|
|
|
|
|
just so you don't think I am not writing anything, here is what I've got so far, please do not laugh
void CTestFolderBrowseDlg::OnSaveentry()
{
// TODO: Add your control notification handler code here
int sel = m_Table.GetSelectionMark();
if(sel < 0)
return; // ERROR no selection
// Build Target File Name
if(!pathLoaded)
return; // ERROR no path info
CString energyText;
energyText = m_Table.GetItemText(sel, 0);
CString fileName(path);
fileName += '\\';
if(energyText.GetLength()<2) fileName += "0";
energyText += "MeV.dat";
fileName += energyText;
// Check if File Exists
fstream FileDataStream;
FileDataStream.open(fileName, ios::out | ios::ate); // note, the noreplace flag doesnt work
if(FileDataStream.is_open())
{
// file exists (I think without noreplace, it's always going to end up in here)
// Read Data
// Append Data
FileDataStream<
|
|
|
|
|
just curious : why are you creating a fstream if you only need to write to the file ? doesn't a ofstream suffice ?
|
|
|
|
|
ldsdbomber wrote: I've only looked in the help and checked out "fstream"...
But you did not look in ios.h , which is included by fstream.h . With the newer header files, the noreplace and nocreate flags were removed.
ldsdbomber wrote: - check if a file (specified by a CString object) exists.
How about _access(str, 0) ? Or just try to open the file for reading. If that fails, the file likely does not exist.
ldsdbomber wrote: - if it does, I want to nip to the end of the file and start appending data rows
Have you tried ios::app ?
"A good athlete is the result of a good and worthy opponent." - David Crow
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
thanks David. I have not used _access before, I am mainly relying on the help files within VC from pressing F1 with the keyword highlighted or searching in the index there. It doesn't always seem very well organised and I am often confused about when I am looking at pure C, C++, MFC, STL etc etc. But _access seems to be exactly what I am looking for. If you can recommend a good book that covers all this newer up to date stuff, that would be great. For the most part, I'm looking at MFC dialog apps
|
|
|
|
|
ldsdbomber wrote: For the most part, I'm looking at MFC dialog apps
For MFC, you can use CFile::GetStatus() . There's also GetFileAttributes() .
"A good athlete is the result of a good and worthy opponent." - David Crow
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
how to create a setup file(msi file) using mfc?
|
|
|
|
|
have you only googled a little ?
isn't inno Setup[^] what you're looking for ?
also, were you really needing to repost your question 2 minutes after this one ? please delete it.
|
|
|
|
|
|
tom groezer wrote: They become undocked form their place
The same happens to your postings...
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.
|
|
|
|
|
|
Nobody can give you wiser advice than yourself. - Cicero
|
|
|
|
|
|
I have a problem with my IDE. Whenever I debug the application i see all the windows flowing over. They become undocked form their place.
|
|
|
|
|
this is because the debugger has its own interface... by chance, it displays the same windows than those docked when you're righting your code, but it could be different also
ps: remove your duplicate message please
|
|
|
|
|
How to get rid of it? Is there something to do with the settings?
|
|
|
|
|
configure it once... for me, no problem with this...
|
|
|
|
|
tom groezer wrote: Whenever I debug the application i see all the windows flowing over.
Dock them.
Close VisualStudio.
Ope it again and the debugger remembers where you placed the windows.
I would have liked a possibility to fix the window-placement, but I have not found it anywhere.
Failure is not an option - it's built right in.
|
|
|
|
|
According to the KB article Q135788 the below code is the correction action that is to be applied to have the TrackPopupMenu to behave accurately.
Could somebody explain the problem better and provide a deeper understanding?
What is the significance of sending WM_NULL message?
SetForegroundWindow(hDlg);
// Display the menu
TrackPopupMenu( hSubMenu,
TPM_RIGHTBUTTON,
pt.x,
pt.y,
0,
hDlg,
NULL);
PostMessage(hDlg, WM_NULL, 0, 0);
|
|
|
|
|
Posting the null message to the popup menu's owner window forces a task switch to the application that displayed the menu. WM_NULL is chosen as it's a benign message that doesn't do anything more than cause the task switch.
/ravi
|
|
|
|
|
if i understood your question correctly, the according KB article in MSDN describes why this workaround is necessary:
PRB: Menus for Notification Icons Do Not Work Correctly[^]
SYMPTOMS
...
When you display a context menu for a notification icon (see Shell_NotifyIcon),
clicking anywhere besides the menu or the window that created the menu
(if it is visible) doesn't cause the menu to disappear.
...
RESOLUTION
...
The second problem is caused by a problem with TrackPopupMenu. It is necessary
to force a task switch to the application that called TrackPopupMenu at some
time in the near future. This can be accomplished by posting a benign message
to the window or thread.
... So the WM_NULL message is used to force a task switch to the calling app, so when you click outside the popup menu, the popup menu disappears correctly.
cheers,
mykel
OMM: "Let us be thankful we have commerce. Buy more. Buy more now. Buy. And be happy."
|
|
|
|
|
Hi everybody,
i already wrote a function which changes the view of a MDIFrame ( hide old view, show new view )
SetActiveView(New_View);
i add even a New_View->SetDlgCtrlID(AFX_IDW_PANE_FIRST);
and ::SetWindowLong(New_View->m_hWnd,GWL_ID,AFX_IDW_PANE_FIRST);
It works nearby perfect. Only if i minimize the frame.
The new view gets the OnSize-Message and the old view too ( 2 times)
So i've an effect of non-drawing on the new view.
I put a "if(isHidden) return;" in the OnSize-Handler of the old view ( isHidden is setted to TRUE during the view-changing ) which don't resolve the problem
Big thanks for help
|
|
|
|
|
I'm trying to write a program that will connect two computers with a parallel port, be able to send information from one and have the other receive it, and work in Visual C++. I've been researching other programs using the parallel port, and everything I have found is a different type of program (such as LEDs lighting up), won't compile in Visual C++, or is more advanced than I can understand. I attempted to modify the code from the article "How to use serial port to communicate between two computers" and I might have the receive part working, but I can't test it until I finish the other half. I honestly don't think I did it right, so if anyone has any tips or helpful comments, I'd greatly appreciate it.
|
|
|
|
|
I recently got interested in something alike a while back too. the tricky thing is that in windows XP and maybe 2000 etc using windows itself to control the port is blocked, so you must use the dll InpOut32.dll (google it) and take a look at
http://www.logix4u.net/inpout32.htm
http://www.hytherion.com/beattidp/comput/pport.htm
If you still get stuck i can post some of my code when i come home.. (it was only for controling leds and and some inputs, but it may help..) (i controlled a small RC car using the arrow keys ^^ )
//Johannes
|
|
|
|