I want to ask about how to use startdoc(), startpage() to print data on paper imediately then receive the next data and print imediately and receive the next data and print ......

Example : If I want to print this below data in first page imediately and after that I receive the other data and print imediately not like Microsoft word which must receive all data and print 1 time.

110011110

How to do that loop?

This below is my program want to do that.

If first data is 110011110

I change 1 in the above data to solid black (which have 2 pixel width and 4 pixel height) and 0 in the above data to solid white (which have 2 pixel width and 4 pixel height)

code:
------------------------------------------------------------

DOCINFO di ;
CPrintInfo printInfo ;
CString filename ;
CDC dc ;
CRect draw_area ;
CPrintDialog dlg(FALSE) ;

if (Dlg.DoModal() == IDCANCEL)
return ;

HDC hDC = dlg.GetPrinterDC() ;
if (hDC == NULL)
return ;

di.cbSize = sizeof(DOCINFO) ;
di.lpszDocName = "Document name"
di.lpszOutput = NULL ;

// prepare the print information structure
dc.Attach(hDC) ;
printInfo.m_bDirect = TRUE ;
printInfo.m_rectDraw.left = 0 ;
printInfo.m_rectDraw.right = dc.GetDeviceCaps(HORZRES) ;
printInfo.m_rectDraw.top = 0 ;
printInfo.m_rectDraw.bottom = dc.GetDeviceCaps(VERTRES) ;
draw_area = printInfo.m_rectDraw ;

dc.StartDoc(&di) ;

//receive first data
CString testline = "110011110" ;

int x = 0 ;
int y = 0 ;
int pos = 0 ;
// start printing the document

dc.StartPage() ;

CBrush brush;

// Creation of the brush with a black color

brush.CreateSolidBrush(RGB(0, 0, 0));

while (pos < testline.GetLength())
{
if ((testline.GetAt(pos)) == '1')
{

// Create a rectangle with coordinates x,y,x+2,y+4 corresponding with top, left, bottom, right
CRect Rectangle(x, y, x + 2, y + 4) ;

// Fill a rectangle in the current device context or DC
dc.FillRect(&Rectangle , &brush);

x += 2;
}

else if ((testline.GetAt(pos)) == '0'){

x += 2;
}
pos++ ;
}
y += 4 ;
x = 0 ;
pos = 0 ;

dc.EndPage() ;
printInfo.m_rectDraw = draw_area ;

//OnEndPrinting(&dc, &printInfo);
dc.EndDoc() ;
VERIFY(dc.DeleteDC()) ;

------------------------------------------------------------