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 :)

>>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.

Thanks Ancient :)

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

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(), ... );
   }
}
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.