{*******************************************************} { } { PrintHook } { } { Copyright (C) 2022 kku } { } {*******************************************************} unit PrintHook; interface uses System.SysUtils, System.Classes, Tocsg.DllEntry, Tocsg.CommonData, GlobalDefine, Winapi.Windows, Winapi.Messages, Winapi.ShellAPI, Tocsg.Trace, Vcl.Graphics, System.Generics.Collections, EM.GDIPAPI; const IGNORE_PROCESS = '1explorer.exe|taskmgr.exe|dropbox.exe|kakaotalk.exe|telegram.exe|' + 'regedit.exe|eCrmHomeEdition.exe|Everything.exe|Listary.exe|' + 'OpenWith.exe|conhost.exe|PrintMark.exe|Evernote.exe'; SMALL_FONT = 'chrome.exe|msedge.exe|Evernote.exe'; // START_PROCESS = 'excel.exe'; END_PROCESS = 'chrome.exe|msedge.exe|Honeyview.exe|POWERPNT.EXE|' + // 'ApplicationFrameHost.exe|' + 'mspaint.exe|Acrobat.exe|Evernote.exe'; WORD_GAP = ' '; CaptureBlt = $40000000; type TPrintHook = class(TTgDllEntry) private SharedData_: TTgFileMapping; Trace_: TTgTrace; dtCreate_: TDateTime; hProcWnd_: HWND; hWndHook_, hMsgHook_, hCbtHook_, hShellHook_: HHook; sCurDocName_, sPtrText_, sImgPath_, sLogPath_: String; bIsStartPage_, bIsPrinting_, bIsWaterMaking_, bInitOk_, bBlockDrop_, bEndDocProc_, bSmallFont_: Boolean; OFList_: TStringList; // DcFileH_: TDictionary; CurPtrDC_: HDC; nPtrCnt_: Integer; PtrBmp_: TBitmap; ProcList_: TList; procedure Log(sLog: String); procedure DoInterceptCreate; procedure DoInterceptRemove; function InstallHook: Integer; function UnInstallHook: Integer; function GetActive: Boolean; function GetRcvWnd: LONGLONG; function GetText: String; function GetImagePath: String; function GetFontSize: Integer; function GetLineCount: Integer; procedure SetPtrInfo(sInfo: String); procedure SetCurDocName(sName: String); public Constructor Create; Destructor Destroy; override; function IsAblePrintDrawCopy: Boolean; property Active: Boolean read GetActive; property RcvWnd: LONGLONG read GetRcvWnd; property Text: String read GetText; property ImagePath : String read GetImagePath; property FontSize: Integer read GetFontSize; property LineCount: Integer read GetLineCount; property PtrInfo: String write SetPtrInfo; property CurDocName: String read sCurDocName_ write SetCurDocName; end; TFun_CreateFileA = function(lpFileName: PAnsiChar; dwDesiredAccess, dwShareMode: DWORD; lpSecurityAttributes: PSecurityAttributes; dwCreationDisposition, dwFlagsAndAttributes: DWORD; hTemplateFile: THandle): THandle; stdcall; TFun_CreateFileW = function(lpFileName: PWideChar; dwDesiredAccess, dwShareMode: DWORD; lpSecurityAttributes: PSecurityAttributes; dwCreationDisposition, dwFlagsAndAttributes: DWORD; hTemplateFile: THandle): THandle; stdcall; TFun_CloseHandle = function(hObject: THandle): BOOL; stdcall; TFun_StartDocA = function(dc: HDC; pDocInfo: PDocInfoA): Integer; stdcall; TFun_StartDocW = function(dc: HDC; pDocInfo: PDocInfoW): Integer; stdcall; TFun_HDC = function(dc: HDC): Integer; stdcall; TFun_DragQueryFileA = function(Drop: HDROP; FileIndex: UINT; FileName: LPSTR; cb: UINT): UINT; stdcall; TFun_DragQueryFileW = function(Drop: HDROP; FileIndex: UINT; FileName: LPWSTR; cb: UINT): UINT; stdcall; TFun_DrawTextA = function(hDC: HDC; lpString: LPCSTR; nCount: Integer; var lpRect: TRect; uFormat: UINT): Integer; stdcall; TFun_DrawTextW = function(hDC: HDC; lpString: LPCWSTR; nCount: Integer; var lpRect: TRect; uFormat: UINT): Integer; stdcall; TFun_DrawTextExA = function(DC: HDC; lpchText: LPCSTR; cchText: Integer; var p4: TRect; dwDTFormat: UINT; DTParams: PDrawTextParams): Integer; stdcall; TFun_DrawTextExW = function(DC: HDC; lpchText: LPCWSTR; cchText: Integer; var p4: TRect; dwDTFormat: UINT; DTParams: PDrawTextParams): Integer; stdcall; TFun_ExtTextOutA = function(DC: HDC; X, Y: Integer; Options: Longint; Rect: PRect; Str: LPCSTR; Count: Longint; Dx: PInteger): BOOL; stdcall; TFun_ExtTextOutW = function(DC: HDC; X, Y: Integer; Options: Longint; Rect: PRect; Str: LPCWSTR; Count: Longint; Dx: PInteger): BOOL; stdcall; TFun_TextOutA = function(DC: HDC; X, Y: Integer; Str: LPCSTR; Count: Integer): BOOL; stdcall; TFun_TextOutW = function(DC: HDC; X, Y: Integer; Str: LPCWSTR; Count: Integer): BOOL; stdcall; TFun_PolyTextOutA = function(DC: HDC; const PolyTextArray; Strings: Integer): BOOL; stdcall; TFun_PolyTextOutW = function(DC: HDC; const PolyTextArray; Strings: Integer): BOOL; stdcall; TFun_TabbedTextOutA = function(hDC: HDC; X, Y: Integer; lpString: LPCSTR; nCount, nTabPositions: Integer; var lpnTabStopPositions; nTabOrigin: Integer): Longint; stdcall; TFun_TabbedTextOutW = function(hDC: HDC; X, Y: Integer; lpString: LPCWSTR; nCount, nTabPositions: Integer; var lpnTabStopPositions; nTabOrigin: Integer): Longint; stdcall; TFun_SetWindowTextA = function(hWnd: HWND; lpString: LPCSTR): BOOL; stdcall; TFun_SetWindowTextW = function(hWnd: HWND; lpString: LPCWSTR): BOOL; stdcall; TFun_MessageBoxA = function(hWnd: HWND; lpText, lpCaption: LPCSTR; uType: UINT): Integer; stdcall; TFun_MessageBoxW = function(hWnd: HWND; lpText, lpCaption: LPCWSTR; uType: UINT): Integer; stdcall; TFun_MessageBoxExA = function(hWnd: HWND; lpText, lpCaption: LPCSTR; uType: UINT; wLanguageId: Word): Integer; stdcall; TFun_MessageBoxExW = function(hWnd: HWND; lpText, lpCaption: LPCWSTR; uType: UINT; wLanguageId: Word): Integer; stdcall; TFun_BitBlt = function(DestDC: HDC; X, Y, Width, Height: Integer; SrcDC: HDC; XSrc, YSrc: Integer; Rop: DWORD): BOOL; stdcall; TFun_StretchBlt = function(DestDC: HDC; X, Y, SrcWidth, SrcHeight: Integer; SrcDC: HDC; XSrc, YSrc, DestWidth, DestHeight: Integer; Rop: DWORD): BOOL; stdcall; TFun_TransparentBlt = function(DestDC: HDC; X, Y, DestWidth, DestHeight: Integer; SrcDC: HDC; XSrc, YSrc, SrcWidth, SrcHeight: Integer; dwTransparent: DWORD): BOOL; stdcall; TFun_StretchDIBits = function(DC: HDC; DestX, DestY, DestWidth, DestHeight, SrcX, SrcY, SrcWidth, SrcHeight: Integer; Bits: Pointer; var BitsInfo: TBitmapInfo; Usage: UINT; Rop: DWORD): Integer; stdcall; TFun_SetDIBitsToDevice = function(DC: HDC; DestX, DestY: Integer; Width, Height: DWORD; SrcX, SrcY: Integer; nStartScan, NumScans: UINT; Bits: Pointer; var BitsInfo: TBitmapInfo; Usage: UINT): Integer; stdcall; TFun_PatBlt = function(DC: HDC; X, Y, Width, Height: Integer; Rop: DWORD): BOOL; stdcall; TFun_SetMapperFlags = function(DC: HDC; Flag: DWORD): DWORD; stdcall; TFun_SetGraphicsMode = function(hdc: HDC; iMode: Integer): Integer; stdcall; TFun_SetMapMode = function(DC: HDC; p2: Integer): Integer; stdcall; TFun_SetPixel = function(DC: HDC; X, Y: Integer; Color: COLORREF): COLORREF; stdcall; TFun_SetPixelV = function(DC: HDC; X, Y: Integer; Color: COLORREF): BOOL; stdcall; TFun_LineTo = function(DC: HDC; X, Y: Integer): BOOL; stdcall; TFun_MoveToEx = function(DC: HDC; p2, p3: Integer; p4: PPoint): BOOL; stdcall; TFun_Pie = function(DC: HDC; X1, Y1, X2, Y2, X3, Y3, X4, Y4: Integer): BOOL; stdcall; TFun_PaintRgn = function(DC: HDC; RGN: HRGN): BOOL; stdcall; TFun_PolyPolygon = function(DC: HDC; var Points; var nPoints; p4: Integer): BOOL; stdcall; TFun_Rectangle = function(DC: HDC; X1, Y1, X2, Y2: Integer): BOOL; stdcall; TFun_StrokePath = function(DC: HDC): BOOL; stdcall; TFun_StrokeAndFillPath = function(DC: HDC): BOOL; stdcall; TFun_BeginPath = function(DC: HDC): BOOL; stdcall; TFun_EndPath = function(DC: HDC): BOOL; stdcall; TFun_FillPath = function(DC: HDC): BOOL; stdcall; TFun_FlattenPath = function(DC: HDC): BOOL; stdcall; TFun_WidenPath = function(DC: HDC): BOOL; stdcall; TFun_CreatePen = function(Style, Width: Integer; Color: COLORREF): HPEN; stdcall; TFun_SelectObject = function(DC: HDC; p2: HGDIOBJ): HGDIOBJ; stdcall; TFun_DeleteObject = function(p1: HGDIOBJ): BOOL; stdcall; TFun_Arc = function(hDC: HDC; left, top, right, bottom, startX, startY, endX, endY: Integer): BOOL; stdcall; TFun_Chord = function(DC: HDC; X1, Y1, X2, Y2, X3, Y3, X4, Y4: Integer): BOOL; stdcall; TFun_DrawEscape = function(DC: HDC; p2, p3: Integer; p4: LPCSTR): BOOL; stdcall; TFun_Ellipse = function(DC: HDC; X1, Y1, X2, Y2: Integer): BOOL; stdcall; TFun_RoundRect = function(DC: HDC; X1, Y1, X2, Y2, X3, Y3: Integer): BOOL; stdcall; TFun_AngleArc = function(DC: HDC; p2, p3: Integer; p4: DWORD; p5, p6: Single): BOOL; stdcall; TFun_ArcTo = function(DC: HDC; RLeft, RTop, RRight, RBottom: Integer; X1, Y1, X2, Y2: Integer): BOOL; stdcall; TFun_PolyPolyline = function(DC: HDC; const PointStructs; const Points; p4: DWORD): BOOL; stdcall; TFun_PolyDraw = function(DC: HDC; const Points, Types; cCount: Integer): BOOL; stdcall; TFun_Polygon = function(DC: HDC; const Points; Count: Integer): BOOL; stdcall; TFun_Polyline = function(DC: HDC; const Points; Count: Integer): BOOL; stdcall; TFun_PolyBezier = function(DC: HDC; const Points; Count: DWORD): BOOL; stdcall; TFun_PolyBezierTo = function(DC: HDC; const Points; Count: DWORD): BOOL; stdcall; TFun_PolyLineTo = function(DC: HDC; const Points; Count: DWORD): BOOL; stdcall; TFun_SetPolyFillMode = function(DC: HDC; PolyFillMode: Integer): Integer; stdcall; TFun_ExtFloodFill = function(DC: HDC; X, Y: Integer; Color: COLORREF; FillType: UINT): BOOL; stdcall; TFun_FloodFill = function(DC: HDC; nXStart, nYStart: Integer; crFill: COLORREF): BOOL; stdcall; TFun_FillRgn = function(DC: HDC; hrgn: HRGN; hbr: HBRUSH): BOOL; stdcall; TFun_FillRect = function(hDC: HDC; const lprc: TRect; hbr: HBRUSH): Integer; stdcall; TFun_FrameRect = function(hDC: HDC; const lprc: TRect; hbr: HBRUSH): Integer; stdcall; TFun_GradientFill = function(DC: HDC; Vertex: PTriVertex; NumVertex: ULONG; Mesh: Pointer; NumMesh, Mode: ULONG): BOOL; stdcall; TFun_SetDCBrushColor = function(DC: HDC; Color: COLORREF): COLORREF; stdcall; TFun_SetDCPenColor = function(DC: HDC; Color: COLORREF): COLORREF; stdcall; TFun_SetDIBColorTable = function(DC: HDC; p2, p3: UINT; var RGBQuadSTructs): UINT; stdcall; TFun_SetBkColor = function(DC: HDC; Color: COLORREF): COLORREF; stdcall; TFun_SetTextAlign = function(DC: HDC; Flags: UINT): UINT; stdcall; TFun_SetColorAdjustment = function(DC: HDC; const p2: TColorAdjustment): BOOL; stdcall; TFun_SetArcDirection = function(DC: HDC; Direction: Integer): Integer; stdcall; TFun_SetViewportExtEx = function(DC: HDC; XExt, YExt: Integer; Size: PSize): BOOL; stdcall; TFun_SetViewportOrgEx = function(DC: HDC; X, Y: Integer; Point: PPoint): BOOL; stdcall; TFun_SetICMMode = function(DC: HDC; Mode: Integer): Integer; stdcall; TFun_SetColorSpace = function(DC: HDC; ColorSpace: HCOLORSPACE): BOOL; stdcall; TFun_CreateDIBitmap = function(DC: HDC; var InfoHeader: TBitmapInfoHeader; dwUsage: DWORD; InitBits: Pointer; var InitInfo: TBitmapInfo; wUsage: UINT): HBITMAP; stdcall; TFun_SetDIBits = function(DC: HDC; Bitmap: HBITMAP; StartScan, NumScans: UINT; Bits: Pointer; var BitsInfo: TBitmapInfo; Usage: UINT): Integer; stdcall; TFun_MaskBlt = function(DestDC: HDC; XDest, YDest, Width, Height: Integer; SrcDC: HDC; XScr, YScr: Integer; Mask: HBITMAP; xMask, yMask: Integer; Rop: DWORD): BOOL; stdcall; TFun_PlgBlt = function(DestDC: HDC; const PointsArray; SrcDC: HDC; XSrc, YSrc, Width, Height: Integer; Mask: HBITMAP; xMask, yMask: Integer): BOOL; stdcall; TFun_GdipDrawRectangle = function(graphics: GPGRAPHICS; pen: GPPEN; x: Single; y: Single; width: Single; height: Single): GPSTATUS; stdcall; TFun_GdipDrawRectangleI = function(graphics: GPGRAPHICS; pen: GPPEN; x: Integer; y: Integer; width: Integer; height: Integer): GPSTATUS; stdcall; TFun_GdipDrawRectangles = function(graphics: GPGRAPHICS; pen: GPPEN; rects: GPRECTF; count: Integer): GPSTATUS; stdcall; TFun_GdipDrawRectanglesI = function(graphics: GPGRAPHICS; pen: GPPEN; rects: GPRECT; count: Integer): GPSTATUS; stdcall; TFun_GdipDrawLine = function(graphics: GPGRAPHICS; pen: GPPEN; x1: Single; y1: Single; x2: Single; y2: Single): GPSTATUS; stdcall; TFun_GdipDrawLineI = function(graphics: GPGRAPHICS; pen: GPPEN; x1: Integer; y1: Integer; x2: Integer; y2: Integer): GPSTATUS; stdcall; TFun_GdipDrawLines = function(graphics: GPGRAPHICS; pen: GPPEN; points: GPPOINTF; count: Integer): GPSTATUS; stdcall; TFun_GdipDrawLinesI = function(graphics: GPGRAPHICS; pen: GPPEN; points: GPPOINT; count: Integer): GPSTATUS; stdcall; function InstallPrintHook: Integer; export; stdcall; function UninstallPrintHook: Integer; export; stdcall; implementation uses DDetours, Vcl.Imaging.pngimage, Vcl.Imaging.jpeg, Tocsg.Safe, Tocsg.Path, Tocsg.Strings, Tocsg.WndUtil, Tocsg.Process, Tocsg.Convert; var _PrintHook: TPrintHook = nil; _bLogProcessing: Boolean = false; ozStartDocA: TFun_StartDocA = nil; ozStartDocW: TFun_StartDocW = nil; ozCloseHandle: TFun_CloseHandle = nil; ozStartPage: TFun_HDC = nil; // ozBeginPath: TFun_HDC = nil; // ozFillPath: TFun_HDC = nil; ozEndPage: TFun_HDC = nil; ozEndDoc: TFun_HDC = nil; ozDragQueryFileA: TFun_DragQueryFileA = nil; ozDragQueryFileW: TFun_DragQueryFileW = nil; ozDrawTextA: TFun_DrawTextA = nil; ozDrawTextW: TFun_DrawTextW = nil; ozDrawTextExA: TFun_DrawTextExA = nil; ozDrawTextExW: TFun_DrawTextExW = nil; ozExtTextOutA: TFun_ExtTextOutA = nil; ozExtTextOutW: TFun_ExtTextOutW = nil; ozTextOutA: TFun_TextOutA = nil; ozTextOutW: TFun_TextOutW = nil; ozPolyTextOutA: TFun_PolyTextOutA = nil; ozPolyTextOutW: TFun_PolyTextOutW = nil; ozTabbedTextOutA: TFun_TabbedTextOutA = nil; ozTabbedTextOutW: TFun_TabbedTextOutW = nil; ozSetWindowTextA: TFun_SetWindowTextA = nil; ozSetWindowTextW: TFun_SetWindowTextW = nil; ozMessageBoxA: TFun_MessageBoxA = nil; ozMessageBoxW: TFun_MessageBoxW = nil; ozMessageBoxExA: TFun_MessageBoxExA = nil; ozMessageBoxExW: TFun_MessageBoxExW = nil; ozCreateFileA: TFun_CreateFileA = nil; ozCreateFileW: TFun_CreateFileW = nil; ozBitBlt: TFun_BitBlt = nil; ozStretchBlt: TFun_StretchBlt = nil; ozTransparentBlt: TFun_TransparentBlt = nil; ozStretchDIBits: TFun_StretchDIBits = nil; ozPatBlt: TFun_PatBlt = nil; ozSetMapperFlags: TFun_SetMapperFlags = nil; ozSetGraphicsMode: TFun_SetGraphicsMode = nil; ozSetMapMode: TFun_SetMapMode = nil; ozLineTo: TFun_LineTo = nil; ozMoveToEx: TFun_MoveToEx = nil; ozPie: TFun_Pie = nil; ozPaintRgn: TFun_PaintRgn = nil; ozPolyPolygon: TFun_PolyPolygon = nil; ozRectangle: TFun_Rectangle = nil; ozStrokePath: TFun_StrokePath = nil; ozStrokeAndFillPath: TFun_StrokeAndFillPath = nil; ozBeginPath: TFun_BeginPath = nil; ozEndPath: TFun_EndPath = nil; ozFillPath: TFun_FillPath = nil; ozCreatePen: TFun_CreatePen = nil; ozSelectObject: TFun_SelectObject = nil; ozDeleteObject: TFun_DeleteObject = nil; ozSetPixel: TFun_SetPixel = nil; ozSetPixelV: TFun_SetPixelV = nil; ozFlattenPath: TFun_FlattenPath = nil; ozWidenPath: TFun_WidenPath = nil; ozArc: TFun_Arc = nil; ozChord: TFun_Chord = nil; ozDrawEscape: TFun_DrawEscape = nil; ozEllipse: TFun_Ellipse = nil; ozRoundRect: TFun_RoundRect = nil; ozAngleArc: TFun_AngleArc = nil; ozArcTo: TFun_ArcTo = nil; ozPolyPolyline: TFun_PolyPolyline = nil; ozPolyDraw: TFun_PolyDraw = nil; ozPolygon: TFun_Polygon = nil; ozPolyline: TFun_Polyline = nil; ozPolyBezier: TFun_PolyBezier = nil; ozPolyBezierTo: TFun_PolyBezierTo = nil; ozPolyLineTo: TFun_PolyLineTo = nil; ozSetPolyFillMode: TFun_SetPolyFillMode = nil; ozExtFloodFill: TFun_ExtFloodFill = nil; ozFloodFill: TFun_FloodFill = nil; ozFillRgn: TFun_FillRgn = nil; ozFillRect: TFun_FillRect = nil; ozFrameRect: TFun_FrameRect = nil; ozGradientFill: TFun_GradientFill = nil; ozSetDCBrushColor: TFun_SetDCBrushColor = nil; ozSetDCPenColor: TFun_SetDCPenColor = nil; ozSetDIBColorTable: TFun_SetDIBColorTable = nil; ozSetColorAdjustment: TFun_SetColorAdjustment = nil; ozSetArcDirection: TFun_SetArcDirection = nil; ozSetViewportExtEx: TFun_SetViewportExtEx = nil; ozSetViewportOrgEx: TFun_SetViewportOrgEx = nil; ozSetICMMode: TFun_SetICMMode = nil; ozSetColorSpace: TFun_SetColorSpace = nil; ozCreateDIBitmap: TFun_CreateDIBitmap = nil; ozSetDIBits: TFun_SetDIBits = nil; ozMaskBlt: TFun_MaskBlt = nil; ozPlgBlt: TFun_PlgBlt = nil; ozSetBkColor: TFun_SetBkColor = nil; ozSetTextAlign: TFun_SetTextAlign = nil; ozSetDIBitsToDevice: TFun_SetDIBitsToDevice = nil; ozGdipDrawRectangle: TFun_GdipDrawRectangle = nil; ozGdipDrawRectangleI: TFun_GdipDrawRectangleI = nil; ozGdipDrawRectangles: TFun_GdipDrawRectangles = nil; ozGdipDrawRectanglesI: TFun_GdipDrawRectanglesI = nil; ozGdipDrawLine: TFun_GdipDrawLine = nil; ozGdipDrawLineI: TFun_GdipDrawLineI = nil; ozGdipDrawLines: TFun_GdipDrawLines = nil; ozGdipDrawLinesI: TFun_GdipDrawLinesI = nil; function process_WH_CALLWNDPROC(nCode: Integer; wParam: WPARAM; lParam: LPARAM): LRESULT; stdcall; var cwp: PCWPStruct; begin if Assigned(_PrintHook) then Result := CallNextHookEx(_PrintHook.hWndHook_, nCode, wParam, lParam) else Result := 0; end; function process_WH_GETMESSAGE(nCode: Integer; wParam: WPARAM; lParam: LPARAM): LRESULT; stdcall; begin if Assigned(_PrintHook) then Result := CallNextHookEx(_PrintHook.hMsgHook_, nCode, wParam, lParam) else Result := 0; end; function process_WH_CBT(nCode: Integer; wParam: WPARAM; lParam: LPARAM): LRESULT; stdcall; begin if Assigned(_PrintHook) then begin try try if nCode >= HC_ACTION then case nCode of HCBT_CREATEWND : ; // À©µµ¿ì°¡ »ý¼ºµÈ °æ¿ì´Ù, WM_CREATE, WM_NCCREATE ÇÁ·Î½ÃÀú°¡ ¾ÆÁ÷ ¼öÇàµÇÁö ¾ÊÀº ´Ü°è HCBT_DESTROYWND : ; // À©µµ¿ì°¡ ÆÄ±«µÈ °æ¿ì´Ù HCBT_ACTIVATE : ; // À©µµ¿ì°¡ Ȱ¼ºÈ­ µÈ °æ¿ì´Ù HCBT_CLICKSKIPPED : ; // ¸¶¿ì½º ¸Þ½ÃÁö°¡ ½Ã½ºÅÛ ¸Þ½ÃÁö¿¡¼­ Á¦°ÅµÈ °æ¿ì´Ù HCBT_KEYSKIPPED : ; // Űº¸µå ¸Þ½ÃÁö°¡ ½Ã½ºÅÛ ¸Þ½ÃÁö Å¥¿¡¼­ Á¦°ÅµÈ °æ¿ì´Ù HCBT_MINMAX : ; // À©µµ¿ì°¡ ÃÖ¼ÒÈ­/ÃÖ´ëÈ­°¡ µÈ °æ¿ì´Ù HCBT_MOVESIZE : ; // À©µµ¿ì°¡ ¿Å°ÜÁö°Å³ª Å©±â°¡ º¯°æµÈ °æ¿ì´Ù HCBT_QS : ; // ½Ã½ºÅÛ ¸Þ½ÃÁö Å¥·ÎºÎÅÍ WM_QUEUESYNC ¸Þ½ÃÁö¸¦ Àü´Þ¹ÞÀº °æ¿ì´Ù HCBT_SETFOCUS : ; // À©µµ¿ì°¡ Űº¸µå Æ÷Ä¿½º¸¦ °¡Áö°Ô µÈ °æ¿ì´Ù HCBT_SYSCOMMAND : ; // ½Ã½ºÅÛ ¸í·É(WM_SYSCOMMAND)ÀÌ ¼öÇàµÇ´Â °æ¿ì´Ù end; except exit; end; finally Result := CallNextHookEx(_PrintHook.hCbtHook_, nCode, wParam, lParam); end; end else Result := 0;//CallNextHookEx(0, nCode, wParam, lParam); end; function process_WH_SHELL(nCode: Integer; wParam: WPARAM; lParam: LPARAM): LRESULT; stdcall; var i: Integer; sTitle: String; begin if Assigned(_PrintHook) then begin try try if nCode >= HC_ACTION then case nCode of // HSHELL_ACCESSIBILITYSTATE : _PrintHook.Log('HSHELL_ACCESSIBILITYSTATE'); // Windows 2000/XP: accessibility »óŰ¡ º¯°æµÇ¾úÀ½ // HSHELL_APPCOMMAND : _PrintHook.Log('HSHELL_APPCOMMAND'); // Windows 2000/XP: »ç¿ëÀÚÀÇ ÀÔ·Â À̺¥Æ®¿¡ ÀÇÇØ¼­ WM_APPCOMMAND °¡ ¹ß»ýÇÑ °æ¿ì´Ù // HSHELL_ACTIVATESHELLWINDOW : _PrintHook.Log('HSHELL_ACTIVATESHELLWINDOW'); // ½© ¸ÞÀÎ À©µµ¿ì°¡ Ȱ¼ºÈ­ µÇ¾î¾ß ÇÏ´Â °æ¿ì´Ù // HSHELL_GETMINRECT : _PrintHook.Log('HSHELL_GETMINRECT'); // À©µµ¿ì°¡ ÃÖ¼ÒÈ­/ÃÖ´ëÈ­µÈ °æ¿ì´Ù // HSHELL_LANGUAGE : _PrintHook.Log('HSHELL_LANGUAGE'); // Űº¸µå ¾ð¾î°¡ º¯°æµÇ°Å³ª »õ·Î¿î Űº¸µå ·¹À̾ƿôÀÌ ·ÎµåµÈ °æ¿ì´Ù HSHELL_REDRAW, // ŽºÅ©¹Ù¿¡ ÀÖ´Â À©µµ¿ì ŸÀÌÆ²ÀÌ »õ·Î ±×·ÁÁö´Â °æ¿ì´Ù HSHELL_WINDOWACTIVATED : // ž ·¹º§ À©µµ¿ìÀÇ È°¼ºÈ­ »óŰ¡ º¯°æµÈ °æ¿ì´Ù begin if _PrintHook.hProcWnd_ = 0 then _PrintHook.hProcWnd_ := wParam; end; HSHELL_WINDOWCREATED : ; // ž ·¹º§ À©µµ¿ì°¡ »ý¼ºµÈ °æ¿ì´Ù. ÀÌ ÈÅÀÌ È£ÃâµÇ´Â ½ÃÁ¡¿¡ À©µµ¿ì´Â »ý¼ºµÈ »óÅ´٠HSHELL_WINDOWDESTROYED : ; // ž ·¹º§ À©µµ¿ì°¡ ÆÄ±«µÈ °æ¿ì´Ù. ÀÌ ÈÅÀÌ È£ÃâµÇ´Â ½ÃÁ¡¿¡ À©µµ¿ì´Â Á¸ÀçÇÑ´Ù HSHELL_WINDOWREPLACED : ;//_PrintHook.Log('HSHELL_WINDOWREPLACED'); // Windows XP: ž ·¹º§ À©µµ¿ì°¡ ´ëü(replaced)µÈ °æ¿ì´Ù end; except exit; end; finally Result := CallNextHookEx(_PrintHook.hShellHook_, nCode, wParam, lParam); end; end else Result := 0; end; const PRINT_PATH_EXT = 'DOC|DOCX|PPT|PPTX|XLS|XLSX|TXT|RTF|LOG|PDF|JPG|JPEG|PSD|' + 'BMP|PNG|HWP|HWPX|HTML|HTM|XML'; function CreateFileAHook(lpFileName: PAnsiChar; dwDesiredAccess, dwShareMode: DWORD; lpSecurityAttributes: PSecurityAttributes; dwCreationDisposition, dwFlagsAndAttributes: DWORD; hTemplateFile: THandle): THandle; stdcall; begin Result := ozCreateFileA(lpFileName, dwDesiredAccess, dwShareMode, lpSecurityAttributes, dwCreationDisposition, dwFlagsAndAttributes, hTemplateFile); // if (_PrintHook <> nil) and _PrintHook.Active then begin if CompareText(PChar(_PrintHook.sLogPath_), PChar(String(AnsiString(lpFileName)))) = 0 then exit; if (Result <> 0) and (Result <> INVALID_HANDLE_VALUE) then begin var sPath: AnsiString := AnsiString(lpFileName); if Pos(GetFileExt(sPath).ToUpper, PRINT_PATH_EXT) = 0 then exit; if (_PrintHook.OFList_ <> nil) and (_PrintHook.OFList_.IndexOf(sPath) = -1) then _PrintHook.OFList_.Add(sPath); end; end; end; function CreateFileWHook(lpFileName: PWideChar; dwDesiredAccess, dwShareMode: DWORD; lpSecurityAttributes: PSecurityAttributes; dwCreationDisposition, dwFlagsAndAttributes: DWORD; hTemplateFile: THandle): THandle; stdcall; begin Result := ozCreateFileW(lpFileName, dwDesiredAccess, dwShareMode, lpSecurityAttributes, dwCreationDisposition, dwFlagsAndAttributes, hTemplateFile); // if (_PrintHook <> nil) and _PrintHook.Active then begin if CompareText(PChar(_PrintHook.sLogPath_), lpFileName) = 0 then exit; if (Result <> 0) and (Result <> INVALID_HANDLE_VALUE) then begin var sPath: String := String(lpFileName); if Pos(GetFileExt(sPath).ToUpper, PRINT_PATH_EXT) = 0 then exit; if (_PrintHook.OFList_ <> nil) and (_PrintHook.OFList_.IndexOf(sPath) = -1) then _PrintHook.OFList_.Add(sPath); end; // if (Result <> 0) and (Result <> INVALID_HANDLE_VALUE) and (_PrintHook.DcFileH_ <> nil) then // begin // var sPath: String := String(lpFileName); //// var sFName: String := ExtractFileName(sPath); //// //// if sFName = '' then //// exit; //// //// if Length(sPath) < 2 then //// exit; //// //// if sPath[2] <> ':' then //// exit; //// //// if GetFileExt(sPath).ToUpper = 'EXE' then //// exit; // // if Pos(GetFileExt(sPath).ToUpper, PRINT_PATH_EXT) = 0 then // exit; // //// if CompareText(_PrintHook.ModuleName, 'notepad.exe') = 0 then //// _PrintHook.Log(Format('lpFileName = %s', [sPath])); // // // ¸Þ¸ðÀåÀº... ÆÄÀÏÀ» ÀÐ°í ¹Ù·Î ´Ý¾Æ¹ö¸°´Ù... ¾îÂîÇÒ±î 22_0916 14:31:55 kku // if not _PrintHook.DcFileH_.ContainsKey(Result) then // begin // _PrintHook.DcFileH_.Add(Result, sPath); // end; // end; end; end; function CloseHandleHook(hObject: THandle): BOOL; stdcall; begin // if _PrintHook.DcFileH_ <> nil then // begin // if _PrintHook.DcFileH_.ContainsKey(hObject) then // _PrintHook.DcFileH_.Remove(hObject); // end; Result := ozCloseHandle(hObject); end; function StartDocAHook(DC: HDC; pDocInfo: PDocInfoA): Integer; stdcall; var sFName, sChkDoc, sDocName: AnsiString; enum: TEnumerator; i: Integer; begin sDocName := AnsiString(pDocInfo.lpszDocName); if (_PrintHook <> nil) and _PrintHook.Active then begin _PrintHook.nPtrCnt_ := 0; _PrintHook.CurDocName := sDocName; // if _PrintHook.hProcWnd_ = 0 then // _PrintHook.hProcWnd_ := GetWndHandleFromPID(GetCurrentProcessId); if _PrintHook.OFList_ <> nil then begin sChkDoc := UpperCase(sDocName); for i := 0 to _PrintHook.OFList_.Count - 1 do begin sFName := UpperCase(ExtractFileName(_PrintHook.OFList_[i])); // _PrintHook.Log('StartDocAHook() - File1 = ' + sFName); if Pos(sFName, sChkDoc) > 0 then sDocName := _PrintHook.OFList_[i]; end; end; var sInfo: String; sInfo := _PrintHook.ModuleName; if _PrintHook.hProcWnd_ <> 0 then SumString(sInfo, GetWindowCaption(_PrintHook.hProcWnd_), '|') else SumString(sInfo, 'None', '|'); SumString(sInfo, sDocName, '|'); _PrintHook.PtrInfo := sInfo; PostMessage(_PrintHook.RcvWnd, WM_CATCH_PRINT, 0, 0); end; _PrintHook.Log('StartDocAHook() - lpszDocName = ' + sDocName); // _PrintHook.Log('StartDocAHook() - lpszOutput = ' + AnsiString(pDocInfo.lpszOutput)); // _PrintHook.Log('StartDocAHook() - lpszDatatype = ' + AnsiString(pDocInfo.lpszDatatype)); _PrintHook.sPtrText_ := ''; if FileExists(_PrintHook.sLogPath_) then DeleteFile(PChar(ExtractFilePath(_PrintHook.sLogPath_) + 'PrintText.txt')); Result := ozStartDocA(dc, pDocInfo); end; function StartDocWHook(dc: HDC; pDocInfo: PDocInfoW): Integer; stdcall; var sFName, sChkDoc, sDocName: String; enum: TEnumerator; i: Integer; begin sDocName := String(pDocInfo.lpszDocName); // if _PrintHook.DcFileH_ <> nil then // begin // sChkDoc := UpperCase(sDocName); // Guard(enum, _PrintHook.DcFileH_.Values.GetEnumerator); // while enum.MoveNext do // begin // _PrintHook.Log('StartDocAHook() - File = ' + enum.Current); // sFName := UpperCase(ExtractFileName(enum.Current)); // if Pos(sFName, sChkDoc) > 0 then // sDocName := enum.Current; // end; // end; if (_PrintHook <> nil) and _PrintHook.Active then begin _PrintHook.nPtrCnt_ := 0; _PrintHook.CurDocName := sDocName; // if _PrintHook.hProcWnd_ = 0 then // _PrintHook.hProcWnd_ := GetWndHandleFromPID(GetCurrentProcessId); if _PrintHook.OFList_ <> nil then begin sChkDoc := UpperCase(sDocName); for i := 0 to _PrintHook.OFList_.Count - 1 do begin sFName := UpperCase(ExtractFileName(_PrintHook.OFList_[i])); _PrintHook.Log('StartDocAHook() - File1 = ' + sFName); if Pos(sFName, sChkDoc) > 0 then sDocName := _PrintHook.OFList_[i]; end; end; var sInfo: String; sInfo := _PrintHook.ModuleName; if _PrintHook.hProcWnd_ <> 0 then SumString(sInfo, GetWindowCaption(_PrintHook.hProcWnd_), '|') else SumString(sInfo, 'None', '|'); SumString(sInfo, sDocName, '|'); _PrintHook.PtrInfo := sInfo; PostMessage(_PrintHook.RcvWnd, WM_CATCH_PRINT, 0, 0); end; _PrintHook.Log('StartDocWHook() - lpszDocName = ' + sDocName); // _PrintHook.Log('StartDocWHook() - lpszOutput = ' + String(pDocInfo.lpszOutput)); // _PrintHook.Log('StartDocWHook() - lpszDatatype = ' + String(pDocInfo.lpszDatatype)); _PrintHook.sPtrText_ := ''; if FileExists(_PrintHook.sLogPath_) then DeleteFile(PChar(ExtractFilePath(_PrintHook.sLogPath_) + 'PrintText.txt')); Result := ozStartDocW(dc, pDocInfo); end; function blur(source:TBitmap):TBitmap; var x,y:integer; tline, mline, bline:PByteArray; begin for y := 1 to source.Height - 2 do begin tline := source.ScanLine[y-1]; mline := source.ScanLine[y]; bline := source.ScanLine[y+1]; for x := 1 to source.Width - 2 do begin mline^[x*3] := (mline^[x*3 - 3] + mline^[x*3 + 3] + tline^[x*3 - 3] + tline^[x*3 + 3] + tline^[x*3] + mline^[x*3 - 3] + mline^[x*3 + 3] + mline^[x*3]) div 8; mline^[x*3+1] := (mline^[x*3 - 2] + mline^[x*3 + 4] + tline^[x*3 - 2] + tline^[x*3 + 4] + tline^[x*3+1] + mline^[x*3 - 2] + mline^[x*3 + 4] + mline^[x*3+1]) div 8; mline^[x*3+2] := (mline^[x*3 - 1] + mline^[x*3 + 5] + tline^[x*3 - 1] + tline^[x*3 + 5] + tline^[x*3+2] + mline^[x*3 - 1] + mline^[x*3 + 5] + mline^[x*3+2]) div 8; end; end; result := source; end; // Åõ¸í È¿°ú Àû¿ë ¾ÈµÇ´Â ÇÁ¸°ÅÍ ¶§¹®¿¡ »ç¿ë ¾ÈÇÔ 22_0916 09:57:52 kku { function ProcessWatermark(DC: HDC): Boolean; var nW, nH, nX, i, nGapH, nRepeat: Integer; sExt, sOut, sImgPath: String; MemCanvas: TCanvas; hbmp, hOldBmp: HBITMAP; bf: BLENDFUNCTION; bmp: TBitmap; bImgLoad, bAlphaSupport: Boolean; pen: HPEN; begin Result := false; try nW := GetDeviceCaps(DC, HORZRES); nH := GetDeviceCaps(DC, VERTRES); Guard(MemCanvas, TCanvas.Create); MemCanvas.Handle := CreateCompatibleDC(DC); hbmp := CreateCompatibleBitmap(DC, nW, nH); hOldBmp := SelectObject(MemCanvas.Handle, hbmp); _PrintHook.Log(Format('ProcessWatermark() - DocSize W=%d, H=%d, dc=%d', [nW, nH, DC])); bImgLoad := false; Guard(bmp, TBitmap.Create); PatBlt(MemCanvas.Handle, 0, 0, nW, nH, WHITENESS); sImgPath := _PrintHook.SharedData_.Data.sImgPath; if FileExists(sImgPath) then begin try sOut := GetFileExt(sImgPath).ToUpper; if sOut = 'PNG' then begin var png: TPngImage; Guard(png, TPngImage.Create); png.LoadFromFile(sImgPath); bmp.Assign(png); end else if (sOut = 'JPG') or (sOut = 'JPEG') then begin var jpg: TJPEGImage; Guard(jpg, TJPEGImage.Create); jpg.LoadFromFile(sImgPath); bmp.Assign(jpg); end else if sOut = 'bmp' then bmp.LoadFromFile(sImgPath); // bmp := blur(bmp); // BitBlt(MemCanvas.Handle, (nW div 2) - (bmp.Width div 2), // (nH div 2) - (bmp.Height div 2), // bmp.Width, bmp.Height, bmp.Canvas.Handle, 0, 0, SRCCOPY); if not StretchBlt(MemCanvas.Handle, 0, 0, nW, nH, bmp.Canvas.Handle, 0, 0, bmp.Width, bmp.Height, SRCCOPY) then _PrintHook.Log('ProcessWatermark() - Fail .. StretchBlt() .. 1'); // StretchBlt(MemCanvas.Handle, (nW div 2) - 400, (nH div 2) - 300, nW div 2, nH div 2, bmp.Canvas.Handle, 0, 0, bmp.Width, bmp.Height, SRCCOPY); bImgLoad := true; except // ... end; end; pen := CreatePen(PS_SOLID, 1, RGB(255, 0, 0)); hOldBmp := SelectObject(MemCanvas.Handle, pen); sOut := _PrintHook.SharedData_.Data.sText; SetBkMode(MemCanvas.Handle, TRANSPARENT); if _PrintHook.bSmallFont_ then begin MemCanvas.Font.Size := _PrintHook.SharedData_.Data.nFontSize - 125; if MemCanvas.Font.Size < 10 then MemCanvas.Font.Size := 10; end else MemCanvas.Font.Size := _PrintHook.SharedData_.Data.nFontSize; MemCanvas.Font.Color := clSilver; // clGray; MemCanvas.Font.Style := MemCanvas.Font.Style + [fsBold]; MemCanvas.Font.Orientation := 250; _PrintHook.Log(Format('ProcessWatermark() - Font.Size=%d', [MemCanvas.Font.Size])); nX := 0; for i := 0 to 3 do sOut := sOut + WORD_GAP + sOut; i := 0; nRepeat := _PrintHook.SharedData_.Data.nLineCnt; nGapH := nH div (nRepeat - 1); while i < nH + nGapH do begin MemCanvas.TextOut(nX, i, sOut); Inc(i, nGapH); end; SelectObject(MemCanvas.Handle, hBmp); // TransparentBlt(MemCanvas2.Handle, 0, 0, nW, nH, MemCanvas.Handle, 0, 0, nW, nH, RGB(255, 255, 255)); // TransparentBlt(DC, 0, 0, nW, nH, MemCanvas.Handle, 0, 0, nW, nH, RGB(255, 255, 255)); // TransparentBlt(DC, 0, 0, nW, nH, MemCanvas.Handle, 0, 0, nW, nH, RGB(0, 0, 0)); bf.AlphaFormat := 0; // ÀÏ¹Ý ºñÆ®¸Ê 0, 32ºñÆ® ºñÆ®¸Ê AC_SRC_ALPHA bf.BlendFlags := 0; // ¹«Á¶°Ç 0 bf.BlendOp := AC_SRC_OVER; // AC_SRC_OVER bf.SourceConstantAlpha := 40; // Åõ¸íµµ(Åõ¸í 0 - ºÒÅõ¸í 255) if not AlphaBlend(DC, 0, 0, nW, nH, MemCanvas.Handle, 0, 0, nW, nH, bf) then _PrintHook.Log('ProcessWatermark() - Fail .. AlphaBlend()'); SelectObject(MemCanvas.Handle, hOldBmp); DeleteObject(pen); DeleteObject(hbmp); DeleteDC(MemCanvas.Handle); MemCanvas.Handle := 0; _PrintHook.Log(Format('ProcessWatermark() - Completed, LastError=%d', [GetLastError])); Result := true; except // ½ÇÆÐÇϸé Ãâ·Â ¾ÈµÇ°Ô ÇØÁØ´Ù 22_0907 14:28:52 kku Result := false; DeleteDC(DC); end; end; } function ProcessWatermark(DC: HDC; bStartPage: Boolean = true): Boolean; var nW, nH, nX, i, nGapH, nRepeat: Integer; sExt, sOut, sImgPath: String; MemCanvas: TCanvas; hbmp, hOldBmp: HBITMAP; bf: BLENDFUNCTION; bmp: TBitmap; bImgLoad, bAlphaSupport: Boolean; pen: HPEN; begin // Result := true; //exit; Result := false; _PrintHook.bIsWaterMaking_ := true; try try nW := GetDeviceCaps(DC, HORZRES); nH := GetDeviceCaps(DC, VERTRES); Guard(MemCanvas, TCanvas.Create); if bStartPage then MemCanvas.Handle := CreateCompatibleDC(DC) else MemCanvas.Handle := DC; //CreateCompatibleDC(DC); hbmp := CreateCompatibleBitmap(DC, nW, nH); hOldBmp := SelectObject(MemCanvas.Handle, hbmp); _PrintHook.Log(Format('ProcessWatermark() - DocSize W=%d, H=%d, dc=%d', [nW, nH, DC])); bImgLoad := false; Guard(bmp, TBitmap.Create); if bStartPage then PatBlt(MemCanvas.Handle, 0, 0, nW, nH, WHITENESS); // sImgPath := _PrintHook.ImagePath; if FileExists(sImgPath) then begin try sOut := GetFileExt(sImgPath).ToUpper; if sOut = 'PNG' then begin var png: TPngImage; Guard(png, TPngImage.Create); png.LoadFromFile(sImgPath); bmp.Assign(png); end else if (sOut = 'JPG') or (sOut = 'JPEG') then begin var jpg: TJPEGImage; Guard(jpg, TJPEGImage.Create); jpg.LoadFromFile(sImgPath); bmp.Assign(jpg); end else if sOut = 'bmp' then bmp.LoadFromFile(sImgPath); // bmp := blur(bmp); // BitBlt(MemCanvas.Handle, (nW div 2) - (bmp.Width div 2), // (nH div 2) - (bmp.Height div 2), // bmp.Width, bmp.Height, bmp.Canvas.Handle, 0, 0, SRCCOPY); if not StretchBlt(MemCanvas.Handle, 0, 0, nW, nH, bmp.Canvas.Handle, 0, 0, bmp.Width, bmp.Height, SRCCOPY) then _PrintHook.Log('ProcessWatermark() - Fail .. StretchBlt() .. 1'); // StretchBlt(MemCanvas.Handle, (nW div 2) - 400, (nH div 2) - 300, nW div 2, nH div 2, bmp.Canvas.Handle, 0, 0, bmp.Width, bmp.Height, SRCCOPY); bImgLoad := true; except // ... end; end; pen := CreatePen(PS_SOLID, 1, RGB(255, 0, 0)); hOldBmp := SelectObject(MemCanvas.Handle, pen); sOut := _PrintHook.Text; SetBkMode(MemCanvas.Handle, TRANSPARENT); if _PrintHook.bSmallFont_ then begin MemCanvas.Font.Size := _PrintHook.FontSize - 150; if MemCanvas.Font.Size < 10 then MemCanvas.Font.Size := 10; end else MemCanvas.Font.Size := _PrintHook.FontSize; MemCanvas.Font.Orientation := 250; MemCanvas.Font.Color := $F1F1F1; // clSilver; // clGray; MemCanvas.Font.Style := MemCanvas.Font.Style + [fsBold]; _PrintHook.Log(Format('ProcessWatermark() - Font.Size=%d', [MemCanvas.Font.Size])); nX := 0; for i := 0 to 3 do sOut := sOut + WORD_GAP + sOut; i := 0; nRepeat := _PrintHook.LineCount; nGapH := nH div (nRepeat - 1); if _PrintHook.bSmallFont_ then nGapH := nGapH div 7; while i < nH + nGapH do begin MemCanvas.TextOut(nX, i, sOut); Inc(i, nGapH); end; if bStartPage then BitBlt(DC, 0, 0, nW, nH, MemCanvas.Handle, 0, 0, SRCCOPY); SelectObject(MemCanvas.Handle, hOldBmp); DeleteObject(pen); DeleteObject(hbmp); if bStartPage then DeleteDC(MemCanvas.Handle); MemCanvas.Handle := 0; _PrintHook.Log(Format('ProcessWatermark() - Completed, LastError=%d', [GetLastError])); Result := true; except // ½ÇÆÐÇϸé Ãâ·Â ¾ÈµÇ°Ô ÇØÁØ´Ù 22_0907 14:28:52 kku Result := false; DeleteDC(DC); end; finally _PrintHook.bIsWaterMaking_ := false; end; end; procedure SetPtrBmpFont(SrcDC: HDC); stdcall; var mtr: TTextMetric; arrName: array [0..255] of Char; begin if _PrintHook.IsAblePrintDrawCopy then begin _PrintHook.PtrBmp_.Canvas.Font.Color := GetTextColor(SrcDC); if GetTextFace(SrcDC, 256, arrName) <> 0 then begin _PrintHook.PtrBmp_.Canvas.Font.Name := String(arrName); // _PrintHook.Log(Format('SetPtrBmpFont() .. FontName=%s', [_PrintHook.PtrBmp_.Canvas.Font.Name])); end; if GetTextMetrics(SrcDC, mtr) then begin _PrintHook.PtrBmp_.Canvas.Font.Size := mtr.tmHeight - 60; _PrintHook.PtrBmp_.Canvas.Font.Charset := mtr.tmCharSet; _PrintHook.PtrBmp_.Canvas.Font.Pitch := TFontPitch(mtr.tmPitchAndFamily); if mtr.tmWeight > 400 then _PrintHook.PtrBmp_.Canvas.Font.Style := _PrintHook.PtrBmp_.Canvas.Font.Style + [fsBold] else _PrintHook.PtrBmp_.Canvas.Font.Style := _PrintHook.PtrBmp_.Canvas.Font.Style - [fsBold]; if mtr.tmItalic <> 0 then _PrintHook.PtrBmp_.Canvas.Font.Style := _PrintHook.PtrBmp_.Canvas.Font.Style + [fsItalic] else _PrintHook.PtrBmp_.Canvas.Font.Style := _PrintHook.PtrBmp_.Canvas.Font.Style - [fsItalic]; if mtr.tmUnderlined <> 0 then _PrintHook.PtrBmp_.Canvas.Font.Style := _PrintHook.PtrBmp_.Canvas.Font.Style + [fsUnderline] else _PrintHook.PtrBmp_.Canvas.Font.Style := _PrintHook.PtrBmp_.Canvas.Font.Style - [fsUnderline]; if mtr.tmStruckOut <> 0 then _PrintHook.PtrBmp_.Canvas.Font.Style := _PrintHook.PtrBmp_.Canvas.Font.Style + [fsStrikeOut] else _PrintHook.PtrBmp_.Canvas.Font.Style := _PrintHook.PtrBmp_.Canvas.Font.Style - [fsStrikeOut]; end else _PrintHook.Log('Fail .. SetPtrBmpFont()'); end; end; procedure SetPtrBmpPixel(SrcDC: HDC); stdcall; var gdObj: HGDIOBJ; BmpInfo: Winapi.Windows.TBitmap; begin if _PrintHook.IsAblePrintDrawCopy then begin gdObj := GetCurrentObject(SrcDC, OBJ_BITMAP); if gdObj <> 0 then begin if GetObject(gdObj, SizeOf(BmpInfo), @BmpInfo) <> 0 then begin case BmpInfo.bmBitsPixel of 8 : _PrintHook.PtrBmp_.PixelFormat := pf8bit; 15 : _PrintHook.PtrBmp_.PixelFormat := pf15bit; 16 : _PrintHook.PtrBmp_.PixelFormat := pf16bit; 24 : _PrintHook.PtrBmp_.PixelFormat := pf24bit; 32 : _PrintHook.PtrBmp_.PixelFormat := pf32bit; else _PrintHook.PtrBmp_.PixelFormat := pfDevice; end; end; end; end; end; procedure SetPtrBmpBrush(SrcDC: HDC); stdcall; var gdObj: HGDIOBJ; BruInfo: TLogBrush; begin gdObj := GetCurrentObject(SrcDC, OBJ_BRUSH); if gdObj <> 0 then begin if GetObject(gdObj, SizeOf(BruInfo), @BruInfo) <> 0 then begin _PrintHook.PtrBmp_.Canvas.Brush.Color := BruInfo.lbColor; _PrintHook.PtrBmp_.Canvas.Brush.Style := TBrushStyle(BruInfo.lbStyle); // _PrintHook.PtrBmp_.Canvas.Brush.Color := PenInfo.elpColor; end; end; end; procedure SetPtrBmpPen(SrcDC: HDC); stdcall; var gdObj: HGDIOBJ; // PenInfo: TLogPen; PenInfo: TExtLogPen; begin if _PrintHook.IsAblePrintDrawCopy then begin // gdObj := GetCurrentObject(SrcDC, OBJ_PEN); gdObj := GetCurrentObject(SrcDC, OBJ_EXTPEN); if gdObj <> 0 then begin // _PrintHook.Log(Format('SetPtrBmpPen() .. Get=%d', [GetObject(gdObj, SizeOf(PenInfo), @PenInfo)])); if GetObject(gdObj, SizeOf(PenInfo), @PenInfo) <> 0 then begin // _PrintHook.Log(Format('SetPtrBmpPen() .. 2elpPenStyle=%d, elpWidth=%d, elpColor=%d', // [PenInfo.elpPenStyle, PenInfo.elpWidth, PenInfo.elpColor])); _PrintHook.PtrBmp_.Canvas.Pen.Style := TPenStyle(PenInfo.elpPenStyle); _PrintHook.PtrBmp_.Canvas.Pen.Width := PenInfo.elpWidth; _PrintHook.PtrBmp_.Canvas.Pen.Color := PenInfo.elpColor; end; { _PrintHook.Log(Format('SetPtrBmpPen() .. Get=%d', [GetObject(gdObj, SizeOf(PenInfo), @PenInfo)])); // if GetObject(gdObj, SizeOf(PenInfo), @PenInfo) <> 0 then begin _PrintHook.Log(Format('SetPtrBmpPen() .. 1elpPenStyle=%d, elpWidth=%d, elpColor=%d', [PenInfo.lopnStyle, PenInfo.lopnWidth.X, PenInfo.lopnColor])); _PrintHook.PtrBmp_.Canvas.Pen.Style := TPenStyle(PenInfo.lopnStyle); _PrintHook.PtrBmp_.Canvas.Pen.Width := PenInfo.lopnWidth.X; _PrintHook.PtrBmp_.Canvas.Pen.Color := GetDCPenColor(SrcDC);// PenInfo.lopnColor; end; } end; end; end; function BitBltHook(DestDC: HDC; X, Y, Width, Height: Integer; SrcDC: HDC; XSrc, YSrc: Integer; Rop: DWORD): BOOL; stdcall; begin if _PrintHook.IsAblePrintDrawCopy and (_PrintHook.CurPtrDC_ = DestDC) then begin _PrintHook.Log(Format('BitBltHook() .. X=%d, Y=%d, Width=%d, Height=%d', [X, Y, Width, Height])); try SetPtrBmpPixel(SrcDC); if not ozBitBlt(_PrintHook.PtrBmp_.Canvas.Handle, X, Y, Width, Height, SrcDC, XSrc, YSrc, Rop) then _PrintHook.Log('Fail .. BitBltHook() .. ozBitBlt()'); except on E: Exception do _PrintHook.Log('Fail .. BitBltHook() .. ' + E.Message); end; end; Result := ozBitBlt(DestDC, X, Y, Width, Height, SrcDC, XSrc, YSrc, Rop); end; function StretchBltHook(DestDC: HDC; X, Y, SrcWidth, SrcHeight: Integer; SrcDC: HDC; XSrc, YSrc, DestWidth, DestHeight: Integer; Rop: DWORD): BOOL; stdcall; begin if _PrintHook.IsAblePrintDrawCopy and (_PrintHook.CurPtrDC_ = DestDC) then begin _PrintHook.Log(Format('StretchBltHook() .. XSrc=%d, YSrc=%d, SrcWidth=%d, SrcHeight=%d', [XSrc, YSrc, SrcWidth, SrcHeight])); try SetPtrBmpPixel(SrcDC); ozStretchBlt(_PrintHook.PtrBmp_.Canvas.Handle, X, Y, SrcWidth, SrcHeight, SrcDC, XSrc, YSrc, DestWidth, DestHeight, Rop); except on E: Exception do _PrintHook.Log('Fail .. StretchBltHook() .. ' + E.Message); end; end; Result := ozStretchBlt(DestDC, X, Y, SrcWidth, SrcHeight, SrcDC, XSrc, YSrc, DestWidth, DestHeight, Rop); end; function TransparentBltHook(DestDC: HDC; X, Y, DestWidth, DestHeight: Integer; SrcDC: HDC; XSrc, YSrc, SrcWidth, SrcHeight: Integer; dwTransparent: DWORD): BOOL; stdcall; begin if _PrintHook.IsAblePrintDrawCopy and (_PrintHook.CurPtrDC_ = DestDC) then begin _PrintHook.Log(Format('TransparentBltHook() .. XSrc=%d, YSrc=%d, SrcWidth=%d, SrcHeight=%d', [XSrc, YSrc, SrcWidth, SrcHeight])); try SetPtrBmpPixel(SrcDC); ozTransparentBlt(_PrintHook.PtrBmp_.Canvas.Handle, X, Y, DestWidth, DestHeight, SrcDC, XSrc, YSrc, SrcWidth, SrcHeight, dwTransparent); except on E: Exception do _PrintHook.Log('Fail .. TransparentBltHook() .. ' + E.Message); end; end; Result := ozTransparentBlt(DestDc, X, Y, DestWidth, DestHeight, SrcDC, XSrc, YSrc, SrcWidth, SrcHeight, dwTransparent); end; function StretchDIBitsHook(DC: HDC; DestX, DestY, DestWidth, DestHeight, SrcX, SrcY, SrcWidth, SrcHeight: Integer; Bits: Pointer; var BitsInfo: TBitmapInfo; Usage: UINT; Rop: DWORD): Integer; stdcall; begin if _PrintHook.IsAblePrintDrawCopy and (_PrintHook.CurPtrDC_ = DC) then begin _PrintHook.Log(Format('StretchDIBitsHook() .. SrcX=%d, SrcY=%d, SrcWidth=%d, SrcHeight=%d, DestX=%d, DestY=%d, DestWidth=%d, DestHeight=%d', [SrcX, SrcY, SrcWidth, SrcHeight, DestX, DestY, DestWidth, DestHeight])); try SetPtrBmpPixel(DC); // SetPtrBmpPen(DC); // var bmp: TBitmap; // Guard(bmp, TBitmap.Create); // bmp.Width := SrcWidth; // bmp.Height := SrcHeight; // bmp.PixelFormat := _PrintHook.PtrBmp_.PixelFormat; // ozStretchDIBits(bmp.Canvas.Handle, 0, 0, SrcWidth, SrcHeight, SrcX, SrcY, // SrcWidth, SrcHeight, Bits, BitsInfo, Usage, Rop); // bmp.SaveToFile(Format('C:\Users\kkuzil\Desktop\ptrTest\StretchDIBitsHook_%d_W%dH%d.bmp', [_PrintHook.nPtrCnt_, SrcWidth, SrcHeight])); ozStretchDIBits(_PrintHook.PtrBmp_.Canvas.Handle, DestX, DestY, DestWidth, DestHeight, SrcX, SrcY, SrcWidth, SrcHeight, Bits, BitsInfo, Usage, Rop); except on E: Exception do _PrintHook.Log('Fail .. StretchDIBitsHook() .. ' + E.Message); end; end; Result := ozStretchDIBits(DC, DestX, DestY, DestWidth, DestHeight, SrcX, SrcY, SrcWidth, SrcHeight, Bits, BitsInfo, Usage, Rop); end; function SetDIBitsToDeviceHook(DC: HDC; DestX, DestY: Integer; Width, Height: DWORD; SrcX, SrcY: Integer; nStartScan, NumScans: UINT; Bits: Pointer; var BitsInfo: TBitmapInfo; Usage: UINT): Integer; stdcall; begin if _PrintHook.IsAblePrintDrawCopy and (_PrintHook.CurPtrDC_ = DC) then begin _PrintHook.Log(Format('SetDIBitsToDeviceHook() .. DestX=%d, DestY=%d, Width=%d, Height=%d', [DestX, DestY, Width, Height])); try SetPtrBmpPixel(DC); ozSetDIBitsToDevice(_PrintHook.PtrBmp_.Canvas.Handle, DestX, DestY, Width, Height, SrcX, SrcY, nStartScan, NumScans, Bits, BitsInfo, Usage); except on E: Exception do _PrintHook.Log('Fail .. SetDIBitsToDeviceHook() .. ' + E.Message); end; end; Result := ozSetDIBitsToDevice(DC, DestX, DestY, Width, Height, SrcX, SrcY, nStartScan, NumScans, Bits, BitsInfo, Usage); end; function GdipDrawRectangleHook(graphics: GPGRAPHICS; pen: GPPEN; x: Single; y: Single; width: Single; height: Single): GPSTATUS; stdcall; begin // if _PrintHook.IsAblePrintDrawCopy and (_PrintHook.CurPtrDC_ = DestDC) then // begin // Result := Ok; // end else // Result := ozGdipDrawRectangle(graphics, pen, x, y, width, height); // exit; Result := ozGdipDrawRectangle(graphics, pen, x, y, width, height); end; function GdipDrawRectangleIHook(graphics: GPGRAPHICS; pen: GPPEN; x: Integer; y: Integer; width: Integer; height: Integer): GPSTATUS; stdcall; begin // if _PrintHook.IsAblePrintDrawCopy and (_PrintHook.CurPtrDC_ = DestDC) then // begin // Result := Ok; // end else // Result := ozGdipDrawRectangleI(graphics, pen, x, y, width, height); // exit; Result := ozGdipDrawRectangleI(graphics, pen, x, y, width, height); end; function GdipDrawRectanglesHook(graphics: GPGRAPHICS; pen: GPPEN; rects: GPRECTF; count: Integer): GPSTATUS; stdcall; begin // if _PrintHook.IsAblePrintDrawCopy and (_PrintHook.CurPtrDC_ = DestDC) then // begin // Result := Ok; // end else // Result := ozGdipDrawRectangles(graphics, pen, rects, count); // exit; Result := ozGdipDrawRectangles(graphics, pen, rects, count); end; function GdipDrawRectanglesIHook(graphics: GPGRAPHICS; pen: GPPEN; rects: GPRECT; count: Integer): GPSTATUS; stdcall; begin // if _PrintHook.IsAblePrintDrawCopy and (_PrintHook.CurPtrDC_ = DestDC) then // begin // Result := Ok; // end else // Result := ozGdipDrawRectanglesI(graphics, pen, rects, count); // exit; Result := ozGdipDrawRectanglesI(graphics, pen, rects, count); end; function GdipDrawLineHook(graphics: GPGRAPHICS; pen: GPPEN; x1: Single; y1: Single; x2: Single; y2: Single): GPSTATUS; stdcall; begin // if _PrintHook.IsAblePrintDrawCopy then // begin // Result := Ok; // end else // Result := ozGdipDrawLine(graphics, pen, x1, y1, x2, y2); // exit; Result := ozGdipDrawLine(graphics, pen, x1, y1, x2, y2); end; function GdipDrawLineIHook(graphics: GPGRAPHICS; pen: GPPEN; x1: Integer; y1: Integer; x2: Integer; y2: Integer): GPSTATUS; stdcall; begin // if _PrintHook.IsAblePrintDrawCopy then // begin // Result := Ok; // end else // Result := ozGdipDrawLineI(graphics, pen, x1, y1, x2, y2); // exit; Result := ozGdipDrawLineI(graphics, pen, x1, y1, x2, y2); end; function GdipDrawLinesHook(graphics: GPGRAPHICS; pen: GPPEN; points: GPPOINTF; count: Integer): GPSTATUS; stdcall; begin // if _PrintHook.IsAblePrintDrawCopy then // begin // Result := Ok; // end else // Result := ozGdipDrawLines(graphics, pen, points, count); // exit; Result := ozGdipDrawLines(graphics, pen, points, count); end; function GdipDrawLinesIHook(graphics: GPGRAPHICS; pen: GPPEN; points: GPPOINT; count: Integer): GPSTATUS; stdcall; begin // if _PrintHook.IsAblePrintDrawCopy then // begin // Result := Ok; // end else // Result := ozGdipDrawLinesI(graphics, pen, points, count); // exit; Result := ozGdipDrawLinesI(graphics, pen, points, count); end; function PatBltHook(DC: HDC; X, Y, Width, Height: Integer; Rop: DWORD): BOOL; stdcall; begin if _PrintHook.IsAblePrintDrawCopy and (_PrintHook.CurPtrDC_ = DC) then begin _PrintHook.Log(Format('PatBltHook() .. X=%d, Y=%d, Width=%d, Height=%d', [X, Y, Width, Height])); try SetPtrBmpPixel(DC); // SetPtrBmpPen(DC); ozPatBlt(_PrintHook.PtrBmp_.Canvas.Handle, X, Y, Width, Height, Rop); except on E: Exception do _PrintHook.Log('Fail .. PatBltHook() .. ' + E.Message); end; end; Result := ozPatBlt(DC, X, Y, Width, Height, Rop); end; function SetMapperFlagsHook(DC: HDC; Flag: DWORD): DWORD; stdcall; begin if _PrintHook.IsAblePrintDrawCopy and (_PrintHook.CurPtrDC_ = DC) then ozSetMapperFlags(_PrintHook.PtrBmp_.Canvas.Handle, Flag); Result := ozSetMapperFlags(DC, Flag); end; function SetGraphicsModeHook(hdc: HDC; iMode: Integer): Integer; stdcall; begin if _PrintHook.IsAblePrintDrawCopy and (_PrintHook.CurPtrDC_ = hDC) then ozSetGraphicsMode(_PrintHook.PtrBmp_.Canvas.Handle, iMode); Result := ozSetGraphicsMode(hdc, iMode); end; function SetMapModeHook(DC: HDC; p2: Integer): Integer; stdcall; begin if _PrintHook.IsAblePrintDrawCopy and (_PrintHook.CurPtrDC_ = DC) then ozSetMapMode(_PrintHook.PtrBmp_.Canvas.Handle, p2); Result := ozSetMapMode(DC, p2); end; function SetBkColorHook(DC: HDC; Color: COLORREF): COLORREF; stdcall; begin if _PrintHook.IsAblePrintDrawCopy and (_PrintHook.CurPtrDC_ = DC) then ozSetBkColor(_PrintHook.PtrBmp_.Canvas.Handle, Color); Result := ozSetBkColor(DC, Color); end; function SetTextAlignHook(DC: HDC; Flags: UINT): UINT; stdcall; begin if _PrintHook.IsAblePrintDrawCopy and (_PrintHook.CurPtrDC_ = DC) then ozSetTextAlign(_PrintHook.PtrBmp_.Canvas.Handle, Flags); Result := ozSetTextAlign(DC, Flags); end; function SetPixelHook(DC: HDC; X, Y: Integer; Color: COLORREF): COLORREF; stdcall; begin // if _PrintHook.IsAblePrintDrawCopy and (_PrintHook.CurPtrDC_ = DestDC) then // begin // Result := Color; // end else // Result := ozSetPixel(DC, X, Y, Color); // exit; if _PrintHook.IsAblePrintDrawCopy and (_PrintHook.CurPtrDC_ = DC) then ozSetPixel(_PrintHook.PtrBmp_.Canvas.Handle, X, Y, Color); Result := ozSetPixel(DC, X, Y, Color); end; function SetPixelVHook(DC: HDC; X, Y: Integer; Color: COLORREF): BOOL; stdcall; begin // if _PrintHook.IsAblePrintDrawCopy and (_PrintHook.CurPtrDC_ = DestDC) then // begin // Result := TRUE; // end else // Result := ozSetPixelV(DC, X, Y, Color); // exit; if _PrintHook.IsAblePrintDrawCopy and (_PrintHook.CurPtrDC_ = DC) then ozSetPixelV(_PrintHook.PtrBmp_.Canvas.Handle, X, Y, Color); Result := ozSetPixelV(DC, X, Y, Color); end; function LineToHook(DC: HDC; X, Y: Integer): BOOL; stdcall; var pt: TPoint; begin // Result := ozMoveToEx(DC, X, Y, @pt); // exit; if _PrintHook.IsAblePrintDrawCopy and (_PrintHook.CurPtrDC_ = DC) then begin // _PrintHook.Log('LineToHook() ..'); SetPtrBmpPen(DC); // SetPtrBmpBrush(DC); ozLineTo(_PrintHook.PtrBmp_.Canvas.Handle, X, Y); end; Result := ozLineTo(DC, X, Y); end; function MoveToExHook(DC: HDC; p2, p3: Integer; p4: PPoint): BOOL; stdcall; begin if _PrintHook.IsAblePrintDrawCopy and (_PrintHook.CurPtrDC_ = DC) then begin SetPtrBmpPen(DC); ozMoveToEx(_PrintHook.PtrBmp_.Canvas.Handle, p2, p3, p4); end; Result := ozMoveToEx(DC, p2, p3, p4); end; function DrawEscapeHook(DC: HDC; p2, p3: Integer; p4: LPCSTR): BOOL; stdcall; begin // if _PrintHook.IsAblePrintDrawCopy and (_PrintHook.CurPtrDC_ = DestDC) then // begin // Result := TRUE; // end else // Result := ozDrawEscape(DC, p2, p3, p4); // exit; if _PrintHook.IsAblePrintDrawCopy and (_PrintHook.CurPtrDC_ = DC) then begin SetPtrBmpPen(DC); ozDrawEscape(_PrintHook.PtrBmp_.Canvas.Handle, p2, p3, p4); end; Result := ozDrawEscape(DC, p2, p3, p4); end; function EllipseHook(DC: HDC; X1, Y1, X2, Y2: Integer): BOOL; stdcall; begin // if _PrintHook.IsAblePrintDrawCopy and (_PrintHook.CurPtrDC_ = DestDC) then // begin // Result := TRUE; // end else // Result := ozEllipse(DC, X1, Y1, X2, Y2); // exit; if _PrintHook.IsAblePrintDrawCopy and (_PrintHook.CurPtrDC_ = DC) then begin SetPtrBmpPen(DC); ozEllipse(_PrintHook.PtrBmp_.Canvas.Handle, X1, Y1, X2, Y2); end; Result := ozEllipse(DC, X1, Y1, X2, Y2); end; function RoundRectHook(DC: HDC; X1, Y1, X2, Y2, X3, Y3: Integer): BOOL; stdcall; begin // if _PrintHook.IsAblePrintDrawCopy and (_PrintHook.CurPtrDC_ = DestDC) then // begin // Result := TRUE; // end else // Result := ozRoundRect(DC, X1, Y1, X2, Y2, X3, Y3); // exit; if _PrintHook.IsAblePrintDrawCopy and (_PrintHook.CurPtrDC_ = DC) then begin SetPtrBmpPen(DC); // SetPtrBmpBrush(DC); ozRoundRect(_PrintHook.PtrBmp_.Canvas.Handle, X1, Y1, X2, Y2, X3, Y3); end; Result := ozRoundRect(DC, X1, Y1, X2, Y2, X3, Y3); end; function AngleArcHook(DC: HDC; p2, p3: Integer; p4: DWORD; p5, p6: Single): BOOL; stdcall; begin // if _PrintHook.IsAblePrintDrawCopy and (_PrintHook.CurPtrDC_ = DestDC) then // begin // Result := TRUE; // end else // Result := ozAngleArc(DC, p2, p3, p4, p5, p6); // exit; if _PrintHook.IsAblePrintDrawCopy and (_PrintHook.CurPtrDC_ = DC) then begin SetPtrBmpPen(DC); // SetPtrBmpBrush(DC); ozAngleArc(_PrintHook.PtrBmp_.Canvas.Handle, p2, p3, p4, p5, p6); end; Result := ozAngleArc(DC, p2, p3, p4, p5, p6); end; function ArcToHook(DC: HDC; RLeft, RTop, RRight, RBottom: Integer; X1, Y1, X2, Y2: Integer): BOOL; stdcall; begin // if _PrintHook.IsAblePrintDrawCopy and (_PrintHook.CurPtrDC_ = DestDC) then // begin // Result := TRUE; // end else // Result := ozArcTo(DC, RLeft, RTop, RRight, RBottom, X1, Y1, X2, Y2); // exit; if _PrintHook.IsAblePrintDrawCopy and (_PrintHook.CurPtrDC_ = DC) then begin SetPtrBmpPen(DC); ozArcTo(_PrintHook.PtrBmp_.Canvas.Handle, RLeft, RTop, RRight, RBottom, X1, Y1, X2, Y2); end; Result := ozArcTo(DC, RLeft, RTop, RRight, RBottom, X1, Y1, X2, Y2); end; function PolyPolylineHook(DC: HDC; const PointStructs; const Points; p4: DWORD): BOOL; stdcall; begin // if _PrintHook.IsAblePrintDrawCopy and (_PrintHook.CurPtrDC_ = DestDC) then // begin // Result := TRUE; // end else // Result := ozPolyPolyline(DC, PointStructs, Points, p4); // exit; if _PrintHook.IsAblePrintDrawCopy and (_PrintHook.CurPtrDC_ = DC) then begin SetPtrBmpPen(DC); ozPolyPolyline(_PrintHook.PtrBmp_.Canvas.Handle, PointStructs, Points, p4); end; Result := ozPolyPolyline(DC, PointStructs, Points, p4); end; function PolyDrawHook(DC: HDC; const Points, Types; cCount: Integer): BOOL; stdcall; begin // if _PrintHook.IsAblePrintDrawCopy and (_PrintHook.CurPtrDC_ = DestDC) then // begin // Result := TRUE; // end else // Result := ozPolyDraw(DC, Points, Types, cCount); // exit; if _PrintHook.IsAblePrintDrawCopy and (_PrintHook.CurPtrDC_ = DC) then begin SetPtrBmpPen(DC); ozPolyDraw(_PrintHook.PtrBmp_.Canvas.Handle, Points, Types, cCount); end; Result := ozPolyDraw(DC, Points, Types, cCount); end; function PolygonHook(DC: HDC; const Points; Count: Integer): BOOL; stdcall; begin // if _PrintHook.IsAblePrintDrawCopy and (_PrintHook.CurPtrDC_ = DestDC) then // begin // Result := TRUE; // end else // Result := ozPolygon(DC, Points, Count); // exit; if _PrintHook.IsAblePrintDrawCopy and (_PrintHook.CurPtrDC_ = DC) then begin SetPtrBmpPen(DC); ozPolygon(_PrintHook.PtrBmp_.Canvas.Handle, Points, Count); end; Result := ozPolygon(DC, Points, Count); end; function PolylineHook(DC: HDC; const Points; Count: Integer): BOOL; stdcall; begin // if _PrintHook.IsAblePrintDrawCopy and (_PrintHook.CurPtrDC_ = DestDC) then // begin // Result := TRUE; // end else // Result := ozPolyline(DC, Points, Count); // exit; if _PrintHook.IsAblePrintDrawCopy and (_PrintHook.CurPtrDC_ = DC) then begin SetPtrBmpPen(DC); ozPolyline(_PrintHook.PtrBmp_.Canvas.Handle, Points, Count); end; Result := ozPolyline(DC, Points, Count); end; function PolyBezierHook(DC: HDC; const Points; Count: DWORD): BOOL; stdcall; begin // if _PrintHook.IsAblePrintDrawCopy and (_PrintHook.CurPtrDC_ = DestDC) then // begin // Result := TRUE; // end else // Result := ozPolyBezier(DC, Points, Count); // exit; if _PrintHook.IsAblePrintDrawCopy and (_PrintHook.CurPtrDC_ = DC) then begin SetPtrBmpPen(DC); ozPolyBezier(_PrintHook.PtrBmp_.Canvas.Handle, Points, Count); end; Result := ozPolyBezier(DC, Points, Count); end; function PolyBezierToHook(DC: HDC; const Points; Count: DWORD): BOOL; stdcall; begin // if _PrintHook.IsAblePrintDrawCopy and (_PrintHook.CurPtrDC_ = DestDC) then // begin // Result := TRUE; // end else // Result := ozPolyBezierTo(DC, Points, Count); // exit; if _PrintHook.IsAblePrintDrawCopy and (_PrintHook.CurPtrDC_ = DC) then begin SetPtrBmpPen(DC); ozPolyBezierTo(_PrintHook.PtrBmp_.Canvas.Handle, Points, Count); end; Result := ozPolyBezierTo(DC, Points, Count); end; function PolyLineToHook(DC: HDC; const Points; Count: DWORD): BOOL; stdcall; begin // if _PrintHook.IsAblePrintDrawCopy and (_PrintHook.CurPtrDC_ = DestDC) then // begin // Result := TRUE; // end else // Result := ozPolyLineTo(DC, Points, Count); // exit; if _PrintHook.IsAblePrintDrawCopy and (_PrintHook.CurPtrDC_ = DC) then begin SetPtrBmpPen(DC); ozPolyLineTo(_PrintHook.PtrBmp_.Canvas.Handle, Points, Count); end; Result := ozPolyLineTo(DC, Points, Count); end; function SetPolyFillModeHook(DC: HDC; PolyFillMode: Integer): Integer; stdcall; begin // if _PrintHook.IsAblePrintDrawCopy and (_PrintHook.CurPtrDC_ = DestDC) then // begin // Result := 1; // end else // Result := ozSetPolyFillMode(DC, PolyFillMode); // exit; if _PrintHook.IsAblePrintDrawCopy and (_PrintHook.CurPtrDC_ = DC) then begin SetPtrBmpPen(DC); ozSetPolyFillMode(_PrintHook.PtrBmp_.Canvas.Handle, PolyFillMode); end; Result := ozSetPolyFillMode(DC, PolyFillMode); end; function ExtFloodFillHook(DC: HDC; X, Y: Integer; Color: COLORREF; FillType: UINT): BOOL; stdcall; begin // if _PrintHook.IsAblePrintDrawCopy and (_PrintHook.CurPtrDC_ = DestDC) then // begin // Result := TRUE; // end else // Result := ozExtFloodFill(DC, X, Y, Color, FillType); // exit; if _PrintHook.IsAblePrintDrawCopy and (_PrintHook.CurPtrDC_ = DC) then begin SetPtrBmpPen(DC); ozExtFloodFill(_PrintHook.PtrBmp_.Canvas.Handle, X, Y, Color, FillType); end; Result := ozExtFloodFill(DC, X, Y, Color, FillType); end; function FloodFillHook(DC: HDC; X, Y: Integer; Color: COLORREF; FillType: UINT): BOOL; stdcall; begin // if _PrintHook.IsAblePrintDrawCopy and (_PrintHook.CurPtrDC_ = DestDC) then // begin // Result := TRUE; // end else // Result := ozFloodFill(DC, X, Y, Color); // exit; if _PrintHook.IsAblePrintDrawCopy and (_PrintHook.CurPtrDC_ = DC) then begin SetPtrBmpPen(DC); ozFloodFill(_PrintHook.PtrBmp_.Canvas.Handle, X, Y, Color); end; Result := ozFloodFill(DC, X, Y, Color); end; function FillRgnHook(DC: HDC; hrgn: HRGN; hbr: HBRUSH): BOOL; stdcall; begin // if _PrintHook.IsAblePrintDrawCopy and (_PrintHook.CurPtrDC_ = DestDC) then // begin // Result := TRUE; // end else // Result := ozFillRgn(DC, hrgn, hbr); // exit; if _PrintHook.IsAblePrintDrawCopy and (_PrintHook.CurPtrDC_ = DC) then begin SetPtrBmpPen(DC); ozFillRgn(_PrintHook.PtrBmp_.Canvas.Handle, hrgn, hbr); end; Result := ozFillRgn(DC, hrgn, hbr); end; function FillRectHook(hDC: HDC; const lprc: TRect; hbr: HBRUSH): Integer; stdcall; begin // if _PrintHook.IsAblePrintDrawCopy and (_PrintHook.CurPtrDC_ = DestDC) then // begin // Result := 1; // end else // Result := ozFillRect(hDC, lprc, hbr); // exit; if _PrintHook.IsAblePrintDrawCopy and (_PrintHook.CurPtrDC_ = hDC) then begin SetPtrBmpPen(hDC); ozFillRect(_PrintHook.PtrBmp_.Canvas.Handle, lprc, hbr); end; Result := ozFillRect(hDC, lprc, hbr); end; function FrameRectHook(hDC: HDC; const lprc: TRect; hbr: HBRUSH): Integer; stdcall; begin // if _PrintHook.IsAblePrintDrawCopy and (_PrintHook.CurPtrDC_ = DestDC) then // begin // Result := 1; // end else // Result := ozFrameRect(hDC, lprc, hbr); // exit; if _PrintHook.IsAblePrintDrawCopy and (_PrintHook.CurPtrDC_ = hDC) then begin SetPtrBmpPen(hDC); ozFrameRect(_PrintHook.PtrBmp_.Canvas.Handle, lprc, hbr); end; Result := ozFrameRect(hDC, lprc, hbr); end; function GradientFillHook(DC: HDC; Vertex: PTriVertex; NumVertex: ULONG; Mesh: Pointer; NumMesh, Mode: ULONG): BOOL; stdcall; begin // if _PrintHook.IsAblePrintDrawCopy and (_PrintHook.CurPtrDC_ = DestDC) then // begin // Result := TRUE; // end else // Result := ozGradientFill(DC, Vertex, NumVertex, Mesh, NumMesh, Mode); // exit; if _PrintHook.IsAblePrintDrawCopy and (_PrintHook.CurPtrDC_ = DC) then begin SetPtrBmpPen(DC); ozGradientFill(_PrintHook.PtrBmp_.Canvas.Handle, Vertex, NumVertex, Mesh, NumMesh, Mode); end; Result := ozGradientFill(DC, Vertex, NumVertex, Mesh, NumMesh, Mode); end; function SetDCBrushColorHook(DC: HDC; Color: COLORREF): COLORREF; stdcall; begin if _PrintHook.IsAblePrintDrawCopy and (_PrintHook.CurPtrDC_ = DC) then begin _PrintHook.PtrBmp_.Canvas.Brush.Color := Color; end; Result := ozSetDCBrushColor(DC, Color); end; function SetDCPenColorHook(DC: HDC; Color: COLORREF): COLORREF; stdcall; begin if _PrintHook.IsAblePrintDrawCopy and (_PrintHook.CurPtrDC_ = DC) then begin _PrintHook.PtrBmp_.Canvas.Pen.Color := Color; end; Result := ozSetDCPenColor(DC, Color); end; function SetDIBColorTableHook(DC: HDC; p2, p3: UINT; var RGBQuadSTructs): UINT; stdcall; begin if _PrintHook.IsAblePrintDrawCopy and (_PrintHook.CurPtrDC_ = DC) then begin // SetPtrBmpPen(DC); ozSetDIBColorTable(_PrintHook.PtrBmp_.Canvas.Handle, p2, p3, RGBQuadSTructs); end; Result := ozSetDIBColorTable(DC, p2, p3, RGBQuadSTructs); end; function SetColorAdjustmentHook(DC: HDC; const p2: TColorAdjustment): BOOL; stdcall; begin if _PrintHook.IsAblePrintDrawCopy and (_PrintHook.CurPtrDC_ = DC) then begin SetPtrBmpPen(DC); SetColorAdjustment(_PrintHook.PtrBmp_.Canvas.Handle, p2); end; Result := ozSetColorAdjustment(DC, p2); end; function SetArcDirectionHook(DC: HDC; Direction: Integer): Integer; stdcall; begin // if _PrintHook.IsAblePrintDrawCopy and (_PrintHook.CurPtrDC_ = DestDC) then // begin // Result := 1; // end else // Result := ozSetArcDirection(DC, Direction); // exit; if _PrintHook.IsAblePrintDrawCopy and (_PrintHook.CurPtrDC_ = DC) then begin SetPtrBmpPen(DC); ozSetArcDirection(_PrintHook.PtrBmp_.Canvas.Handle, Direction); end; Result := ozSetArcDirection(DC, Direction); end; function SetViewportExtExHook(DC: HDC; XExt, YExt: Integer; Size: PSize): BOOL; stdcall; begin if _PrintHook.IsAblePrintDrawCopy and (_PrintHook.CurPtrDC_ = DC) then begin SetPtrBmpPen(DC); ozSetViewportExtEx(_PrintHook.PtrBmp_.Canvas.Handle, XExt, YExt, Size); end; Result := ozSetViewportExtEx(DC, XExt, YExt, Size); end; function SetViewportOrgExHook(DC: HDC; X, Y: Integer; Point: PPoint): BOOL; stdcall; begin if _PrintHook.IsAblePrintDrawCopy and (_PrintHook.CurPtrDC_ = DC) then begin SetPtrBmpPen(DC); ozSetViewportOrgEx(_PrintHook.PtrBmp_.Canvas.Handle, X, Y, Point); end; Result := ozSetViewportOrgEx(DC, X, Y, Point); end; function SetICMModeHook(DC: HDC; Mode: Integer): Integer; stdcall; begin if _PrintHook.IsAblePrintDrawCopy and (_PrintHook.CurPtrDC_ = DC) then begin SetPtrBmpPen(DC); ozSetICMMode(_PrintHook.PtrBmp_.Canvas.Handle, Mode); end; Result := ozSetICMMode(DC, Mode); end; function SetColorSpaceHook(DC: HDC; ColorSpace: HCOLORSPACE): BOOL; stdcall; begin if _PrintHook.IsAblePrintDrawCopy and (_PrintHook.CurPtrDC_ = DC) then begin SetPtrBmpPen(DC); ozSetColorSpace(_PrintHook.PtrBmp_.Canvas.Handle, ColorSpace); end; Result := ozSetColorSpace(DC, ColorSpace); end; function CreateDIBitmapHook(DC: HDC; var InfoHeader: TBitmapInfoHeader; dwUsage: DWORD; InitBits: Pointer; var InitInfo: TBitmapInfo; wUsage: UINT): HBITMAP; stdcall; begin if _PrintHook.IsAblePrintDrawCopy and (_PrintHook.CurPtrDC_ = DC) then begin _PrintHook.Log(Format('CreateDIBitmapHook() ,, W=%d, H=%d', [InfoHeader.biWidth, InfoHeader.biHeight])); end; Result := ozCreateDIBitmap(DC, InfoHeader, dwUsage, InitBits, InitInfo, wUsage); end; function SetDIBitsHook(DC: HDC; Bitmap: HBITMAP; StartScan, NumScans: UINT; Bits: Pointer; var BitsInfo: TBitmapInfo; Usage: UINT): Integer; stdcall; begin if _PrintHook.IsAblePrintDrawCopy and (_PrintHook.CurPtrDC_ = DC) then begin _PrintHook.Log(Format('ozSetDIBits() ,, W=%d, H=%d', [BitsInfo.bmiHeader.biWidth, BitsInfo.bmiHeader.biHeight])); end; Result := ozSetDIBits(DC, Bitmap, StartScan, NumScans, Bits, BitsInfo, Usage); end; function MaskBltHook(DestDC: HDC; XDest, YDest, Width, Height: Integer; SrcDC: HDC; XScr, YScr: Integer; Mask: HBITMAP; xMask, yMask: Integer; Rop: DWORD): BOOL; stdcall; begin if _PrintHook.IsAblePrintDrawCopy and (_PrintHook.CurPtrDC_ = DestDC) then begin _PrintHook.Log(Format('PlgBltHook() ,, W=%d, H=%d', [Width, Height])); end; Result := ozMaskBlt(DestDC, XDest, YDest, Width, Height, SrcDC, XScr, YScr, Mask, xMask, yMask, Rop); end; function PlgBltHook(DestDC: HDC; const PointsArray; SrcDC: HDC; XSrc, YSrc, Width, Height: Integer; Mask: HBITMAP; xMask, yMask: Integer): BOOL; stdcall; begin if _PrintHook.IsAblePrintDrawCopy and (_PrintHook.CurPtrDC_ = DestDC) then begin _PrintHook.Log(Format('PlgBltHook() ,, W=%d, H=%d', [Width, Height])); end; Result := ozPlgBlt(DestDC, PointsArray, SrcDC, XSrc, YSrc, Width, Height, Mask, xMask, yMask); end; function ArcHook(hDC: HDC; left, top, right, bottom, startX, startY, endX, endY: Integer): BOOL; stdcall; begin // if _PrintHook.IsAblePrintDrawCopy and (_PrintHook.CurPtrDC_ = DestDC) then // begin // Result := TRUE; // end else // Result := ArcHook(hDC, left, top, right, bottom, startX, startY, endX, endY); // exit; if _PrintHook.IsAblePrintDrawCopy and (_PrintHook.CurPtrDC_ = hDC) then begin SetPtrBmpPen(hDC); ozArc(_PrintHook.PtrBmp_.Canvas.Handle, left, top, right, bottom, startX, startY, endX, endY); end; Result := ozArc(hDC, left, top, right, bottom, startX, startY, endX, endY); end; function ChordHook(DC: HDC; X1, Y1, X2, Y2, X3, Y3, X4, Y4: Integer): BOOL; stdcall; begin // if _PrintHook.IsAblePrintDrawCopy and (_PrintHook.CurPtrDC_ = DestDC) then // begin // Result := TRUE; // end else // Result := ozChord(DC, X1, Y1, X2, Y2, X3, Y3, X4, Y4); // exit; if _PrintHook.IsAblePrintDrawCopy and (_PrintHook.CurPtrDC_ = DC) then begin SetPtrBmpPen(DC); ozChord(_PrintHook.PtrBmp_.Canvas.Handle, X1, Y1, X2, Y2, X3, Y3, X4, Y4); end; Result := ozChord(DC, X1, Y1, X2, Y2, X3, Y3, X4, Y4); end; function PieHook(DC: HDC; X1, Y1, X2, Y2, X3, Y3, X4, Y4: Integer): BOOL; stdcall; begin // if _PrintHook.IsAblePrintDrawCopy and (_PrintHook.CurPtrDC_ = DestDC) then // begin // Result := TRUE; // end else // Result := ozPie(DC, X1, Y1, X2, Y2, X3, Y3, X4, Y4); // exit; if _PrintHook.IsAblePrintDrawCopy and (_PrintHook.CurPtrDC_ = DC) then begin SetPtrBmpPen(DC); ozPie(_PrintHook.PtrBmp_.Canvas.Handle, X1, Y1, X2, Y2, X3, Y3, X4, Y4); end; Result := ozPie(DC, X1, Y1, X2, Y2, X3, Y3, X4, Y4); end; function PaintRgnHook(DC: HDC; RGN: HRGN): BOOL; stdcall; begin // if _PrintHook.IsAblePrintDrawCopy and (_PrintHook.CurPtrDC_ = DestDC) then // begin // Result := TRUE; // end else // Result := ozPaintRgn(DC, RGN); // exit; if _PrintHook.IsAblePrintDrawCopy and (_PrintHook.CurPtrDC_ = DC) then begin SetPtrBmpPen(DC); ozPaintRgn(_PrintHook.PtrBmp_.Canvas.Handle, RGN); end; Result := ozPaintRgn(DC, RGN); end; function PolyPolygonHook(DC: HDC; var Points; var nPoints; p4: Integer): BOOL; stdcall; begin // if _PrintHook.IsAblePrintDrawCopy and (_PrintHook.CurPtrDC_ = DestDC) then // begin // Result := TRUE; // end else // Result := ozPolyPolygon(DC, Points, nPoints, p4); // exit; if _PrintHook.IsAblePrintDrawCopy and (_PrintHook.CurPtrDC_ = DC) then begin SetPtrBmpPen(DC); ozPolyPolygon(_PrintHook.PtrBmp_.Canvas.Handle, Points, nPoints, p4); end; Result := ozPolyPolygon(DC, Points, nPoints, p4); end; function RectangleHook(DC: HDC; X1, Y1, X2, Y2: Integer): BOOL; stdcall; begin // if _PrintHook.IsAblePrintDrawCopy and (_PrintHook.CurPtrDC_ = DestDC) then // begin // Result := TRUE; // end else // Result := ozRectangle(DC, X1, Y1, X2, Y2); // exit; if _PrintHook.IsAblePrintDrawCopy and (_PrintHook.CurPtrDC_ = DC) then begin SetPtrBmpPen(DC); ozRectangle(_PrintHook.PtrBmp_.Canvas.Handle, X1, Y1, X2, Y2); end; Result := ozRectangle(DC, X1, Y1, X2, Y2); end; function StrokePathHook(DC: HDC): BOOL; stdcall; begin // if _PrintHook.IsAblePrintDrawCopy and (_PrintHook.CurPtrDC_ = DestDC) then // begin // Result := TRUE; // end else // Result := ozStrokePath(DC); // exit; if _PrintHook.IsAblePrintDrawCopy and (_PrintHook.CurPtrDC_ = DC) then begin SetPtrBmpPen(DC); ozStrokePath(_PrintHook.PtrBmp_.Canvas.Handle); end; Result := ozStrokePath(DC); end; function StrokeAndFillPathHook(DC: HDC): BOOL; stdcall; begin // if _PrintHook.IsAblePrintDrawCopy and (_PrintHook.CurPtrDC_ = DestDC) then // begin // Result := TRUE; // end else // Result := ozStrokeAndFillPath(DC); // exit; if _PrintHook.IsAblePrintDrawCopy and (_PrintHook.CurPtrDC_ = DC) then begin SetPtrBmpPen(DC); ozStrokeAndFillPath(_PrintHook.PtrBmp_.Canvas.Handle); end; Result := ozStrokeAndFillPath(DC); end; function BeginPathHook(DC: HDC): BOOL; stdcall; begin if _PrintHook.IsAblePrintDrawCopy and (_PrintHook.CurPtrDC_ = DC) then begin SetPtrBmpPen(DC); ozBeginPath(_PrintHook.PtrBmp_.Canvas.Handle); end; Result := ozBeginPath(DC); end; function EndPathHook(DC: HDC): BOOL; stdcall; begin if _PrintHook.IsAblePrintDrawCopy and (_PrintHook.CurPtrDC_ = DC) then begin SetPtrBmpPen(DC); ozEndPath(_PrintHook.PtrBmp_.Canvas.Handle); end; Result := ozEndPath(DC); end; function FillPathHook(DC: HDC): BOOL; stdcall; begin // if _PrintHook.IsAblePrintDrawCopy and (_PrintHook.CurPtrDC_ = DestDC) then // begin // Result := TRUE; // end else // Result := ozFillPath(DC); // exit; if _PrintHook.IsAblePrintDrawCopy and (_PrintHook.CurPtrDC_ = DC) then begin SetPtrBmpPen(DC); SetPtrBmpBrush(DC); ozFillPath(_PrintHook.PtrBmp_.Canvas.Handle); end; Result := ozFillPath(DC); end; function FlattenPathHook(DC: HDC): BOOL; stdcall; begin // if _PrintHook.IsAblePrintDrawCopy and (_PrintHook.CurPtrDC_ = DC) then // begin // Result := TRUE; // end else // Result := ozFlattenPath(DC); // exit; if _PrintHook.IsAblePrintDrawCopy and (_PrintHook.CurPtrDC_ = DC) then begin SetPtrBmpPen(DC); ozFlattenPath(_PrintHook.PtrBmp_.Canvas.Handle); end; Result := ozFlattenPath(DC); end; function WidenPathHook(DC: HDC): BOOL; stdcall; begin if _PrintHook.IsAblePrintDrawCopy and (_PrintHook.CurPtrDC_ = DC) then begin SetPtrBmpPen(DC); ozWidenPath(_PrintHook.PtrBmp_.Canvas.Handle); end; Result := ozWidenPath(DC); end; function CreatePenHook(Style, Width: Integer; Color: COLORREF): HPEN; stdcall; begin Result := ozCreatePen(Style, Width, Color); end; function SelectObjectHook(DC: HDC; p2: HGDIOBJ): HGDIOBJ; stdcall; begin Result := ozSelectObject(DC, p2); // ¾Æ·¡ ºÎÁú ¾øÀ½, ±â·ÏÀ» À§ÇØ ³²°ÜµÒ 23_0107 19:46:38 kku // if _PrintHook.IsAblePrintDrawCopy and (_PrintHook.CurPtrDC_ = DestDC) and _PrintHook.DcPen_.ContainsKey(p2) then // begin // pEnt := _PrintHook.DcPen_[p2]; // _PrintHook.Log(Format('SelectObjectHook() .. Style=%d, Width=%d, Color=%d', [pEnt.nStyle, pEnt.nWidth, pEnt.nColor])); // _PrintHook.PtrBmp_.Canvas.Pen.Style := TPenStyle(pEnt.nStyle); // _PrintHook.PtrBmp_.Canvas.Pen.Width := pEnt.nWidth; // _PrintHook.PtrBmp_.Canvas.Pen.Color := pEnt.nColor; // end; end; function DeleteObjectHook(p1: HGDIOBJ): BOOL; stdcall; begin Result := ozDeleteObject(p1); end; function StartPageHook(DC: HDC): Integer; stdcall; begin // if _PrintHook.nPtrCnt_ > 1 then // begin // Result := -1; // _PrintHook.bIsStartPage_ := false; // _PrintHook.bIsPrinting_ := false; // exit; // end; _PrintHook.bIsStartPage_ := true; _PrintHook.bIsPrinting_ := true; // if _PrintHook.Active and (_PrintHook.hMemDC_ = 0) then if _PrintHook.Active and (_PrintHook.PtrBmp_ = nil) then begin Inc(_PrintHook.nPtrCnt_); _PrintHook.CurPtrDC_ := DC; _PrintHook.PtrBmp_ := TBitmap.Create; _PrintHook.PtrBmp_.Width := GetDeviceCaps(DC, HORZRES); _PrintHook.PtrBmp_.Height := GetDeviceCaps(DC, VERTRES); SetPtrBmpFont(DC); SetPtrBmpPixel(DC); // SetPtrBmpPen(DC); _PrintHook.PtrBmp_.Canvas.Font.Name := 'Tahoma'; _PrintHook.PtrBmp_.Canvas.Pen.Width := 2; _PrintHook.PtrBmp_.Canvas.Pen.Style := psSolid; _PrintHook.PtrBmp_.Canvas.Pen.Color := clRed; // _PrintHook.PtrBmp_.Canvas.Brush.Style := bsClear; // _PrintHook.PtrBmp_.Canvas.Brush.Color := clRed; // _PrintHook.PtrBmp_.Canvas.Pen.Mode // _PrintHook.hMemDC_ := CreateCompatibleDC(DC); // _PrintHook.hbmp_ := CreateCompatibleBitmap(DC, _PrintHook.nW_, _PrintHook.nH_); // SelectObject(_PrintHook.hMemDC_, _PrintHook.hbmp_); // // var hFont := CreateFont(50,0,0,0,0,0,0,0,HANGEUL_CHARSET,0,0,0, // VARIABLE_PITCH or FF_ROMAN, '±Ã¼­'); // SelectObject(_PrintHook.hMemDC_, hFont); // PatBlt(_PrintHook.hMemDC_, 0, 0, _PrintHook.nW_, _PrintHook.nH_, WHITENESS); end; Result := ozStartPage(DC); // º°µµ ÇÁ·Î½ÃÀú ¸¸µé¾î¼­ »ç¿ëÇÏ¸é ¾ÈµÈ´Ù.. ±×·¡¼­ StartPageHook(), EndPageHook() °¢°¢ ±¸Çö 22_0907 15:06:14 kku if not _PrintHook.Active or _PrintHook.bEndDocProc_ then exit; if Result = 1 then begin _PrintHook.Log('StartPageHook() .. ProcessWatermark()'); if not ProcessWatermark(DC) then // if not ProcessWatermark(_MemCanvas.Handle) then Result := -1; end; end; function EndPageHook(DC: HDC): Integer; stdcall; begin if _PrintHook.Active and _PrintHook.bEndDocProc_ then begin _PrintHook.Log('EndPageHook() .. ProcessWatermark()'); // if _MemCanvas <> nil then // begin // if not ProcessWatermark(_MemCanvas.Handle, false) then // begin // Result := -1; // exit; // end; // end else begin if not ProcessWatermark(DC, false) then begin Result := -1; exit; end; end; end; _PrintHook.Log('EndPageHook()'); _PrintHook.bIsStartPage_ := false; if _PrintHook.PtrBmp_ <> nil then begin _PrintHook.CurPtrDC_ := 0; try var jpg: TJPEGImage; Guard(jpg, TJPEGImage.Create); jpg.Assign(_PrintHook.PtrBmp_); // _PrintHook.PtrBmp_.SaveToFile(Format('C:\Users\kkuzil\Desktop\ptrTest\%s-%.2d.bmp', [_PrintHook.CurDocName, _PrintHook.nPtrCnt_])); FreeAndNil(_PrintHook.PtrBmp_); jpg.SaveToFile(Format('C:\Users\kku\Desktop\ptr_test\%s-%.2d.jpg', [ExtractFileName(_PrintHook.CurDocName), _PrintHook.nPtrCnt_])); except on E: Exception do _PrintHook.Log('Fail .. EndPageHook(), ' + E.Message); end; end; Result := ozEndPage(DC); _PrintHook.bIsPrinting_ := false; end; function EndDocHook(DC: HDC): Integer; stdcall; begin if FileExists(_PrintHook.sLogPath_) then WriteLnFileEndUTF8(ExtractFilePath(_PrintHook.sLogPath_) + 'PrintText.txt', _PrintHook.sPtrText_); Result := ozEndDoc(DC); _PrintHook.Log('EndDocHook()'); end; function DragQueryFileAHook(Drop: HDROP; FileIndex: UINT; FileName: LPSTR; cb: UINT): UINT; stdcall; begin if _PrintHook.Active then begin // Â÷´Ü Result := 0; end else Result := ozDragQueryFileA(Drop, FileIndex, FileName, cb); end; function DragQueryFileWHook(Drop: HDROP; FileIndex: UINT; FileName: LPWSTR; cb: UINT): UINT; stdcall; begin if _PrintHook.Active then begin // Â÷´Ü Result := 0; end else Result := ozDragQueryFileW(Drop, FileIndex, FileName, cb); end; procedure ReplaceTextA(sStr: LPCSTR); inline; stdcall; var sData: AnsiString; bMod: Boolean; begin bMod := false; sData := AnsiString(sStr); if Pos('·Î±×', sData) > 0 then begin sData := StringReplace(sData, '·Î±×', '**', [rfReplaceAll]); bMod := true; end else if Pos('±è±¸Áø', sData) > 0 then begin sData := StringReplace(sData, '±è±¸Áø', '±èÁ¾¹«', [rfReplaceAll]); bMod := true; end; if Pos('±èÁø¾Æ', sData) > 0 then begin sData := StringReplace(sData, '±èÁø¾Æ', '±èÁ¾¹«', [rfReplaceAll]); bMod := true; end; if Pos('¼³ÀçÈ£', sData) > 0 then begin sData := StringReplace(sData, '¼³ÀçÈ£', '±èÁ¾¹«', [rfReplaceAll]); bMod := true; end; if Pos('Á¶ÇöÈ£', sData) > 0 then begin sData := StringReplace(sData, 'Á¶ÇöÈ£', '±èÁ¾¹«', [rfReplaceAll]); bMod := true; end; if Pos('±è°æ´ö', sData) > 0 then begin sData := StringReplace(sData, '±è°æ´ö', '±èÁ¾¹«', [rfReplaceAll]); bMod := true; end; if Pos('±æÁ¤¿ì', sData) > 0 then begin sData := StringReplace(sData, '±æÁ¤¿ì', '±èÁ¾¹«', [rfReplaceAll]); bMod := true; end; if Pos('Á¤¿ì¼º', sData) > 0 then begin sData := StringReplace(sData, 'Á¤¿ì¼º', '±èÁ¾¹«', [rfReplaceAll]); bMod := true; end; if Pos('svchost', sData) > 0 then begin sData := StringReplace(sData, 'svchost', 'xxxxxxx', [rfReplaceAll]); bMod := true; end; if bMod then CopyMemory(@sStr[0], @sData[1], Length(sData)); end; procedure ReplaceTextW(sStr: LPCWSTR); inline; stdcall; var sData: String; bMod: Boolean; begin bMod := false; sData := String(sStr); if Pos('·Î±×', sData) > 0 then begin sData := StringReplace(sData, '·Î±×', '**', [rfReplaceAll]); bMod := true; end else if Pos('±è±¸Áø', sData) > 0 then begin sData := StringReplace(sData, '±è±¸Áø', '±èÁ¾¹«', [rfReplaceAll]); bMod := true; end; if Pos('±èÁø¾Æ', sData) > 0 then begin sData := StringReplace(sData, '±èÁø¾Æ', '±èÁ¾¹«', [rfReplaceAll]); bMod := true; end; if Pos('¼³ÀçÈ£', sData) > 0 then begin sData := StringReplace(sData, '¼³ÀçÈ£', '±èÁ¾¹«', [rfReplaceAll]); bMod := true; end; if Pos('Á¶ÇöÈ£', sData) > 0 then begin sData := StringReplace(sData, 'Á¶ÇöÈ£', '±èÁ¾¹«', [rfReplaceAll]); bMod := true; end; if Pos('±è°æ´ö', sData) > 0 then begin sData := StringReplace(sData, '±è°æ´ö', '±èÁ¾¹«', [rfReplaceAll]); bMod := true; end; if Pos('±æÁ¤¿ì', sData) > 0 then begin sData := StringReplace(sData, '±æÁ¤¿ì', '±èÁ¾¹«', [rfReplaceAll]); bMod := true; end; if Pos('Á¤¿ì¼º', sData) > 0 then begin sData := StringReplace(sData, 'Á¤¿ì¼º', '±èÁ¾¹«', [rfReplaceAll]); bMod := true; end; if Pos('svchost', sData) > 0 then begin sData := StringReplace(sData, 'svchost', 'xxxxxxx', [rfReplaceAll]); bMod := true; end; if bMod then CopyMemory(@sStr[0], @sData[1], Length(sData) * 2); end; function DrawTextAHook(hDC: HDC; lpString: LPCSTR; nCount: Integer; var lpRect: TRect; uFormat: UINT): Integer; stdcall; var sData: AnsiString; begin if _PrintHook.IsAblePrintDrawCopy and (_PrintHook.CurPtrDC_ = hDC) then begin ReplaceTextA(lpString); sData := AnsiString(lpString); SumString(_PrintHook.sPtrText_, sData, ' '); SetPtrBmpFont(hDC); ozDrawTextA(_PrintHook.PtrBmp_.Canvas.Handle, lpString, nCount, lpRect, uFormat); end; Result := ozDrawTextA(hDc, lpString, nCount, lpRect, uFormat); end; function DrawTextWHook(hDC: HDC; lpString: LPCWSTR; nCount: Integer; var lpRect: TRect; uFormat: UINT): Integer; stdcall; var sData: String; begin if _PrintHook.IsAblePrintDrawCopy and (_PrintHook.CurPtrDC_ = hDC) then begin ReplaceTextW(lpString); sData := String(lpString); SumString(_PrintHook.sPtrText_, sData, ' '); SetPtrBmpFont(hDC); ozDrawTextW(_PrintHook.PtrBmp_.Canvas.Handle, lpString, nCount, lpRect, uFormat); end; Result := ozDrawTextW(hDc, lpString, nCount, lpRect, uFormat); end; function DrawTextExAHook(DC: HDC; lpchText: LPCSTR; cchText: Integer; var p4: TRect; dwDTFormat: UINT; DTParams: PDrawTextParams): Integer; stdcall; var sData: AnsiString; begin ReplaceTextA(lpchText); if _PrintHook.IsAblePrintDrawCopy and (_PrintHook.CurPtrDC_ = DC) then begin sData := AnsiString(lpchText); SumString(_PrintHook.sPtrText_, sData, ' '); SetPtrBmpFont(DC); ozDrawTextExA(_PrintHook.PtrBmp_.Canvas.Handle, lpchText, cchText, p4, dwDTFormat, DTParams); end; Result := ozDrawTextExA(DC, lpchText, cchText, p4, dwDTFormat, DTParams); end; function DrawTextExWHook(DC: HDC; lpchText: LPCWSTR; cchText: Integer; var p4: TRect; dwDTFormat: UINT; DTParams: PDrawTextParams): Integer; stdcall; var sData: String; begin ReplaceTextW(lpchText); if _PrintHook.IsAblePrintDrawCopy and (_PrintHook.CurPtrDC_ = DC) then begin sData := String(lpchText); SumString(_PrintHook.sPtrText_, sData, ' '); SetPtrBmpFont(DC); ozDrawTextExW(_PrintHook.PtrBmp_.Canvas.Handle, lpchText, cchText, p4, dwDTFormat, DTParams); // if _PrintHook.hMemDC_ <> 0 then // ozDrawTextExW(_PrintHook.hMemDC_, lpchText, cchText, p4, dwDTFormat, DTParams); end; Result := ozDrawTextExW(DC, lpchText, cchText, p4, dwDTFormat, DTParams); end; function ExtTextOutAHook(DC: HDC; X, Y: Integer; Options: Longint; Rect: PRect; Str: LPCSTR; Count: Longint; Dx: PInteger): BOOL; stdcall; var sData: AnsiString; begin ReplaceTextA(Str); if _PrintHook.IsAblePrintDrawCopy and (_PrintHook.CurPtrDC_ = DC) then begin sData := AnsiString(Str); SumString(_PrintHook.sPtrText_, sData, ' '); if _PrintHook.IsAblePrintDrawCopy then begin SetPtrBmpFont(DC); ozExtTextOutA(_PrintHook.PtrBmp_.Canvas.Handle, X, Y, Options, Rect, Str, Count, Dx); end; // if _PrintHook.hMemDC_ <> 0 then // ozExtTextOutA(_PrintHook.hMemDC_, X, Y, Options, Rect, Str, Count, Dx); end; Result := ozExtTextOutA(DC, X, Y, Options, Rect, Str, Count, Dx); end; function ExtTextOutWHook(DC: HDC; X, Y: Integer; Options: Longint; Rect: PRect; Str: LPCWSTR; Count: Longint; Dx: PInteger): BOOL; stdcall; var sData: String; begin ReplaceTextW(Str); if _PrintHook.IsAblePrintDrawCopy and (_PrintHook.CurPtrDC_ = DC) then begin ReplaceTextW(Str); sData := String(Str); SumString(_PrintHook.sPtrText_, String(Str), ' '); if _PrintHook.IsAblePrintDrawCopy then begin SetPtrBmpFont(DC); // _PrintHook.Log('ExtTextOutWHook() .. FontName : ' + _PrintHook.PtrBmp_.Canvas.Font.Name); // ozTextOutW(_PrintHook.PtrBmp_.Canvas.Handle, X, Y, Str, Count); ozExtTextOutW(_PrintHook.PtrBmp_.Canvas.Handle, X, Y, Options, Rect, Str, Count, Dx); end; // if _PrintHook.hMemDC_ <> 0 then // ozExtTextOutW(_PrintHook.hMemDC_, X, Y, Options, Rect, Str, Count, Dx); end; Result := ozExtTextOutW(DC, X, Y, Options, Rect, Str, Count, Dx); end; function TextOutAHook(DC: HDC; X, Y: Integer; Str: LPCSTR; Count: Integer): BOOL; stdcall; var sData: AnsiString; begin ReplaceTextA(Str); if _PrintHook.IsAblePrintDrawCopy and (_PrintHook.CurPtrDC_ = DC) then begin sData := AnsiString(Str); SumString(_PrintHook.sPtrText_, sData, ' '); SetPtrBmpFont(DC); if _PrintHook.IsAblePrintDrawCopy then ozTextOutA(_PrintHook.PtrBmp_.Canvas.Handle, X, Y, Str, Count); // if _PrintHook.hMemDC_ <> 0 then // ozTextOutA(_PrintHook.hMemDC_, X, Y, Str, Count); end; Result := ozTextOutA(DC, X, Y, Str, Count); end; function TextOutWHook(DC: HDC; X, Y: Integer; Str: LPCWSTR; Count: Integer): BOOL; stdcall; var sData: String; begin ReplaceTextW(Str); if _PrintHook.IsAblePrintDrawCopy and (_PrintHook.CurPtrDC_ = DC) then begin sData := String(Str); SumString(_PrintHook.sPtrText_, sData, ' '); SetPtrBmpFont(DC); if _PrintHook.IsAblePrintDrawCopy then ozTextOutW(_PrintHook.PtrBmp_.Canvas.Handle, X, Y, Str, Count); // if _PrintHook.hMemDC_ <> 0 then // ozTextOutW(_PrintHook.hMemDC_, X, Y, Str, Count); end; Result := ozTextOutW(DC, X, Y, Str, Count); end; function PolyTextOutAHook(DC: HDC; const PolyTextArray; Strings: Integer): BOOL; stdcall; type TArrayLPCSTR = array [0..0] of LPCSTR; var i: Integer; begin if _PrintHook.IsAblePrintDrawCopy and (_PrintHook.CurPtrDC_ = DC) then begin try for i := 0 to Strings - 1 do begin ReplaceTextA(TArrayLPCSTR(PolyTextArray)[i]); SumString(_PrintHook.sPtrText_, AnsiString(TArrayLPCSTR(PolyTextArray)[i]), ' '); end; SetPtrBmpFont(DC); if _PrintHook.IsAblePrintDrawCopy then ozPolyTextOutA(_PrintHook.PtrBmp_.Canvas.Handle, PolyTextArray, Strings); except // .. end; end; Result := ozPolyTextOutA(DC, PolyTextArray, Strings); end; function PolyTextOutWHook(DC: HDC; const PolyTextArray; Strings: Integer): BOOL; stdcall; type TArrayLPCWSTR = array [0..0] of LPCWSTR; var i: Integer; begin if _PrintHook.IsAblePrintDrawCopy and (_PrintHook.CurPtrDC_ = DC) then begin try for i := 0 to Strings - 1 do begin ReplaceTextW(TArrayLPCWSTR(PolyTextArray)[i]); SumString(_PrintHook.sPtrText_, String(TArrayLPCWSTR(PolyTextArray)[i]), ' '); end; SetPtrBmpFont(DC); if _PrintHook.IsAblePrintDrawCopy then ozPolyTextOutW(_PrintHook.PtrBmp_.Canvas.Handle, PolyTextArray, Strings); except // .. end; end; Result := ozPolyTextOutW(DC, PolyTextArray, Strings); end; function TabbedTextOutAHook(hDC: HDC; X, Y: Integer; lpString: LPCSTR; nCount, nTabPositions: Integer; var lpnTabStopPositions; nTabOrigin: Integer): Longint; stdcall; var sData: AnsiString; begin if _PrintHook.IsAblePrintDrawCopy and (_PrintHook.CurPtrDC_ = hDC) then begin ReplaceTextA(lpString); sData := AnsiString(lpString); SumString(_PrintHook.sPtrText_, sData, ' '); SetPtrBmpFont(hDC); if _PrintHook.IsAblePrintDrawCopy then ozTabbedTextOutA(_PrintHook.PtrBmp_.Canvas.Handle, X, Y, lpString, nCount, nTabPositions, lpnTabStopPositions, nTabOrigin); end; Result := ozTabbedTextOutA(hDC, X, Y, lpString, nCount, nTabPositions, lpnTabStopPositions, nTabOrigin); end; function TabbedTextOutWHook(hDC: HDC; X, Y: Integer; lpString: LPCWSTR; nCount, nTabPositions: Integer; var lpnTabStopPositions; nTabOrigin: Integer): Longint; stdcall; var sData: String; begin if _PrintHook.IsAblePrintDrawCopy and (_PrintHook.CurPtrDC_ = hDC) then begin ReplaceTextW(lpString); sData := String(lpString); SumString(_PrintHook.sPtrText_, sData, ' '); SetPtrBmpFont(hDC); if _PrintHook.IsAblePrintDrawCopy then ozTabbedTextOutW(_PrintHook.PtrBmp_.Canvas.Handle, X, Y, lpString, nCount, nTabPositions, lpnTabStopPositions, nTabOrigin); end; Result := ozTabbedTextOutW(hDC, X, Y, lpString, nCount, nTabPositions, lpnTabStopPositions, nTabOrigin); end; function SetWindowTextAHook(hWnd: HWND; lpString: LPCSTR): BOOL; stdcall; var sData: AnsiString; begin if _PrintHook.Active and _PrintHook.bIsPrinting_ then begin ReplaceTextA(lpString); sData := AnsiString(lpString); SumString(_PrintHook.sPtrText_, sData, ' '); end; Result := SetWindowTextA(hWnd, lpString); end; function SetWindowTextWHook(hWnd: HWND; lpString: LPCWSTR): BOOL; stdcall; var sData: String; begin if _PrintHook.Active and _PrintHook.bIsPrinting_ then begin ReplaceTextW(lpString); sData := String(lpString); SumString(_PrintHook.sPtrText_, sData, ' '); end; Result := SetWindowTextW(hWnd, lpString); end; function MessageBoxAHook(hWnd: HWND; lpText, lpCaption: LPCSTR; uType: UINT): Integer; stdcall; var sData: AnsiString; begin if _PrintHook.Active and _PrintHook.bIsPrinting_ then begin ReplaceTextA(lpText); ReplaceTextA(lpCaption); sData := AnsiString(lpText); SumString(_PrintHook.sPtrText_, sData, ' '); end; Result := MessageBoxA(hWnd, lpText, lpCaption, uType); end; function MessageBoxWHook(hWnd: HWND; lpText, lpCaption: LPCWSTR; uType: UINT): Integer; stdcall; var sData: String; begin if _PrintHook.Active and _PrintHook.bIsPrinting_ then begin ReplaceTextW(lpText); ReplaceTextW(lpCaption); sData := String(lpText); SumString(_PrintHook.sPtrText_, sData, ' '); end; Result := MessageBoxW(hWnd, lpText, lpCaption, uType); end; function MessageBoxExAHook(hWnd: HWND; lpText, lpCaption: LPCSTR; uType: UINT; wLanguageId: Word): Integer; stdcall; var sData: AnsiString; begin if _PrintHook.Active and _PrintHook.bIsPrinting_ then begin ReplaceTextA(lpText); ReplaceTextA(lpCaption); sData := AnsiString(lpText); SumString(_PrintHook.sPtrText_, sData, ' '); end; Result := MessageBoxExA(hWnd, lpText, lpCaption, uType, wLanguageId); end; function MessageBoxExWHook(hWnd: HWND; lpText, lpCaption: LPCWSTR; uType: UINT; wLanguageId: Word): Integer; stdcall; var sData: String; begin if _PrintHook.Active and _PrintHook.bIsPrinting_ then begin ReplaceTextW(lpText); ReplaceTextW(lpCaption); sData := String(lpText); SumString(_PrintHook.sPtrText_, sData, ' '); end; Result := MessageBoxExW(hWnd, lpText, lpCaption, uType, wLanguageId); end; { TPrintHook } Constructor TPrintHook.Create; procedure GetStartTime; var ftCreate, ftExit, ftKernel, ftUser: TFileTime; nDosTime: Integer; begin dtCreate_ := 0; GetProcessTimes(GetCurrentProcess, ftCreate, ftExit, ftKernel, ftUser); if FileTimeToLocalFileTime(ftCreate, ftCreate) then if FileTimeToDosDateTime(ftCreate, LongRec(nDosTime).Hi, LongRec(nDosTime).Lo) then dtCreate_ := FileDateToDateTime(nDosTime); end; var IgrList: TStringList; begin Inherited Create; ASSERT(_PrintHook = nil); _PrintHook := Self; hWndHook_ := 0; hMsgHook_ := 0; hShellHook_ := 0; bInitOk_ := false; bIsPrinting_ := false; bIsStartPage_ := false; bIsWaterMaking_ := false; CurPtrDC_ := 0; sPtrText_ := ''; sCurDocName_ := ''; nPtrCnt_ := 0; hProcWnd_ := 0; GetStartTime; ProcList_ := TList.Create; // DcFileH_ := TDictionary.Create; OFList_ := TStringList.Create; OFList_.CaseSensitive := false; SharedData_ := TTgFileMapping.Create(MAP_FILENAME_APIHOOK, SizeOf(TSharedData)); if SharedData_.IsAvailable then begin // sImgPath_ := SharedData_.Data.sImgPath; sLogPath_ := SharedData_.Data.sLogPath; end; Guard(IgrList, TStringList.Create); IgrList.CaseSensitive := false; SplitString(END_PROCESS, '|', IgrList); bEndDocProc_ := IgrList.IndexOf(ModuleName) > -1; SplitString(SMALL_FONT, '|', IgrList); bSmallFont_ := IgrList.IndexOf(ModuleName) > -1; SplitString(IGNORE_PROCESS, '|', IgrList); if IgrList.IndexOf(ModuleName) = -1 then begin Trace_ := TTgTrace.Create(ExtractFilePath(sLogPath_), ExtractFileName(sLogPath_)); DoInterceptCreate; end; end; Destructor TPrintHook.Destroy; begin UnInstallHook; _PrintHook := nil; FreeAndNil(SharedData_); if Trace_ <> nil then FreeAndNil(Trace_); // FreeAndNil(DcFileH_); FreeAndNil(OFList_); FreeAndNil(ProcList_); Inherited; end; function TPrintHook.IsAblePrintDrawCopy: Boolean; begin Result := not bIsWaterMaking_ and bIsPrinting_ and GetActive and (PtrBmp_ <> nil); end; procedure TPrintHook.DoInterceptCreate; procedure AddInterceptAPI(var aProcDest: Pointer; aProcSrc, aProcHook: Pointer; sProcName: String); begin if aProcDest = nil then begin aProcDest := InterceptCreate(aProcSrc, aProcHook); if aProcDest <> nil then begin Log(Format('>>> InterceptCreate() - %s <<<', [sProcName])); ProcList_.Add(@aProcDest); end else Log(Format('>>> Fail .. InterceptCreate() - %s <<<', [sProcName])); end; end; begin Log('DoInterceptCreate()'); DoInterceptRemove; AddInterceptAPI(@ozCreateFileA, @CreateFileA, @CreateFileAHook, 'CreateFileA'); AddInterceptAPI(@ozCreateFileW, @CreateFileW, @CreateFileWHook, 'CreateFileW'); AddInterceptAPI(@ozCloseHandle, @CloseHandle, @CloseHandleHook, 'CloseHandle'); AddInterceptAPI(@ozStartDocA, @StartDocA, @StartDocAHook, 'StartDocA'); AddInterceptAPI(@ozStartDocW, @StartDocW, @StartDocWHook, 'StartDocW'); AddInterceptAPI(@ozStartPage, @StartPage, @StartPageHook, 'StartPage'); AddInterceptAPI(@ozEndPage, @EndPage, @EndPageHook, 'EndPage'); AddInterceptAPI(@ozEndDoc, @EndDoc, @EndDocHook, 'EndDoc'); AddInterceptAPI(@ozBitBlt, @BitBlt, @BitBltHook, 'BitBlt'); AddInterceptAPI(@ozStretchBlt, @StretchBlt, @StretchBltHook, 'StretchBlt'); AddInterceptAPI(@ozTransparentBlt, @TransparentBlt, @TransparentBltHook, 'TransparentBlt'); AddInterceptAPI(@ozStretchDIBits, @StretchDIBits, @StretchDIBitsHook, 'StretchDIBits'); // chrome Çʼö AddInterceptAPI(@ozSetDIBitsToDevice, @SetDIBitsToDevice, @SetDIBitsToDeviceHook, 'SetDIBitsToDevice'); // AddInterceptAPI(@ozGdipDrawLine, @GdipDrawLine, @GdipDrawLineHook, 'GdipDrawLine'); // AddInterceptAPI(@ozGdipDrawLineI, @GdipDrawLineI, @GdipDrawLineIHook, 'GdipDrawLineI'); // AddInterceptAPI(@ozGdipDrawLines, @GdipDrawLines, @GdipDrawLinesHook, 'GdipDrawLines'); // AddInterceptAPI(@ozGdipDrawLinesI, @GdipDrawLinesI, @GdipDrawLinesIHook, 'GdipDrawLinesI'); // AddInterceptAPI(@ozGdipDrawRectangle, @GdipDrawRectangle, @GdipDrawRectangleHook, 'GdipDrawRectangle'); // AddInterceptAPI(@ozGdipDrawRectangleI, @GdipDrawRectangleI, @GdipDrawRectangleIHook, 'GdipDrawRectangleI'); // AddInterceptAPI(@ozGdipDrawRectangles, @GdipDrawRectangles, @GdipDrawRectanglesHook, 'GdipDrawRectangles'); // AddInterceptAPI(@ozGdipDrawRectanglesI, @GdipDrawRectanglesI, @GdipDrawRectanglesIHook, 'GdipDrawRectanglesI'); // AddInterceptAPI(@ozPatBlt, @PatBlt, @PatBltHook, 'PatBlt'); AddInterceptAPI(@ozSetMapperFlags, @SetMapperFlags, @SetMapperFlagsHook, 'SetMapperFlags'); AddInterceptAPI(@ozSetGraphicsMode, @SetGraphicsMode, @SetGraphicsModeHook, 'SetGraphicsMode'); AddInterceptAPI(@ozSetMapMode, @SetMapMode, @SetMapModeHook, 'SetMapMode'); AddInterceptAPI(@ozSetPixel, @SetPixel, @SetPixelHook, 'SetPixel'); AddInterceptAPI(@ozSetPixelV, @SetPixelV, @SetPixelVHook, 'SetPixelV'); AddInterceptAPI(@ozLineTo, @LineTo, @LineToHook, 'LineTo'); // chrome Çʼö AddInterceptAPI(@ozMoveToEx, @MoveToEx, @MoveToExHook, 'MoveToEx'); // chrome Çʼö AddInterceptAPI(@ozPolyLineTo, @PolyLineTo, @PolyLineToHook, 'PolyLineTo'); AddInterceptAPI(@ozPolyBezierTo, @PolyBezierTo, @PolyBezierToHook, 'PolyBezierTo'); // chrome Çʼö AddInterceptAPI(@ozPolyDraw, @PolyDraw, @PolyDrawHook, 'PolyDraw'); AddInterceptAPI(@ozRectangle, @Rectangle, @RectangleHook, 'Rectangle'); AddInterceptAPI(@ozRoundRect, @RoundRect, @RoundRectHook, 'RoundRect'); AddInterceptAPI(@ozPolygon, @Polygon, @PolygonHook, 'Polygon'); AddInterceptAPI(@ozPolyBezier, @PolyBezier, @PolyBezierHook, 'PolyBezier'); AddInterceptAPI(@ozPolyline, @Polyline, @PolylineHook, 'Polyline'); // AddInterceptAPI(@ozMaskBlt, @MaskBlt, @MaskBltHook, 'MaskBlt'); // X // AddInterceptAPI(@ozPlgBlt, @PlgBlt, @PlgBltHook, 'PlgBlt'); // X // AddInterceptAPI(@ozCreateDIBitmap, @CreateDIBitmap, @CreateDIBitmapHook, 'CreateDIBitmap'); // X // AddInterceptAPI(@ozSetDIBits, @SetDIBits, @SetDIBitsHook, 'SetDIBits'); // X AddInterceptAPI(@ozBeginPath, @BeginPath, @BeginPathHook, 'BeginPath'); // chrome Çʼö AddInterceptAPI(@ozEndPath, @EndPath, @EndPathHook, 'EndPath'); // chrome Çʼö AddInterceptAPI(@ozFillPath, @FillPath, @FillPathHook, 'FillPath'); // chrome Çʼö AddInterceptAPI(@ozStrokePath, @StrokePath, @StrokePathHook, 'StrokePath');// >> X AddInterceptAPI(@ozStrokeAndFillPath, @StrokeAndFillPath, @StrokeAndFillPathHook, 'StrokeAndFillPath');// >> X AddInterceptAPI(@ozFlattenPath, @FlattenPath, @FlattenPathHook, 'FlattenPath'); AddInterceptAPI(@ozWidenPath, @WidenPath, @WidenPathHook, 'WidenPath'); AddInterceptAPI(@ozSetDCBrushColor, @SetDCBrushColor, @SetDCBrushColorHook, 'SetDCBrushColor'); AddInterceptAPI(@ozSetDCPenColor, @SetDCPenColor, @SetDCPenColorHook, 'SetDCPenColor'); AddInterceptAPI(@ozSetDIBColorTable, @SetDIBColorTable, @SetDIBColorTableHook, 'SetDIBColorTable'); AddInterceptAPI(@ozSetTextAlign, @SetTextAlign, @SetTextAlignHook, 'SetTextAlign'); // AddInterceptAPI(@ozSetBkColor, @SetBkColor, @SetBkColorHook, 'SetBkColor'); // À̰ŠÀû¿ëµÇ¸é »¸À½.. 23_0107 22:41:09 kku AddInterceptAPI(@ozGradientFill, @GradientFill, @GradientFillHook, 'GradientFill'); AddInterceptAPI(@ozFillRect, @FillRect, @FillRectHook, 'FillRect'); AddInterceptAPI(@ozFrameRect, @FrameRect, @FrameRectHook, 'FrameRect'); AddInterceptAPI(@ozFloodFill, @FloodFill, @FloodFillHook, 'FloodFill'); AddInterceptAPI(@ozExtFloodFill, @ExtFloodFill, @ExtFloodFillHook, 'ExtFloodFill'); AddInterceptAPI(@ozFillRgn, @FillRgn, @FillRgnHook, 'FillRgn'); AddInterceptAPI(@ozSetPolyFillMode, @SetPolyFillMode, @SetPolyFillModeHook, 'SetPolyFillMode'); AddInterceptAPI(@ozDrawEscape, @DrawEscape, @DrawEscapeHook, 'DrawEscape'); AddInterceptAPI(@ozPaintRgn, @PaintRgn, @PaintRgnHook, 'PaintRgn'); AddInterceptAPI(@ozSetColorAdjustment, @SetColorAdjustment, @SetColorAdjustmentHook, 'SetColorAdjustment'); AddInterceptAPI(@ozSetArcDirection, @SetArcDirection, @SetArcDirectionHook, 'SetArcDirection'); AddInterceptAPI(@ozSetViewportExtEx, @SetViewportExtEx, @SetViewportExtExHook, 'SetViewportExtEx'); AddInterceptAPI(@ozSetViewportOrgEx, @SetViewportOrgEx, @SetViewportOrgExHook, 'SetViewportOrgEx'); AddInterceptAPI(@ozSetICMMode, @SetICMMode, @SetICMModeHook, 'SetICMMode'); AddInterceptAPI(@ozSetColorSpace, @SetColorSpace, @SetColorSpaceHook, 'SetColorSpace'); AddInterceptAPI(@ozAngleArc, @AngleArc, @AngleArcHook, 'AngleArc'); AddInterceptAPI(@ozArcTo, @ArcTo, @ArcToHook, 'ArcTo'); AddInterceptAPI(@ozPolyPolyline, @PolyPolyline, @PolyPolylineHook, 'PolyPolyline'); AddInterceptAPI(@ozEllipse, @Ellipse, @EllipseHOok, 'Ellipse'); AddInterceptAPI(@ozChord, @Chord, @ChordHook, 'Chord'); AddInterceptAPI(@ozArc, @Arc, @ArcHook, 'Arc'); AddInterceptAPI(@ozPie, @Pie, @PieHook, 'Pie'); AddInterceptAPI(@ozPolyPolygon, @PolyPolygon, @PolyPolygonHook, 'PolyPolygon'); // AddInterceptAPI(@ozCreatePen, @CreatePen, @CreatePenHook, 'CreatePen'); // AddInterceptAPI(@ozSelectObject, @SelectObject, @SelectObjectHook, 'SelectObject'); // AddInterceptAPI(@ozDeleteObject, @DeleteObject, @DeleteObjectHook, 'DeleteObject'); AddInterceptAPI(@ozExtTextOutA, @ExtTextOutA, @ExtTextOutAHook, 'ExtTextOutA'); // notepad++ AddInterceptAPI(@ozExtTextOutW, @ExtTextOutW, @ExtTextOutWHook, 'ExtTextOutW'); // notepad++ AddInterceptAPI(@ozDrawTextA, @DrawTextA, @DrawTextAHook, 'DrawTextA'); AddInterceptAPI(@ozDrawTextW, @DrawTextW, @DrawTextWHook, 'DrawTextW'); AddInterceptAPI(@ozDrawTextExA, @DrawTextExA, @DrawTextExAHook, 'DrawTextExA'); AddInterceptAPI(@ozDrawTextExW, @DrawTextExW, @DrawTextExWHook, 'DrawTextExW'); AddInterceptAPI(@ozTextOutA, @TextOutA, @TextOutAHook, 'TextOutA'); AddInterceptAPI(@ozTextOutW, @TextOutW, @TextOutWHook, 'TextOutW'); AddInterceptAPI(@ozPolyTextOutA, @PolyTextOutA, @PolyTextOutAHook, 'PolyTextOutA'); AddInterceptAPI(@ozPolyTextOutW, @PolyTextOutW, @PolyTextOutWHook, 'PolyTextOutW'); AddInterceptAPI(@ozTabbedTextOutA, @TabbedTextOutA, @TabbedTextOutAHook, 'TabbedTextOutA'); AddInterceptAPI(@ozTabbedTextOutW, @TabbedTextOutW, @TabbedTextOutWHook, 'TabbedTextOutW'); // AddInterceptAPI(@ozDragQueryFileA, @DragQueryFileA, @DragQueryFileAHook, 'DragQueryFileA'); // AddInterceptAPI(@ozDragQueryFileW, @DragQueryFileW, @DragQueryFileWHook, 'DragQueryFileW'); bInitOk_ := true; end; procedure TPrintHook.DoInterceptRemove; procedure RemoveAPI(var aProc: Pointer); var nRet: Integer; begin if aProc <> nil then begin nRet := InterceptRemove(aProc); // Log('DoInterceptRemove() .. RemoveAPI() .. nRet=' + IntToStr(nRet)); aProc := nil; end; end; var i: Integer; begin if bInitOk_ then begin Log('DoInterceptRemove()'); for i := 0 to ProcList_.Count - 1 do RemoveAPI(ProcList_[i]^); ProcList_.Clear; bInitOk_ := false; end; end; procedure TPrintHook.Log(sLog: String); begin if Trace_ <> nil then begin _bLogProcessing := true; Trace_.T('(%s) %s', [ModuleName, sLog]); _bLogProcessing := false; end; end; function TPrintHook.InstallHook: Integer; begin Log('InstallPrintHook'); try // hWndHook_ := SetWindowsHookEx(WH_CALLWNDPROC, process_WH_CALLWNDPROC, HInstance, 0); // if hWndHook_ = 0 then // begin // Log('SetWindowsHookEx(WH_CALLWNDPROC) fail!!'); // Result := 4; // exit; // end; // hMsgHook_ := SetWindowsHookEx(WH_GETMESSAGE, process_WH_GETMESSAGE, HInstance, 0); // if hMsgHook_ = 0 then // begin // Log('SetWindowsHookEx(WH_GETMESSAGE) fail!!'); // Result := 3; // exit; // end; // hCbtHook_ := SetWindowsHookEx(WH_CBT, process_WH_CBT, HInstance, 0); // if hCbtHook_ = 0 then // begin // Log('SetWindowsHookEx(WH_CBT) fail!!'); // Result := 1; // exit; // end; hShellHook_ := SetWindowsHookEx(WH_SHELL, process_WH_SHELL, HInstance, 0); if hShellHook_ = 0 then begin Log('SetWindowsHookEx(WH_SHELL) fail!!'); Result := 2; exit; end; except exit; end; // if (hCbtHook_ <> 0) and (hShellHook_ <> 0) then Result := 0; // else // Result := -2; end; function TPrintHook.UnInstallHook: Integer; begin Log('UninstallPrintHook'); try if hWndHook_ <> 0 then begin Log('UnhookWindowsHookEx(WndHook)'); UnhookWindowsHookEx(hWndHook_); hWndHook_ := 0; end; if hMsgHook_ <> 0 then begin Log('UnhookWindowsHookEx(MsgHook)'); UnhookWindowsHookEx(hMsgHook_); hMsgHook_ := 0; end; try if hCbtHook_ <> 0 then begin Log('UnhookWindowsHookEx(CbtHook)'); UnhookWindowsHookEx(hCbtHook_); hCbtHook_ := 0; end; except // ¿ÖÀÎÁö.. OS ¸¶´Ù´Ù¸¥°ÇÁö ¸ð¸£°ÚÁö¸¸, ¿À·ù¸¦ ¹ß»ýÇØ¼­ °ü·Ã ÇÁ·Î±×·¥ÀÌ Á״´Ù. 14_1023 17:57:08 sunk hCbtHook_ := 0; end; if hShellHook_ <> 0 then begin Log('UnhookWindowsHookEx(ShellHook)'); UnhookWindowsHookEx(hShellHook_); hShellHook_ := 0; end; DoInterceptRemove; except // ¿ÖÀÎÁö.. OS ¸¶´Ù´Ù¸¥°ÇÁö ¸ð¸£°ÚÁö¸¸, ¿À·ù¸¦ ¹ß»ýÇØ¼­ °ü·Ã ÇÁ·Î±×·¥ÀÌ Á״´Ù. 14_1023 17:57:08 sunk hMsgHook_ := 0; hShellHook_ := 0; end; Result := 0; end; function TPrintHook.GetActive: Boolean; begin Result := false; try if SharedData_.Data <> nil then Result := SharedData_.Data.bActive; except Log('Fail .. GetActive()'); end; end; function TPrintHook.GetRcvWnd: LONGLONG; begin Result := 0; try if SharedData_.Data <> nil then Result := SharedData_.Data.llRcvWnd; except Log('Fail .. GetRcvWnd()'); end; end; function TPrintHook.GetText: String; begin Result := 'ToCSG'; try if SharedData_.Data <> nil then Result := SharedData_.Data.sText; except Log('Fail .. GetText()'); end; end; function TPrintHook.GetImagePath: String; begin Result := ''; // try // if SharedData_.Data <> nil then // Result := SharedData_.Data.ssImgPath_; // except // Log('Fail .. GetImagePath()'); // end; end; function TPrintHook.GetFontSize: Integer; begin Result := 0; try if SharedData_.Data <> nil then Result := SharedData_.Data.nFontSize; except Log('Fail .. GetFontSize()'); end; end; function TPrintHook.GetLineCount: Integer; begin Result := 0; try if SharedData_.Data <> nil then Result := SharedData_.Data.nLineCnt; except Log('Fail .. GetLineCount()'); end; end; procedure TPrintHook.SetPtrInfo(sInfo: String); begin try ZeroMemory(@_PrintHook.SharedData_.Data.sPtrInfo, 4096); StrCopy(_PrintHook.SharedData_.Data.sPtrInfo, PChar(sInfo)); except Log('Fail .. SetPtrInfo()'); end; end; procedure TPrintHook.SetCurDocName(sName: String); begin try sCurDocName_ := sName; ZeroMemory(@_PrintHook.SharedData_.Data.sCurDocName, 1024); StrCopy(_PrintHook.SharedData_.Data.sCurDocName, PChar(sCurDocName_)); except Log('Fail .. SetCurDocName()'); end; end; function InstallPrintHook: Integer; begin Result := -1; if Assigned(_PrintHook) then Result := _PrintHook.InstallHook; end; function UninstallPrintHook: Integer; begin Result := -1; if Assigned(_PrintHook) then Result := _PrintHook.UnInstallHook; end; exports InstallPrintHook, UninstallPrintHook; end.