|
lctrncs wrote: It appears that the challenge revolves around restoring functional save capabilities when the base class calls are not present and the CreateFile code is, or overcoming the Access Denied exception that occurs when the open and save base class calls are present in conjunction with the CreateFile code.
Yes.
I looked at your code again and noticed your document class is derived from CRichEditDoc.
You'll definitely need the serialization code used in CDocument::OnSaveDocument() to get the
changes to save. Sorry about that!
I (now) think the simplest solution would be to copy the code from CDocument::OnOpenDocument() and
CDocument::OnSaveDocument() into your overridden implementations. Then tweak the CFile related
code to hold the file open for the entire time the document is open. Also adjust the open flags
appropriately to prevent sharing. Something like this:
class CStudyPartnerDoc : public CRichEditDoc
{
CFile StudyPartnerDocFile;
public:
virtual BOOL OnOpenDocument(LPCTSTR lpszPathName);
virtual BOOL OnSaveDocument(LPCTSTR lpszPathName);
virtual void OnCloseDocument();
};
BOOL CStudyPartnerDoc::OnOpenDocument(LPCTSTR lpszPathName)
{
#ifdef _DEBUG
if (IsModified())
TRACE(traceAppMsg, 0, "Warning: OnOpenDocument replaces an unsaved document.\n");
#endif
CFileException fe;
if (!StudyPartnerDocFile.Open(lpszPathName,
CFile::modeReadWrite | CFile::shareExclusive, &fe))
{
ReportSaveLoadException(lpszPathName, &fe,
FALSE, AFX_IDP_FAILED_TO_OPEN_DOC);
return FALSE;
}
DeleteContents();
SetModifiedFlag();
CArchive loadArchive(&StudyPartnerDocFile, CArchive::load | CArchive::bNoFlushOnDelete);
loadArchive.m_pDocument = this;
loadArchive.m_bForceFlat = FALSE;
TRY
{
CWaitCursor wait;
if (StudyPartnerDocFile.GetLength() != 0)
Serialize(loadArchive);
loadArchive.Close();
}
CATCH_ALL(e)
{
StudyPartnerDocFile.Abort();
DeleteContents();
TRY
{
ReportSaveLoadException(lpszPathName, e,
FALSE, AFX_IDP_FAILED_TO_OPEN_DOC);
}
END_TRY
e->Delete();
return FALSE;
}
END_CATCH_ALL
SetModifiedFlag(FALSE);
return TRUE;
}
BOOL CStudyPartnerDoc::OnSaveDocument(LPCTSTR lpszPathName)
{
StudyPartnerDocFile.SeekToBegin();
CArchive saveArchive(&StudyPartnerDocFile, CArchive::store | CArchive::bNoFlushOnDelete);
saveArchive.m_pDocument = this;
saveArchive.m_bForceFlat = FALSE;
TRY
{
CWaitCursor wait;
Serialize(saveArchive);
saveArchive.Close();
}
CATCH_ALL(e)
{
StudyPartnerDocFile.Abort();
TRY
{
ReportSaveLoadException(lpszPathName, e,
TRUE, AFX_IDP_FAILED_TO_SAVE_DOC);
}
END_TRY
e->Delete();
return FALSE;
}
END_CATCH_ALL
SetModifiedFlag(FALSE);
return TRUE;
}
void CStudyPartnerDoc::OnCloseDocument()
{
CRichEditDoc::OnCloseDocument();
StudyPartnerDocFile.Close();
}
Note that in CStudyPartnerDoc::OnOpenDocument() I left the original error handling when opening
the file. You'll probably want to handle it more gracefully in cases where the file is open
in another app instance (sharing violation).
Maybe I'm on the right track and haven't completely derailed...
|
|
|
|
|
Mark,
Thank for all your help.
This feature is becoming a bit too much for my current schedule.
Chances are that I will return to it at some point. However, for right now I am going to have to put this on the back burner because I need to generate some income (through freelance writing) and find a way to protect my Doc/View based content files (six are ready for posting) so that they cannot be edited and then misrepresented as the work of my company.
Since setting the "read only" bit on the file will not be permanent enough, I thought I might save a flag with my original files then override DoSave to prevent saving if the flag is set.
Another way might be to somehow embed the file in the program itself, so each content file distributed from my company comes with a program, again with DoSave = NULL in the Save As function or some such thing. This approach has the added benefit that I could distribute the content using Armadillo (which I use to provide 30 day trial functionality) which is not able to protect simple unzippers and non-executables.
Since the second approach probably requires the completion of the first, it looks like that will be my starting point.
Thank you again. Your posts were very educational, useful and well written. If you were on my team, I'll bet you could fix all of the problems I plan to spend the next 6 months beating my head against the in an afternoon.
Thanks again. I hope you enjoy your "greetings seasons." Take the rest of the year off.
Groff Schroeder
"For a successful technology, reality must take precedence over public relations, for nature cannot be fooled." Richard Feynman, Minority Report to the Official Report on the Space Shuttle Challenger Crash
|
|
|
|
|
lctrncs wrote: Thanks again. I hope you enjoy your "greetings seasons." Take the rest of the year off.
You're welcome! I wish I could take the rest of the year off but I am about to release my own
product (yeah, I said that last year at this time, and the year before...) which is 5 years
in the making. I have to get it out...this living as a "starving artist" thing is getting old.
At least I have the drums to beat out my aggressions
Anyway, I may have missed the point of what you were trying to achieve. If it's protecting
content then I would make the doc/view editors read-only and encrypt the content files so they
can't be edited outside of your application. There's always a solution (I refuse to ever be
convinced otherwise).
Best of luck (or "break a leg"?) on your writing projects!
Mark Salsbery
|
|
|
|
|
Drums!?
My little band needs a drummer badly. Do you like Pink Floyd? Do you live anywhere near Colorado?
When you get close with your product, send me a version and I will happily test it for you. I once turned down a full time job teaching college for a six-week gigue testing network protocol analyzers for HP. I stayed a year and a half, then came back as a full consultant. Those were the days! Testing is specialty of mine and since you have been so helpful, I would gladly punish your software for you. Bwaahahahahhaaaa!
If you send me your email address through that web site I sent you to, we can both avoid public postings.
Best of luck.
Groff
PS: Thanks for the heads up on the download error. I experienced the same thing and learned that the problem occurs when the complete file does not download. It is about 5.5 meg, so it is probably easy to try to start early. I will probably put up a little warning page in my "free time." GS
"For a successful technology, reality must take precedence over public relations, for nature cannot be fooled." Richard Feynman, Minority Report to the Official Report on the Space Shuttle Challenger Crash
|
|
|
|
|
BOOL CStudyPartnerDoc::OnSaveDocument(LPCTSTR lpszPathName)
{
StudyPartnerDocFile.SeekToBegin();
... should be
BOOL CStudyPartnerDoc::OnSaveDocument(LPCTSTR lpszPathName)
{
StudyPartnerDocFile.SetLength(0LL);
StudyPartnerDocFile.SeekToBegin();
...
|
|
|
|
|
I downloaded the free demo...is that the right one?
I get the following error in a messagebox:
<exe path="">\Setup.ini
Invalid Database.
The Installation will be cancelled.
|
|
|
|
|
The Win32 CreateFile function's dwShareMode parameter can be use to control this without the need to mutexes. Passing in a value of 0 should do the trick.
Steve
|
|
|
|
|
Thank you for responding.
Won't this collide with my existing code for opening files?
"For a successful technology, reality must take precedence over public relations, for nature cannot be fooled." Richard Feynman, Minority Report to the Official Report on the Space Shuttle Challenger Crash
|
|
|
|
|
Thank you for the nice clue.
Including a CreateFile function passing a dwSharedMode 0 in my OnOpenDocument allows me to open a file when I use the lpszPathName of OnOpenDocument as the first argument in the CreateFile function.
If I then try to open the file a second time using a different instance of my app, a "sharing violation" message appears.
If I try to save the first instance of the file using the first instance of my app, a First Chance Exception occurs that passes "access denied" back to the program.
I have tried various file attributes, but am probably doing something more basic wrong.
Any suggestions?
"For a successful technology, reality must take precedence over public relations, for nature cannot be fooled." Richard Feynman, Minority Report to the Official Report on the Space Shuttle Challenger Crash
|
|
|
|
|
lctrncs wrote: If I try to save the first instance of the file using the first instance of my app, a First Chance Exception occurs that passes "access denied" back to the program.
Try to find out where this exception is coming from. First you need to find out the kind of exception (first chance is not an exception type; it just means the debugger is being given the change to process to exception before the application gets its turn). Once you know that you need to setup your debugger to break on this exception so you can see where it’s coming from. On MSVC 6 this is done via the “Debug”->”Exceptions…” menu item which is accessible while an application is being debugged. Try to set this option as late as possible before you trigger the fault.
Steve
|
|
|
|
|
Please,
is there anybody who can show me how can I put a group box control over the tab control, and to have a caption of the group box to be transparent, not gray. I don't use MFC, I use ATL so I am working with the SendDlgItemMessage, but it doesn't matter, as everything boils down to messages anyways. I use manifest files, so controls are XP-like.
Thank you.
|
|
|
|
|
A group box control without a caption. Isn't that just a rectangle?
And what does "over the tab control" mean? On Top (Z order)? Please don't make up new technical terms, there are enough already.
led mike
|
|
|
|
|
No, it is not that. A group box has a caption, but I don't want a gray background for it.
|
|
|
|
|
So you are saying if you put a group box in a standard white window the caption has a gray background? That's nasty. I see Michael Dunn has given you the answer. Give him a 5 for that.
led mike
|
|
|
|
|
Remember, led mike, you can give a man a gift certificate for a filet-o-fish and he'll eat for a
day. Get a man a job at McDonalds and he'll have an employee discount for life.
I think that's how the saying goes...
|
|
|
|
|
led mike
|
|
|
|
|
You cold resize/reposition the tab control to fit in the group box.
Making the groupbox text transparent is tough. Ownerdraw may help but it seems easier to just
draw a frame and the text.
I don't use ATL, I use MFC so I can't provide an example.
Mark
|
|
|
|
|
Yeah....this is why more and more businesses are dumping Visual C++...this is something that C# or VB programmers are not even thinking about, they just put it on the window and concentrate on the more important business logic.
|
|
|
|
|
Yeah, I can only dream of using those fancy new Windows controls they have in C# and VB.
|
|
|
|
|
Yeah non-software companies usually use VB for their internal programming and software companies usually do not use VB for their products.
Microsoft could have provided for VC the conveniences they provided for VB but they just did not.
Many things are easier in VB but when we need to do things that VB is not designed to do then VB is more difficult.
|
|
|
|
|
That is fine, but we could just have at least the basic functionality, not to bother with the transparency of static controls, for goodness sake.
Sarajevo, Bosnia
|
|
|
|
|
Set the Transparent style bit on the group box (WS_EX_TRANSPARENT ).
|
|
|
|
|
If only they had implemented it in the text part of the control. What's interesting is the part
inside the box is transparent with or without that style set
|
|
|
|
|
Yeah, the group box has weird behavior when themes are on in XP (maybe Vista too? not sure about that)
|
|
|
|
|
I truly believe that with Vista we'll encounter a whole new set of problems with even the most common controls.
Sarajevo, Bosnia
|
|
|
|