hello :)

i'm using MFC SDI, & i'm less familiar to it.

i need to know,

1: i have found a way of printing a string as

pDC->DrawText( " Task still pending!!! ", &rect , DT_PATH_ELLIPSIS );

but i want to know, how can i print a 2D-Array in MFC SDI?

2: i've included a Dialog Box aswell. but how can i access the variables of my "xyzView.cpp" file in the Dialog Box button fuctions?

Thanks :)

5 Years
Discussion Span
Last Post by Ancient Dragon

>>how can i access the variables of my "xyzView.cpp" file in the Dialog Box

CDocument class contains a linked list of CView classes. So first you have to get a pointer to CWinApp by calling AFX::GetApp(), then from that pointer get a pointer to CDocument using its GetNextDocumenTemplate() method. Since MFC is just c++ you will have to make sure that the variables have public access in CWin class by either making the variables public or having public getter and setter methods.

>>but i want to know, how can i print a 2D-Array in MFC SDI?

Similar to the way you would with cout but you have to covert the data to a string first. cout makes that conversion for you -- in MFC you have to do it yourself. You can use any of the standard C or C++ functions to do that.Formatting the string is the easy part -- calculating the exact pixel location where it is to be printed may be more problematic.

Edited by Ancient Dragon: n/a


Forgot to mention that CString has a Format() method which works very similar to sprintf() that you can use to format int to strings.

Edited by Ancient Dragon: n/a


Ancient, i'm working with graphs (points & lines) in SDI. in my "xyzView.cpp", i need to print a 2D array within SDI, where my graphs are visible. as i can print a string above my graph, using

pDC->DrawText( " Fully Connected: ", &rect , DT_PATH_ELLIPSIS );

now how can i print a 2D integer array, even along with casting each digit to character?
does "cout" of iostream works?


>>does "cout" of iostream works?

No. You have to create the strings and use DrawText() to display them where you want them. How big is that 2d array? Now many columns and how many rows.

Lets say the array is declare as int array[5][2]; Then create the string something like this:

CString line;
for(int row = 0; row < 5; row++)
   for(int column = 0; column < 2; column++)
        line.Format("%d", array[row][column];
        // calculate the pixel location not shown here
        pDC->DrawText(line.GetBuffer(), ... );
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.