I want to add a line to my text in notepad when printing a pdf, for these purpose I hook Enddoc function and use GDILineTo()
. but when I print my text, the LineTo()
creates new page at the end of pdf and draws Line in it. does any body knows how can I draw line in all pdf pages without create new page ?
here is my code:
int StopPrint::hookFunction(HDC hdc, const DOCINFOW *lpdi)
{
HPEN hPen1 = CreatePen(PS_SOLID, 1, BLACK_PEN);
HGDIOBJ l = hPen1;
HPEN holdPen = (HPEN)SelectObject(hdc, l);
SelectObject(hdc, hPen1);
MoveToEx(hdc, 500, 500, NULL);
LineTo(hdc, 2000, 2000);
return getOriginalFunction()(hdc, lpdi);
}
CodePudding user response:
I've no idea if this will work or quite what you're up to, but I think you need to 'hook' EndPage
rather than EndDoc
. Also, your hook function is broken in various ways so try this:
int StopPrint::EndPageHook(HDC hdc)
{
HPEN holdPen = (HPEN) SelectObject(hdc, GetStockObject (BLACK_PEN));
POINT old_pos;
MoveToEx(hdc, 500, 500, &old_pos);
LineTo(hdc, 2000, 2000);
MoveToEx(hdc, old_pos.x, old_pos,y, NULL);
SelectObject(hdc, holdPen);
return getOriginalEndPage()(hdc);
}
Pretty weird line BTW, that looks wrong to me. Might want to start from (something derived from) the current position, see what you get.