Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

View data as with old command-style window

Status
Not open for further replies.

graetzd

Technical User
Jun 29, 2001
17
US
Hello Tek-Tips Forum,

Before describing my problem I should give a short background. I
am a forest research scientist and my applications have been stictly
command window programs. I am now trying to learn some C++ and
MFC so I can build some simple front-end user interfaces for future
applications.

My first application has a simple design. I want to:
1) read in some data,
2) store that data,
3) print some initial info to the screen,
4) process the data,
5) and print final results to screen and disc.

I have been successful with #1 and #2 above. I can get a Open File dialog
box to open and then store the raw data into a CArray that
is associated with the main document. My difficulty is that I
cannot figure out how to print up the raw data onto the screen (or view
as it is).

Here are some relevant pieces:

a)
My program is a SDI and thus has only a single view. The idea is that
I would print up initial raw data to the screen (after I read it in
from disc) and that data would remain on the screen while it is
being processed (I don't care if the screen version is editable, but
for the time I will assume it can be). So what I have for my view class
is:

class CVerstraView : public CEditView
{
protected: // create from serialization only
CVerstraView();
DECLARE_DYNCREATE(CVerstraView)

// Attributes
public:
CVerstraDoc* GetDocument();

// Operations
public:

// Overrides
// ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(CVerstraView)
public:
virtual void OnDraw(CDC* pDC); // overridden to draw this view

//more MFC generated stuff that I am leaving out
}

Now, from what I can understand, my C++ and MFC books indicate that the
function OnDraw is called up every time the view needs updating. But
in my debugger, once I open my input data file, I never seem to enter
the OnDraw() function. So I'm a little confused. For this application
I simply wish to use my CVerstraView as I would an old command style
window. I just want to spit formatted data and strings out to it as
I would with printf() statements in c.

Could someone lead me in the right direction of how I can do this. I
apologize for the simplicity of the problem. I do have 3 decent books
on C++ and some on MFC but they are very poor in examples of how to
just get data in and out to the screen.

I thank you in advance for any help/advice and I am very appreciative
of this forum and the opportunity to seek out such help.

David H. Graetz






 
What about desig of your project as a Win32 console application and use of simply I/O streams or even functions like printf()?
 
The console application is one approach. Second, if you want a GUI, I would suggest creating a dialog based app because in my opinion it would be the easiest to learn with. On the dialog, add an Edit Control and a Button control. Right click that control and give it a better name if you wish but for now ICD_EDIT1 should be fine. Press ctrl-w to open the class wizard. Click on the member variables tab. Select your edit control and click add member. Add a new member var of type CString and name the varialble m_text. Click ok.

Now you should be back at the dialog. Double click on the button and you should see a message box pop up saying something like Add member function "OnButton1". Say yes or ok, whichever it the "Agree". It will take you into the code. Add the following code to OnButton1

OnButton1()
{
UpdateData(TRUE);
m_text += "Hello World\r\n";
UpdateData(FALSE);
}

That should now display Hello World (carriage return) on the dialog in the control. Any text that was already there will remain.

This should give you the basics of displaying text. I hope this helped... if not repost. As a side note, if this does not work, switch the updatedata calls. I am pretty sure the true and false are in the correct positions tho.

Matt
 
First of all, your assuption of the data being editable on the screen in a CView (or derived) class is wrong. It's just to display.

You're right about OnDraw being called whenever the view needs updating. However, since you're the one supplying the data, you're also the one that needs to let this know to the window. You need to call InvalidateRect and UpdateWindow for this.
Greetings,
Rick
 
Thank you all who have replied so far. I have this qustion posted on two forums and have received a few hints and indications that I need to elaborate a bit more.

My intention, for this application, is to learn about creating and using an SDI program. For that reason, I am not interested in creating a win-32 console application (I can already do that). But I am interested in creating an SDI that basically behaves as a win-32 console. I am also trying not to create a dialogue application.

Someone suggested some code to use within my OnDraw() function inside my CVerstraView class, but again, it appears as though the OnDraw() function is not even being called up because I never enter it when I debug.

Someone else suggested that I should not be overridding the OnDraw() function because my CVerstraView is derived from CEditVew and this seems like a good possibility. That person also suggested that I get the data from the screen, add additional data, then write the data back. I'm not sure if I understand that in the context of what I am trying to do. For one, I usually have hundreds of lines of data that contain many individual data values per line.

Here is some more information:

1) Again, my CVerstraView is derived from CEditView and I am not sure if that is necessary. My goal is simply to have a screen with some scrolling capability that I can spit data out to like an old win-32 console. I don't need to have edit capability of the data, but cut and paste ability would be nice.

2) Within my document class, CVerstraDoc, I have overridden the OnFileOpen() method. Currently my method works but when it gets to the end of my OnFileOpen() the program just stops, and thus, it doesn't make a call to OnDraw() and I'm not sure how to implement that. I have tried UpDateAllViews() at the end of my OnFileOpen() but that hasn't worked. For clarity, here is an abbreviated version of my OnFileOpen() method:

//********************************************************************************
void CVerstraDoc::OnFileOpen()
//********************************************************************************
{
/***************************************************************
When debugging, just use a default file - otherwise,
prompt for file input with a FILE OPEN box
****************************************************************/
#ifdef _DEBUG
this->m_strTitle = "D:\\WorkingPrograms\\Verstra\\OutputTest.trl";
#else
//This will construct the actual file open box - but not display it
CFileDialog dlgFile(TRUE, NULL, NULL, OFN_HIDEREADONLY,
"FVS Treelist (*.trl)|*.trl|AllFiles (*.*)|*.*||", NULL);

//This will display the file open box from which file can be selected
if (dlgFile.DoModal() == IDOK)
{
this->m_strTitle = dlgFile.GetPathName();
}
#endif //_DEBUG


/*************************************************
Count up how many unique cutlist files there are
**************************************************/
CountUniqueFiles();

/*************************************************
Prepare to serialize the data (load it up)
**************************************************/
/*
Code to serialize the data is not shown here - as
far as I can tell I am loading up the data OK
*/


UpdateAllViews(NULL); //tried this

}//end void CVerstraDoc::OnFileOpen() //program just stops here


So this is where I am stuck. I have lots of data sitting in arrays inside my document and I simply want to print that data out to the screen. I understand that creating an SDI may be overkill for this particular application but it's one that I can build on once I understand the framework.

If it makes more sense to derive my CVerstraView from a CView class instead of CEditView that would be good to understand.

So I leave it here for the next round of suggestions/help and once again, I thank everyone for their time and energy.

David G.
 
I have one word for you:

DeviceContext.

Oh, and another word:

Scribble.

if you do the scribble tutorial, it will help you learn how to set up the document view architecture.

You should then be able to modify it by removing everything to do with drawing strokes, and replace it using functions like DC->TextOut() to display text on the screen. You will of course have to manage exactly *where* the text goes on the screen.
 
David,

I read your post a bit too quickly...


Your assuption about the data being editable is right (hadn't noticeed you were using the CEditView class). I've never used this view, but if I'm not mistaking it's a mixture of CView and CEdit, meaning that it's derived from CView and has most of the functionalities of CEdit. Also, the "CEdit" part, is probably covering the entire area of the CView window (which is why you don't see anything, or OnDraw doesn't get fired). Because it has the same functionalities a CEdit, I think it should be controlled that way too. That is; use SetWindowText to show the text.
Greetings,
Rick
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top