Home > database >  Please sleep on the night of urban teachers take a screenshot of problem printing
Please sleep on the night of urban teachers take a screenshot of problem printing

Time:09-18

* this code is online, is said to have been sleeping on the night of city teacher's code, please have a look at the code does not perform the reason, I mainly want to print the mouse click on the image to print directly, please the teacher give directions!

DECLARE an INTEGER FindWindow IN user32 STRING lpClassName, STRING lpWindowName
DECLARE an INTEGER GetDC IN user32 INTEGER HWND
Declare SHORT GetWindowRect IN user32 INTEGER HWND, STRING @ lpRect
DECLARE Long GetWindowDC WIN32API IN Long hWnd
DECLARE Long ReleaseDC WIN32API IN Long hWnd, Long hDc
DECLARE Long CreateCompatibleDC WIN32API IN Long hDc
DECLARE Long DeleteDC WIN32API IN Long hDc
DECLARE Long CreateCompatibleBitmap WIN32API IN Long hDc, Long nWidth, Long nHeight
DECLARE Long BitBlt WIN32API IN Long hDestDC, Long nXDest, Long nYDest, Long nWidth, Long nHeight, Long hSrcDC, Long nXSrc, Long nYSrc, Long dwRop
DECLARE Long SelectObject WIN32API IN Long hDc, Long hObject
DECLARE Long DeleteObject WIN32API IN Long hObject
DECLARE Long GdiplusStartup IN gdiplus Long @ token, String @ inputbuf, Long @ outputbuf
DECLARE Long GdiplusShutdown gdiplus IN Long token
DECLARE Long GdipCreateBitmapFromHBITMAP gdiplus IN Long hbitmap, Long hpalette, Long @ hGpBitmap
DECLARE Long GdipDisposeImage gdiplus IN Long image
DECLARE Long GdipSaveImageToFile gdiplus IN Long nImage, String FileName, String clsIdEncoder, Long encoderParams

* * the above API is not just copy all used to come in, too lazy to delete!
DECLARE an INTEGER PrintWindow IN user32 INTEGER, INTEGER, INTEGER

# define SRCCOPY 0 x00cc0020 LOCAL cFileExtName cEncoder, iInputBuf, iResult
LOCAL hDesktopDc, hVDc, hBitmap, hToken hGdipBitmap
M.h Wnd=FindWindow (" Notepad ", NULL) & amp; & Interception of a text window try
TcFile=LOWER (' d: \ aaa. JPG) & amp; & JPG format images
M.c FileExtName=LOWER (JUSTEXT (m. cFile))
LpRect=REPLI (CRH (0), 16)
GetWindowRect (m.h Wnd, @ lpRect)
LnWidth=ctob (SUBS (lpRect, 9, 4), '4 rs) - ctob (SUBS (lpRect, 1, 4),' 4 rs) & amp; & Window width
LnHeight=ctob (SUBS (lpRect, 13, 4), '4 rs) - ctob (SUBS (lpRect, 5, 4),' 4 rs) & amp; & Window height

M.h DesktopDc=GetDC (m.h Wnd)
M.h Vdc=CreateCompatibleDC (m.h DesktopDc)
M.h Bitmap=CreateCompatibleBitmap (m.h DesktopDc lnWidth, lnHeight)
ABC=SelectObject (m.h Vdc, m.h Bitmap)
I=PrintWindow (m.h Wnd, m.h Vdc, 0)
SelectObject (m.h Vdc, ABC)
* BitBlt (m.h Vdc, 0, 0, lnWidth, lnHeight, m.h DesktopDc, 0, 0, SRCCOPY)

M.h Token=0
M.i InputBuf=0 h01-2 + REPLICATE (CRH (0), 15)
M.i Result=1
IF (0==GdiplusStartup (@ m.h Token, @ m.i InputBuf, 0))
M.h GdipBitmap=0
IF (0==GdipCreateBitmapFromHBITMAP (;
M.h Bitmap, 0, @ m.h GdipBitmap))
M.c Encoder=ICASE (;
'JPG'==m.c FileExtName, h01-2, 0;
'GIF'==m.c FileExtName, 0 h02,;
'tif==m.c FileExtName, 0 h05,;
'the PNG'==m.c FileExtName, 0 h06, 0 h00);
+ 0 hf47c55041ad3119a730000f81ef32e
M.i Result=GdipSaveImageToFile (;
M.h GdipBitmap,;
STRCONV (m. cFile + CRH (0), 5),;
M.c Encoder, 0)
GdipDisposeImage (m.h GdipBitmap)
ENDIF
GdiplusShutdown (m.h Token)
ENDIF

DeleteObject (m.h Bitmap)
DeleteDC m.h (Vdc)
ReleaseDC (0, m.h DesktopDc)

CodePudding user response:

Use a ShellExecute stupid way temporarily transition at first, look forward to each master advice!

CodePudding user response:

M.h Wnd=FindWindow (" Notepad ", NULL) & amp; & Interception of a text window try
This window name to intercept correspond with you

CodePudding user response:

That a word has been changed to m.h Wnd=thisform. The hWnd, the main reason is that the code without any response, is not an error

CodePudding user response:

Your program on debugging, I found no problem the above code, the code is used to generate screenshots files, not for print screen, run the code above normal can generate screenshots file 'd: \ aaa. JPG, if you want to click on the print function, apparently the code above is not enough, at least one open Notepad file, and then design a screenshot of the button, the button code to write the code above, at the same time at the back of the code should add' d: \ aaa. JPG image file printed code,

CodePudding user response:

If you want to achieve at the CLICK of a button to print, print button above to code using the TIMER event, let the TIMER event detection in the background the scope of the mouse, if the scope of "Notepad" open, and screen printing operations executed when the CLICK event,
  •  Tags:  
  • VFP
  • Related