How to screen you and save as file

xiaoxiao2021-03-06  37

One. The effect to be implemented: the user drags the mouse on the screen, generates a box selection area; release the screen image of the box selection area when the mouse is released as the BMP file. The project has a BorderStyle = None, schelamode = pixels, a list of Visible = False placed on the form, which is used to select the screen area when the screen is selected. three. Implementation Process: Users Press F10 [Press F10 Recovery Forms again], hide the form, place the screen image in memory DC, maximize this form, display the form, copy the screen image in the memory DC to the form . When the user presses the mouse on the form, the location is recorded as the starting point; the user is dragged the form to reflect the selected area by changing the position of the dummy box; the user releases the image of the box selection area when the user releases the image. Go to the file. four. The key points are two: 1, copy the screen image to the maximized form to hide the "This" form is entered in the last screen image; 2. According to the form [actually includes any HWND object] The handle to save the form image. Fives. Sample code '[For simplicity, all code is placed in a form] Option ExplicitPrivate BLNMaximized As Booleanprivate Intoldx AS IntegerPrivate Intoldy As Integer

Private Declare Function OleCreatePictureIndirect Lib "olepro32.dll" (PicDesc As PicBmp, RefIID As GUID, ByVal fPictureOwnsHandle As Long, IPic As IPicture) As LongPrivate Declare Function CreateCompatibleDC Lib "gdi32" (ByVal hdc As Long) As LongPrivate Declare Function CreateCompatibleBitmap Lib " gdi32 "(ByVal hdc As Long, ByVal nWidth As Long, ByVal nHeight As Long) As LongPrivate Declare Function StretchBlt Lib" gdi32 "(ByVal hdc As Long, ByVal x As Long, ByVal y As Long, ByVal nWidth As Long, ByVal nHeight As Long, ByVal hhdc As Long, ByVal xSrc As Long, ByVal ySrc As Long, ByVal nSrcWidth As Long, ByVal nSrcHeight As Long, ByVal dwRop As Long) As LongPrivate Declare Function SelectObject Lib "gdi32" (ByVal hdc As Long, ByVal hObject As Long) As LongPrivate Declare Function DeleteDC Lib "gdi32" (ByVal hdc As Long) As LongPrivate Declare Function DeleteObject Lib "gdi32" (ByVal hObject As Long) As LongPrivate Declare Function GetDC Lib "user32" (ByVal hWnd As Long) As LongPrivate Di eclare Function ReleaseDC Lib "user32" (ByVal hWnd As Long, ByVal hdc As Long) As LongPrivate Declare Function ShowWindow Lib "user32" (ByVal hWnd As Long, ByVal nCmdShow As Long) As Long'ShowWindow top of nCmdShow optional parameter Const SW_MAXIMIZE = 3Const SW_RESTORE = 9Private Type GUID Data1 As Long Data2 As Integer Data3 As Integer Data4 (7) As ByteEnd TypePrivate Type PicBmp Size As Long Type As Long hBmp As Long hPal As Long Reserved As LongEnd Type

Function hDCToPicture (ByVal hDCSrc As Long, ByVal LeftSrc As Long, ByVal TopSrc As Long, ByVal WidthSrc As Long, ByVal HeightSrc As Long) As Picture 'to ensure that the parameters LeftSrc, TopSrc, WidthSrc, HeightSrc units of pixels !! Dim hDCMemory As Long, hBmp As Long Dim hPal As Long Dim Pic As PicBmp, IPic As IPicture, IID_IDispatch As GUID hDCMemory = CreateCompatibleDC (hDCSrc) hBmp = CreateCompatibleBitmap (hDCSrc, WidthSrc, HeightSrc) DeleteObject SelectObject (hDCMemory, hBmp) 'Copy the source image to Outsrc, widthsrc, heightsrc, widthsrc, heightsrc, widthsrc, heightsrc, widthsrc, heightsrc, vbsrccopy

With IID_IDispatch .Data1 = & H20400 .Data4 (0) = & HC0 .Data4 (7) = & H46 End With 'Fill picture info With Pic .Size = Len (Pic)' Length of structure .Type = vbPicTypeBitmap 'Type of Picture (bitmap) .hBmp = hBmp 'Handle to bitmap .hPal = 0 End With' Create the picture OleCreatePictureIndirect Pic, IID_IDispatch, 1, IPic DeleteDC hDCMemory 'DeleteObject hBmp Set hDCToPicture = IPicEnd Function Private Sub Form_DblClick ()' provides a closed form approach EndEnd Sub Private Sub Form_KeyUp (KeyCode As Integer, Shift As Integer) If KeyCode = vbKeyF10 Then blnMaximized = Not blnMaximized If blnMaximized Then Me.Visible = False DoEvents ShowWindow Me.hWnd, SW_MAXIMIZE 'copy of the image to the screen form ScreenToForm Me.Visible = True else showwindow me.hwnd, sw_restore cls end if end ifend sub private subs screentoform () DIM HBITMAP AS Long Dim hMemDC As Long Dim W As Integer Dim H As Integer W = Screen.Width / Screen.TwipsPerPixelX H = Screen.Height / Screen.TwipsPerPixelY hBitMap = CreateCompatibleBitmap (hdc, W, H) DeleteObject SelectObject (hMemDC, hBitMap) StretchBlt hdc, 0, 0, W, H, GETDC (0), 0, 0, W, H, VBSRCCopy deletedc HMEMDC DeleteObject HbitMapend Sub Private Sub Form_Mousedown (Button As INTEGER, SHIFT AS INTEGER, X As Single, Y as single) if blnmaximized = True dam = x intoldy = y sp1.visible =

转载请注明原文地址:https://www.9cbs.com/read-62322.html

New Post(0)