|
Thanks very much Shog9. Much appreciated.
dlarkin77
|
|
|
|
|
To be more specific, open the file with an option to truncate the file. I don't know what API:s you are using.
With standard C++ class std::ofstream , you can use the "normal" constructor: explicit ofstream ( const char * filename, openmode mode = out | trunc );
The last parameter is the open mode, which defaults to output and truncate.
In Win32, look at the function CreateFile . It has a parameter called dwCreationDisposition which you're interested in. You will want to use CREATE_ALWAYS or TRUNCATE_EXISTING .
For MFC, I really don't know. Haven't touched the crud in 3 years.
--
Komm tu mir langsam weh, leg mir die Ketten an
und zieh die Knoten fest, damit ich lachen kann
I blog too now[^]
|
|
|
|
|
Hi. I have encountered this problem as well, while working for some projects(writing a dos edit-like app, while handling the swap). As far as I could dig, I learned that one approach is to use a temp file, where you write the stuff you need in the file (which means you read the parts you need from the old file and put it in the temp file along with the new content), delete the original file, and name the temp file as you want. Even if some languages might hide that from you, that's what's happening underneath ...
|
|
|
|
|
For my setup , it is not WYSIWYG in the View . I do not know the number of pages for printing beforeHand . Basically I need to print out the contents of a Grid Control
I am overriding
1)OnPrepareDC (basically enables/disables continuing of printing)
that checks for the current Row( being printed out.
The code looks like this
void NewView1::OnPrepareDC(CDC* pDC, CPrintInfo* pInfo) <br />
{<br />
<br />
TRACE("Called OnPrepareDC\n");<br />
if(pInfo && printRowId>=m_grid.intf->RowCount){<br />
TRACE("FALSE\n");<br />
<br />
pInfo->m_bContinuePrinting=false;<br />
printRowId =0;<br />
}<br />
else{<br />
TRACE("TRUE\n");<br />
CFormView::OnPrepareDC(pDC, pInfo); <br />
if(pInfo)<br />
pInfo->m_bContinuePrinting=true;<br />
<br />
}<br />
<br />
}
and
2)OnPrint
<br />
void NewView1::OnPrint(CDC* pDC, CPrintInfo* pInfo) <br />
{ TEXTMETRIC tm;<br />
pDC->GetTextMetrics(&tm);<br />
string data;<br />
<br />
elapsed = printRowId;<br />
if(printRowId==0){<br />
data=m_grid.intf->Caption;<br />
pDC->TextOut(pInfo->m_rectDraw.left,pInfo->m_rectDraw.top+tm.tmHeight,data.c_str());<br />
} <br />
while(printRowId<m_grid.intf->RowCount && printRowId>=0){<br />
for(int j=0;j<17;j++){<br />
IsgCellPtr cell = m_grid.intf->GetCellAt(printRowId,j);<br />
data = cell->GetText();<br />
pDC->SetBkColor(cell->Style->GetBackColor());<br />
<br />
int x=((j-1)*2+5)*tm.tmMaxCharWidth;<br />
if(j==0)<br />
x=0;<br />
pDC->TextOut(pInfo->m_rectDraw.left+x,pInfo->m_rectDraw.top+(printRowId+3)*tm.tmHeight,data.c_str()); <br />
pDC->UpdateColors();<br />
<br />
}<br />
printRowId++;<br />
elapsed = printRowID-elapsed ; <br />
<br />
CFormView::OnPrint(pDC, pInfo);<br />
}
Now when I select the Print Preview it renders ok in the Print Preview Dialog , but when i click to zoom into it it displays a blank page .
I think that its a logical error where I am not able to trap the action of Zooming so that the code understands that the whole document needs to be printed again .
Where can I trap that ?
Engineering is the effort !
|
|
|
|
|
Hi,
I've created an SDI and as part of the application I have a dialog box that gets displayed when some action is done in the view. The dialog box is a separate class. I get some data in that dialog and need to store it in the document.
How can I -
- get a handle to the view from where the dialog was launched in order to be able to use the GetDocument() function within a message handler for the dialog box?
- solve this otherwise?
Thanks,
HelpWanted
|
|
|
|
|
Which class owns the Dialog ?
Engineering is the effort !
|
|
|
|
|
The dialog is in a separate class on it's own. Te view class creates an instance of it and calls the doModal() function to display it.
|
|
|
|
|
This will assume it is a modal dialog.
You mention needing to update the document, so
you need to add a command handler to the doc.
Either using ClassWizard, or manually, add
a command handler to the document.
BEGIN_MESSAGE_MAP(CMyDocument, CDocument)
...
ON_COMMAND(IDC_MYCOMMAND, OnMyCommand)
...
END_MESSAGE_MAP()
...
void CMyDocument::OnMyCommand)
{
}
You've already got a dialog box. I'll pretend
it has a few member variable that you store
data in.
void CMyDocument::OnMyCommand)
{
CMyDialog dlg (AfxGetMainWnd ()); // Make the dialog a child of the application window - doc don't have one.
dlg.m_bFlagOfSomeKind = FLAG_FOO | FLAG_BAR;
dlg.m_nVariable = m_nVariable; // Copy over a variable from the doc.
if (dlg.DoModal () != IDOK) // Do the dialog.
return;
// Use the results.
m_nVariable = dlg.m_nVariable.
m_nOtherVar = dlg.m_nResultData;
UpdateAllView (); // Sync view(s) with new contents of document.
}
Done!
Iain.
|
|
|
|
|
Yes, the dialog is a modal dialog.
Here are some follow up questions:
- What does AfxGetMainWnd() do?
- Can I create an instance of the dialog in the view and display it from there based on some menu choice by the user?
Thanks for the help!
|
|
|
|
|
AfxGetMainWnd
If you look it up in the help, it will tell
you that it returns the main CWnd * of the program.
Look in you CMyApp::InitInstance function for
the place it is set.
You *could* run this the function from the
view class (CMyView::OnMyCommand),
and replaced (AfxGetMainWnd ()) with (this).
You would need to look at the CView::GetDocument () function also.
|
|
|
|
|
Hi,
I am using this to get the time a file was written to and it looks like it always gives me the GMT time and not my local time.
So...
If I write this
<br />
SYSTEMTIME *sys_time=new SYSTEMTIME;<br />
FileTimeToSystemTime (&fd.ftLastWriteTime,sys_time);<br />
Now, sys_time->wHour will not be the eastern time but GMT,so it will be 5 hours forward.
I can easily take off 5 hours, but if it gives me 0 then I have to rull bakc a whole day or year and I don't know of an easy way to do so...
any idea ?
|
|
|
|
|
See SystemTimeToTzSpecificLocalTime. Or, call FileTimeToLocalFileTime before calling FileTimeToSystemTime.
onwards and upwards...
|
|
|
|
|
Cool !
Exactly what I needed.
|
|
|
|
|
i just need a conversion like if i give 1200.25
the class must give a CString like
One Thousand Two hundred and twenty five..
i need this urgently, but i didnt want to re - invent the wheel. , so if you know this please help me..!!
Ninety-eight percent of the thrill comes from knowing that the thing you designed works, and works almost the way you expected it would. If that happens, part of you is in that machine.
|
|
|
|
|
how do i represent 1225.25 ?
Engineering is the effort !
|
|
|
|
|
Several articles here
http://www.codeproject.com/string/#Text+Conversion[^]
"You're obviously a superstar." - Christian Graus about me - 12 Feb '03
"Obviously ??? You're definitely a superstar!!!" mYkel - 21 Jun '04
Within you lies the power for good - Use it!
|
|
|
|
|
renjith_sree wrote:
i just need a conversion like if i give 1200.25
the class must give a CString like
One Thousand Two hundred and twenty five..
I'm a bit confused. Wouldn't "One Thousand Two hundred and twenty five" be represented as 1225, or should the text read "One Thousand Two hundred dollars and twenty five cents" (assuming American currency here)?
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
|
|
|
|
|
I have been trying to get a simple Client/Server application running using the TAO Corba, but having building and then running problems.
Are they any simple
(Get you Started) examples for Visual Studio .Net out there.
I have found some examples on the web, but either cant get them built or dont run.
Thanks.
|
|
|
|
|
Hi!
I have this problem with vc++ 6, under windows XP:
Wher running my application (is a Dll!!) on Debug mode running ,in release mode don't work. The same application under windows 2000 don't have problem!!!
You know this problem?????
Tank's all!!
Hi! I'm very happy to talk with everybody about VC++.
|
|
|
|
|
The devil is in the details.
Your "application" is a DLL.
But you cannot simply run a DLL.
How is it run? Is it a com server, a DLL for
an EXE you've written?
How is it not running? Is it never being used?
That may be a security thing.
Does it start to run, then dies horrible?
Pepper your code with OutputDebugString (...) and look at DebugMon(?) on sysinternals[^].
etc.
|
|
|
|
|
Of course!
I have a EXE application that call a DLL!
Are two different applications.
The DLL application code when goes in execution i receive a message that "The memory cannot read".
Now, the same code under windows 2000 works without problem!
Tank's you!
Hi! I'm very happy to talk with everybody about VC++.
|
|
|
|
|
I would put a lot of OutputDebbugString s in your code, and run Dbgview from www.sysinternals.com[^].
That may help track down the problem.
It is likely to be bad initialisation.
In Debug mode, uninitialised memory gets filled with 0xCD [*], but its filled with NULL in release mode.
So they do behave subtly differently.
Iain.
[*] I'm not 100% sure of the value, but its close.
|
|
|
|
|
Hi Ian!
Tank's you for your disponibility. I have found a solution, but not the problem! I have try to create a new exe and i'have call a part of code.
Now running! I belive that part of the source code are written with "the feet" (sorry for my expression but in my country we say!!). Now i must found the different code from the first application and the new application.
I hope to talk with you again.
Patrizio.
Hi! I'm very happy to talk with everybody about VC++.
|
|
|
|
|
Iain Clarke wrote:
In Debug mode, uninitialised memory gets filled with 0xCD [*], but its filled with NULL in release mode.
No, in release mode uninitialised memory is undetermined. It can be anything that was at that memory location previously. For this reason you should always initialise memory within your applications.
Ant.
I'm hard, yet soft. I'm coloured, yet clear. I'm fruity and sweet. I'm jelly, what am I? Muse on it further, I shall return! - David Walliams (Little Britain)
|
|
|
|
|
Turning brain on, you're right.
If its any consolation, I don't trust uninitialised data anyway, so I haven't been caught
but my own misinformation. Hopefully other people ignore me too!
Iain.
|
|
|
|