Doc /View Debugging.
-
As the dispute continues between me and doc/view, I'm posting my next rant/questions. [The sample I'm talking about is simply the wizard generated SDI executable, without touching the keyboard. So the perfect default application in VS2005] Ok, first off, How do I debug a document application, for example an SDI, When I click on "Save" from the menu, where does the command land? More importantly, How do I see it? Where should I keep the break point. just blows my mind. Second, When you click on "save" it goes through Serialize() function [God only knows how it gets called], and when you check for "IsStoring()" that says true and hence..save. BUT, When I open a document, It doesn't go through the Serialize method. WTH?? It's been clearly said in the book. If "IsStoring()" is false, it means you are opening a document.
Serialize(CArchive& ar)
{
if (ar.IsStoring())
{
AfxMessageBox("Saving");
// TODO: add storing code here
}
else
{
AfxMessageBox("Loading");// Never gets called.
//Doesn't even enter the function.
// TODO: add loading code here
}
}Third, And on what basis, do these handlers exist in the file where CMyApp theApp object exists. Where is the handler for "OnFileSave"? Why is it not transparent? Why do they need to show only New & Open option here? Do you agree with me, they are least intuitive when it comes to Doc/View? :sigh:
ON\_COMMAND(ID\_FILE\_NEW, &CWinApp::OnFileNew) ON\_COMMAND(ID\_FILE\_OPEN, &CWinApp::OnFileOpen)
Thanks.
-
As the dispute continues between me and doc/view, I'm posting my next rant/questions. [The sample I'm talking about is simply the wizard generated SDI executable, without touching the keyboard. So the perfect default application in VS2005] Ok, first off, How do I debug a document application, for example an SDI, When I click on "Save" from the menu, where does the command land? More importantly, How do I see it? Where should I keep the break point. just blows my mind. Second, When you click on "save" it goes through Serialize() function [God only knows how it gets called], and when you check for "IsStoring()" that says true and hence..save. BUT, When I open a document, It doesn't go through the Serialize method. WTH?? It's been clearly said in the book. If "IsStoring()" is false, it means you are opening a document.
Serialize(CArchive& ar)
{
if (ar.IsStoring())
{
AfxMessageBox("Saving");
// TODO: add storing code here
}
else
{
AfxMessageBox("Loading");// Never gets called.
//Doesn't even enter the function.
// TODO: add loading code here
}
}Third, And on what basis, do these handlers exist in the file where CMyApp theApp object exists. Where is the handler for "OnFileSave"? Why is it not transparent? Why do they need to show only New & Open option here? Do you agree with me, they are least intuitive when it comes to Doc/View? :sigh:
ON\_COMMAND(ID\_FILE\_NEW, &CWinApp::OnFileNew) ON\_COMMAND(ID\_FILE\_OPEN, &CWinApp::OnFileOpen)
Thanks.
grassrootkit wrote:
Ok, first off, How do I debug a document application, for example an SDI, When I click on "Save" from the menu, where does the command land? More importantly, How do I see it? Where should I keep the break point. just blows my mind.
Look at the message maps - they tell you where the messages go. Also, pop a breakpoint on your Serialize method and look at the call stack - that shows you where the message has been routed.
grassrootkit wrote:
Second, When you click on "save" it goes through Serialize() function [God only knows how it gets called], and when you check for "IsStoring()" that says true and hence..save. BUT, When I open a document, It doesn't go through the Serialize method. WTH?? It's been clearly said in the book. If "IsStoring()" is false, it means you are opening a document
The reason an open command might not land on your Serialize method is because you're re-opening the currently open document - that's certainly what I've found. MFC detects that case and performs no action (unless, I suspect, you've altered the document since you last saved it).
grassrootkit wrote:
And on what basis, do these handlers exist in the file where CMyApp theApp object exists. Where is the handler for "OnFileSave"? Why is it not transparent? Why do they need to show only New & Open option here? Do you agree with me, they are least intuitive when it comes to Doc/View?
The handlers live with your app because you may have multiple documents and document types - the app attempts to determine what type of document you're opening before opening the document and asking it to load the file - even if you only have one document type and one document. Yes, it can be obscure. The best way to approach MFC is to just go with the MFC flow and accept that it does loads of weird shit. Or try and work through a copy of MFC Internals[^]. And then accept that MFC's going to do what MFC does :-)
Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p
-
grassrootkit wrote:
Ok, first off, How do I debug a document application, for example an SDI, When I click on "Save" from the menu, where does the command land? More importantly, How do I see it? Where should I keep the break point. just blows my mind.
Look at the message maps - they tell you where the messages go. Also, pop a breakpoint on your Serialize method and look at the call stack - that shows you where the message has been routed.
grassrootkit wrote:
Second, When you click on "save" it goes through Serialize() function [God only knows how it gets called], and when you check for "IsStoring()" that says true and hence..save. BUT, When I open a document, It doesn't go through the Serialize method. WTH?? It's been clearly said in the book. If "IsStoring()" is false, it means you are opening a document
The reason an open command might not land on your Serialize method is because you're re-opening the currently open document - that's certainly what I've found. MFC detects that case and performs no action (unless, I suspect, you've altered the document since you last saved it).
grassrootkit wrote:
And on what basis, do these handlers exist in the file where CMyApp theApp object exists. Where is the handler for "OnFileSave"? Why is it not transparent? Why do they need to show only New & Open option here? Do you agree with me, they are least intuitive when it comes to Doc/View?
The handlers live with your app because you may have multiple documents and document types - the app attempts to determine what type of document you're opening before opening the document and asking it to load the file - even if you only have one document type and one document. Yes, it can be obscure. The best way to approach MFC is to just go with the MFC flow and accept that it does loads of weird shit. Or try and work through a copy of MFC Internals[^]. And then accept that MFC's going to do what MFC does :-)
Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p
Thanks for your reply. You continue to help me- that's great. :-D I just figured out, I was trying to open a file of 0 size. I didn't think it's an empty one. I had a bunch of test files and all those that happened to be my test cases where of 0 sizes. :doh: . These aren't passing through serialize method - a great finding :D lol
Stuart Dootson wrote:
try and work through a copy of MFC Internals[^]
Looks like I badly need one. The explanations given in start up MFC books are really insufficient. As the topics are wide, they quickly move to explain the next one. I think this one you just pointed out would talk more :) thanks Stuart :)
-
grassrootkit wrote:
Ok, first off, How do I debug a document application, for example an SDI, When I click on "Save" from the menu, where does the command land? More importantly, How do I see it? Where should I keep the break point. just blows my mind.
Look at the message maps - they tell you where the messages go. Also, pop a breakpoint on your Serialize method and look at the call stack - that shows you where the message has been routed.
grassrootkit wrote:
Second, When you click on "save" it goes through Serialize() function [God only knows how it gets called], and when you check for "IsStoring()" that says true and hence..save. BUT, When I open a document, It doesn't go through the Serialize method. WTH?? It's been clearly said in the book. If "IsStoring()" is false, it means you are opening a document
The reason an open command might not land on your Serialize method is because you're re-opening the currently open document - that's certainly what I've found. MFC detects that case and performs no action (unless, I suspect, you've altered the document since you last saved it).
grassrootkit wrote:
And on what basis, do these handlers exist in the file where CMyApp theApp object exists. Where is the handler for "OnFileSave"? Why is it not transparent? Why do they need to show only New & Open option here? Do you agree with me, they are least intuitive when it comes to Doc/View?
The handlers live with your app because you may have multiple documents and document types - the app attempts to determine what type of document you're opening before opening the document and asking it to load the file - even if you only have one document type and one document. Yes, it can be obscure. The best way to approach MFC is to just go with the MFC flow and accept that it does loads of weird shit. Or try and work through a copy of MFC Internals[^]. And then accept that MFC's going to do what MFC does :-)
Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p
Stuart Dootson wrote:
Also, pop a breakpoint on your Serialize method and look at the call stack - that shows you where the message has been routed.
Hmm, as you see in my case, it will not get into the serialize method. So I cannot put a break point anywhere and so can't catch the call stack. A the worst case would be the "Save". I do not find any message map for "save". It would have been much difficult if it malfunctioned during save, I do not have a visible handler and it doesn't go through Serialize method. It'd be clueless, but anyway no problem yet with Save command. Okay now , I see the handler for "OnOpen" command. But as you know it did not get into serialize method, I cannot put a break point there. If I want to see where the control goes, which file should I open to put the break point? In short,where will CWinApp::OnFileOpen() be defined? ON_COMMAND(ID_FILE_NEW, &CWinApp::OnFileNew) ON_COMMAND(ID_FILE_OPEN, &CWinApp::OnFileOpen) Please hold on till I get the book :rolleyes:
-
Stuart Dootson wrote:
Also, pop a breakpoint on your Serialize method and look at the call stack - that shows you where the message has been routed.
Hmm, as you see in my case, it will not get into the serialize method. So I cannot put a break point anywhere and so can't catch the call stack. A the worst case would be the "Save". I do not find any message map for "save". It would have been much difficult if it malfunctioned during save, I do not have a visible handler and it doesn't go through Serialize method. It'd be clueless, but anyway no problem yet with Save command. Okay now , I see the handler for "OnOpen" command. But as you know it did not get into serialize method, I cannot put a break point there. If I want to see where the control goes, which file should I open to put the break point? In short,where will CWinApp::OnFileOpen() be defined? ON_COMMAND(ID_FILE_NEW, &CWinApp::OnFileNew) ON_COMMAND(ID_FILE_OPEN, &CWinApp::OnFileOpen) Please hold on till I get the book :rolleyes:
The SAVE message map should be in your doc class. As I said, I found the serialize method is invoked when you open a different file than the one you currently have open (I saved a file called a.a then re-opened it - MFC detects that condition and doesn't re-open). CWinApp is in the MFC source - I can't remember off the top of my head which file and I haven't got enugh battery to open VMWare Fusion (I use OS X normally) at thh moment :-) Still - go into the MFC source directory and grep for OnFileOpen.
Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p
-
The SAVE message map should be in your doc class. As I said, I found the serialize method is invoked when you open a different file than the one you currently have open (I saved a file called a.a then re-opened it - MFC detects that condition and doesn't re-open). CWinApp is in the MFC source - I can't remember off the top of my head which file and I haven't got enugh battery to open VMWare Fusion (I use OS X normally) at thh moment :-) Still - go into the MFC source directory and grep for OnFileOpen.
Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p
Stuart Dootson wrote:
The SAVE message map should be in your doc class.
Oops! You are right.
Stuart Dootson wrote:
As I said, I found the serialize method is invoked when you open a different file than the one you currently have open (I saved a file called a.a then re-opened it - MFC detects that condition and doesn't re-open).
I knew my question was not clear this time.Sorry. Actually I understood what you said in your last reply. I was talking in context with the 0 size files. "Assuming I'm opening the 0 size file" and trying debugging, trying to catch the call stack. etc. Anyway helped enough already.
Stuart Dootson wrote:
CWinApp is in the MFC source - I can't remember off the top of my head which file and I haven't got enugh battery to open VMWare Fusion (I use OS X normally) at thh moment Smile Still - go into the MFC source directory and grep for OnFileOpen.
Oh! okay :) No probs. You are clever to move out of windows :rolleyes: .
-
Stuart Dootson wrote:
The SAVE message map should be in your doc class.
Oops! You are right.
Stuart Dootson wrote:
As I said, I found the serialize method is invoked when you open a different file than the one you currently have open (I saved a file called a.a then re-opened it - MFC detects that condition and doesn't re-open).
I knew my question was not clear this time.Sorry. Actually I understood what you said in your last reply. I was talking in context with the 0 size files. "Assuming I'm opening the 0 size file" and trying debugging, trying to catch the call stack. etc. Anyway helped enough already.
Stuart Dootson wrote:
CWinApp is in the MFC source - I can't remember off the top of my head which file and I haven't got enugh battery to open VMWare Fusion (I use OS X normally) at thh moment Smile Still - go into the MFC source directory and grep for OnFileOpen.
Oh! okay :) No probs. You are clever to move out of windows :rolleyes: .
grassrootkit wrote:
I knew my question was not clear this time.Sorry. Actually I understood what you said in your last reply. I was talking in context with the 0 size files. "Assuming I'm opening the 0 size file" and trying debugging, trying to catch the call stack. etc. Anyway helped enough already.
(Back on AC now!) You're quite right - it doesn't bother calling serialize for zero byte files - makes sense, I guess.
Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p