Computing.Net > Forums > Programming > Ask about FillRect() and print data in t

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

Ask about FillRect() and print data in t

Reply to Message Icon

Name: ooosawaddee3
Date: July 25, 2002 at 22:00:45 Pacific
Comment:


I want to print data in text file out to the paper
If my data in text file is

110011110

I want to 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)

This below is code but it does not work. The printer do not print anything.What wrong with my code?

void CTestprint::OnPrintButton()
{
DOCINFO di ;
CPrintInfo printInfo ;

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

CString testline = "101101001" ;

int x = 0 ;
int y = 0 ;
int pos = 0 ;

// start printing the document

dc.StartPage() ;

while (pos < testline.GetLength())
{
if ((testline.GetAt(pos)) == 1)
{
CBrush brush;

// Creation of the brush with a black color

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

// 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;
}

// fall through to '0' which just moves the position
else if ((testline.GetAt(pos)) == 0){
x += 2 ;
}
pos++ ;
}
y += 4 ;
x = 0 ;
pos = 0 ;

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

dc.EndDoc() ;
VERIFY(dc.DeleteDC()) ;
}



Sponsored Link
Ads by Google

Response Number 1
Name: Jeff J
Date: July 26, 2002 at 13:09:53 Pacific
Reply:

I haven't gone through this thoroughly, but you are comparing the characters '0' and '1' to the integers 0 and 1, after calling testline.GetAt(pos). It's a common mishap, because characters are integers too, so no error occurs. Post back if that doesn't resolve it.

Cheers



0
Reply to Message Icon

Related Posts

See More


OM19.dll Executing PHP on Server



Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Programming Forum Home


Sponsored links

Ads by Google


Results for: Ask about FillRect() and print data in t

Batch Printing in HTML www.computing.net/answers/programming/batch-printing-in-html/3648.html

Printing RTF in Batch uses Defaults www.computing.net/answers/programming/printing-rtf-in-batch-uses-defaults/17104.html

Simple design questions in C++ www.computing.net/answers/programming/simple-design-questions-in-c/4384.html