|
Thanks for your replies again. I've done those changes you suggested. Now the reading part moved to document. but I'm still calling the document's reading functions from the view. Is that ok? Please find below ,In the CmyCView::OnOpen function,
<br />
CmyCView::OnOpen()<br />
{<br />
CFileDialog dlg(TRUE,NULL,NULL,NULL,szFilter);<br />
CSDITestDoc* pDoc = GetDocument();<br />
if (dlg.DoModal() == IDOK)<br />
{<br />
pDoc->readFile((LPCTSTR)dlg.GetPathName());<br />
}<br />
CString str = pDoc->getText().c_str();<br />
CEdit& ced = GetEditCtrl();<br />
ced.SetWindowTextA(str);<br />
}<br />
So far so good, some queries regarding the below comment:
Stuart Dootson wrote: You should probably do that in the OnUpdate handler - that should get called when the document is updated, by the document calling its UpdateAllViews method (that's part of CView).
The only interface between the user & the document object(here a text content) is the CEditview, where the user modifies the text and when he saves, it's going be View->to->Doc. And it's going to be one way. Where does your comment fit in? I can't get the picture.. How does the document get modified by itself so that it updates the view from there? May be you are talking about multiple view?
Question No 2:
I guessed about a scenario where , as you said the document gets modified from an external window, may be another dialog. So added a dialog. Now I dont have any clue how do I get the document pointer into my Dialog? looks like I'm on the other end of the river..
|
|
|
|
|
I've just created a tiny MFC SDI app (using VS2008) to test this out.
To hold the text you're editting, I added a member to my document class, plus an accessor function.
public:
CString const& GetText() const { return text_; }
protected:
CString text_;
To read/write a file, I added functionality to the document's Serialize method:
void CdddDoc::Serialize(CArchive& ar)
{
if (ar.IsStoring())
{
ar.Write(text_, text_.GetLength());
}
else
{
const UINT fileSize = (UINT)ar.GetFile()->GetLength();
CStringT<char, StrTraitMFC_DLL<char> > byteString;
ar.Read(byteString.GetBufferSetLength(fileSize), fileSize);
text_ = byteString;
UpdateAllViews(0);
}
}
The byteString stuff is because I had a file with ASCII text, while my app is Unicode, so I need to read the file into a 'byte per char' string and then convert to the standard CString .
Then I added an OnUpdate handler to my view, to set the view's text:
void CdddView::OnUpdate(CView* , LPARAM , CObject* )
{
SetWindowText(GetDocument()->GetText());
}
To update the document in line with the edit view, I'd add a method to the document class that would allow me to update the text somehow.
So, as you can see, by complying with the standard MFC doc/view framework, I've got plenty of functionality for very little effort!
Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p
|
|
|
|
|
Thanks a lot for the sample.. I'll try the same in my application.
|
|
|
|
|
Hi Stuart, I've put the logic in ::Serialize function. But how will I connect this function in "Open New file". The control flow is a bit unclear.
When I open a document, the first function that gets called is the below one.
The void CMyTestView::OnFileOpen()
{
..
}
Also in the document class, I've got,
BOOL CMyTestDoc::OnOpenDocument()
{
return TRUE;
}
Where should we call the ::Serialize() function?.
When I open a new file, what the functions happens/I should call. Can you please..just type down the function names. I'll figure out and end the conversation.
Like,
Open A new document:
1.
void CMyTestView::OnFileOpen()
{
}
2.
BOOL CSDITestDoc::OnOpenDocument()
{
return true;
}
3.
void CSDITestDoc::Serialize(CArchive& ar)
{
}
|
|
|
|
|
As I've said in my other reply - I think you should probably leave handling OnFileOpen to CWinApp , a) because it fits better with the model of responsibilities and collaborations the MFC doc/view framework was designed around, and b) it fits with MFC, so you don't need to write as much code!
Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p
|
|
|
|
|
|
grassrootkit wrote: But shouldn't that be view's OnFileOpen
Not necessarily - thanks to the wonders of command routing, OnFileOpen can be handled by many different things.
The best way to look at whether your view should be handling OnFileOpen is to think about what your view's responsibilities are - display a view of the document and feed back user interactions with that view. Document management (which is what opening a file counts as) isn't really the responsibility of the view.
It becomes clearer when you move to MDI, or if you have multiple views on a single document:
- An application has zero to many documents
- Each document is related to precisely one application, but can have one to many views
- Each view is related to precisely one document
HTH!
Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p
|
|
|
|
|
Why this doesn't write anything on the Edit window?
CEditViews handle things differently from CView?
void CSDITestView::OnDraw(CDC* /*pDC*/)
{
CSDITestDoc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
if (!pDoc)
return;
CString str = "Hello CEditWorld!";
CEdit& ced = GetEditCtrl();
ced.SetWindowTextA(str);
// TODO: add draw code for native data here
}
|
|
|
|
|
Damit OnDraw never gets called for CEditViews. .. Where I can I find a tutorial that clearly talks about a CEditView ? possibly with a notepad example.
|
|
|
|
|
Google[^] is your friend[^]
Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p
|
|
|
|
|
The content in CPP-Home is relatively good. But in all other places, they quickly move on to explain other inherited views. I hate them. I think too few people use SDI,CEdit views in this world . Thanks a lot for the explanation & link. I'll try to make use of the doc class. And will come back with another set of questions.
|
|
|
|
|
I just noticed that when running my application on vista with vista theme (aero glass on or off)
my CListCtrl doesnt hightlight the last selection item before it lost focus
even thought I enable "show selection always".
It still work when vista is set to use classsic style.
Is there any way to make "show selection always" work with vista theme with out custom draw the control myself ?
|
|
|
|
|
It probably is shown, but not very obviously. I've found previously that when a list loses focus, the selection is shown as very light grey, rather than the blue shading that's normally used.
Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p
|
|
|
|
|
hi
in visual studio 2005, i need to know whether a macro is defined when intellisense is processing the source so that i may distinguish between when the compiler is parsing the source code and when the intellisense is reading and processing it.
how it be useful? i need not to limit definitions of classes, variables, etc. for intellisense. although they may not be met sometimes when they're compiled, i need intellisense to meet them everytime. since there's only one definition of everything, there will be no conflict.
i hope i could describe what i'm looking for properly.
any idea?
|
|
|
|
|
If I understand what you're saying, you want Intellisense to see more than the compiler? Sounds bad to me, as then Intellisense would suggest things that wouldn't compile - which would be evil.
Anyway - don't think there's anything that does that (phew!).
Maybe if you gave a concrete example of what you want, we'd be able to understand better?
Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p
|
|
|
|
|
ur right about when there're more than one definition of something, say a macro definition. but when i KNOW that i may reach to a definition which exists ONLY ONCE in the whole of my code, not being able to find it by Intellisense is bad.
|
|
|
|
|
Thanks for looking at my question,
I am wondering how I would use the ToUpper and ToLower functions on only part of a string in .net C++.
For example, I converted an inputted name to all caps for the purpose of comparing it. Now I need to display the name with only the first letter capitalized.
In short, I need to make "BRAD" to "Brad"
Note that the inputted name is not always the same, so however you can show me how to do this has to work with any inputted name.
Thanks for any help!!
|
|
|
|
|
TabascoSauce wrote: .net C++
Are you talking about the C++ that uses System::String? If so, there's a forum[^] just for that variant of C++ (and it's not this one).
In general, though, you'd identify the sub-string that you want to convert, extract if from the string, convert it and then re-insert it into the string. HTH!
[edit]In MFC, I'd do it like this:
CString CapitaliseName(CString const& upperCaseName)
{
return upperCaseName.Left(1) + upperCaseName.Mid(1).MakeLower();
}
[/edit]
Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p
|
|
|
|
|
Thanks for the help, sorry about the wrong forum, I'll repost there.
|
|
|
|
|
TabascoSauce wrote: sorry about the wrong forum
No problem - BTW - have a look at the System::String docs - I have a feeling you'll find the same methods on that as I used on the MFC CString class....
Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p
|
|
|
|
|
I have a rich text edit control which I fill with a small amount of text at runtime. I've managed to slim the RTF down to:
{\rtf1\ansi\deff0{\fonttbl{\f0\fswiss\fcharset0 Segoe UI;}}
\viewkind4\pard\sa80\b\f0\fs24 Test string\par
\b0\fs16 Another string }
This displays the text in Segoe UI font. As this font is usually only available on Vista, I'd like to provide a list of font names in order of priority that the control would try to use in order until it found one that exists on the PC.
Is there a way to do this in the RTF description?
|
|
|
|
|
Don't think so - the RTF specification specifies that a single font name can be associated with a font number, not a set of fonts. Also, you can use only a single number when specifying a font in text, not a list.
I don't think RTF has any concept of font fallback.
Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p
|
|
|
|
|
Thanks. Is there a quick way of finding out if a particular font name exists on the PC? Then I could at least have two RTF strings, one using Segoe UI, and another using Trebuchet MS for when Segoe UI is not present?
|
|
|
|
|
|
Hello,
i need to sort out this problem:
"The bubble sort represented in fig 6.15 of your text book is inefficient for large arrays. Make the following simple modifications to improve the performance of the bubble sort.
After the first pass, the largest number is guaranteed to be in the highest-numbered element of the array; after the second pass, the two highest numbers are “in place,” and so on. Instead of making nine comparisons on every pass, modify the bubble sort to make eight comparisons on the second pass, seven on the third pass and so on."
Could someone check my code? I should get an output like this but i don't :
After pass 0: 2 4 6 8 10 12 68 45 37 89
After pass 1: 2 4 6 8 10 12 45 37 68
After pass 2: 2 4 6 8 10 12 37 45
After pass 3: 2 4 6 8 10 12 37
After pass 4: 2 4 6 8 10 12
After pass 5: 2 4 6 8 10
After pass 6: 2 4 6 8
After pass 7: 2 4 6
After pass 8: 2 4
There is something wrong with the loop...
Thanks a lot!!!
raeiko
#include <stdio.h>
#define SIZE 10
int main ( void )
{
int a[ SIZE ] = { 2, 6, 4, 8, 10, 12, 89, 68, 45, 37 };
int pass;
int i;
int hold;
int NumOfComparisons = 0;
printf( "Data items in original order:\n\n" );
for ( i = 0; i <SIZE; i++ ){
printf( "%4d", a[ i ] );
}
printf( "\n\n" );
for ( pass = 1; pass < 9; pass++ ){
for ( i = 0; i < 9 - pass; i++ ){
if ( a[ i ] > a[ i + 1] ){
hold = a[ i ];
a[ i ] = a[ i + 1];
a[ i + 1] = hold;
}
NumOfComparisons = NumOfComparisons + 1;
}
for ( i = 0; i < SIZE - pass; i++ ){
printf( "After pass %d: %4d\n", pass, a[ i ] );
printf( "\n " );
}
}
printf( "Data items in ascending order:\n\n" );
for ( i = 0; i < SIZE; i++ ){
printf( "%4d", a[ i ] );
}
printf( "\n\n" );
printf( "Number of comparisons: %d\n", NumOfComparisons );
return 0;
}
|
|
|
|
|