Visual Basic, .NET, ASP, VBScript
 

   
   
     

Форум - Общий форум

Страница: 1 |

 

  Вопрос: Скриншот в нужном месте и нужной формы Добавлено: 05.03.10 19:48  

Автор вопроса:  Alex
Привет всем.
Возник вопрос, как сделать скриншот в форме в определенном месте и нужной формы.
Объясняю на делитанском языке как я вижу: мне надо загружать в форму (браузер) определенную страницу.
В ней надо сделать скриншот в верхнем левом углу с отступом от края примерно 1 сантиметр и сохранить его.
Если можно исходник с описанием пожалуйста.
Спасибо.

Ответить

  Ответы Всего ответов: 2  

Номер ответа: 1
Автор ответа:
 AWP



ICQ: 345685652 

Вопросов: 96
Ответов: 1212
 Web-сайт: xawp.narod.ru
 Профиль | | #1
Добавлено: 05.03.10 21:26
  1. Declare Function GetDC Lib "user32.dll" (ByVal hWnd As Long) As Long
  2. Declare Function GetDesktopWindow Lib "user32.dll" () As Long
  3. Declare Function BitBlt Lib"gdi32"(ByVal hDestDC As Long, ByVal X As Long, ByVal Y As Long, ByVal nWidth As Long, ByValcnHeight As Long, ByVal hSrcDC As Long, ByVal xSrc As Long, ByVal ySrc As Long, ByVal dwRop As Long) As Long
  4.  
  5. deskhwnd = GetDesktopWindow() ' get the desktop's handle
  6. deskhdc = GetDC(deskhwnd) ' get the desktop's device contex

Ответить

Номер ответа: 2
Автор ответа:
 Winand



Вопросов: 87
Ответов: 2795
 Web-сайт: winandfx.narod.ru
 Профиль | | #2
Добавлено: 06.03.10 11:44
http://imagebin.org/index.php?mode=image&id=87730
Для создания превьюшек я юзал CaptureClient отсюда:
  1.       '--------------------------------------------------------------------
  2.       '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
  3.       '
  4.       ' Visual Basic 4.0 16/32 Capture Routines
  5.       '
  6.       ' This module contains several routines for capturing windows into a
  7.       ' picture.  All the routines work on both 16 and 32 bit Windows
  8.       ' platforms.
  9.       ' The routines also have palette support.
  10.       '
  11.       ' CreateBitmapPicture - Creates a picture object from a bitmap and
  12.       ' palette.
  13.       ' CaptureWindow - Captures any window given a window handle.
  14.       ' CaptureActiveWindow - Captures the active window on the desktop.
  15.       ' CaptureForm - Captures the entire form.
  16.       ' CaptureClient - Captures the client area of a form.
  17.       ' CaptureScreen - Captures the entire screen.
  18.       ' PrintPictureToFitPage - prints any picture as big as possible on
  19.       ' the page.
  20.       '
  21.       ' NOTES
  22.       '    - No error trapping is included in these routines.
  23.       '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
  24.       '
  25.       Option Explicit
  26.       Option Base 0
  27.  
  28.       Private Type PALETTEENTRY
  29.          peRed As Byte
  30.          peGreen As Byte
  31.          peBlue As Byte
  32.          peFlags As Byte
  33.       End Type
  34.  
  35.       Private Type LOGPALETTE
  36.          palVersion As Integer
  37.          palNumEntries As Integer
  38.          palPalEntry(255) As PALETTEENTRY  ' Enough for 256 colors.
  39.       End Type
  40.  
  41.       Private Type GUID
  42.          Data1 As Long
  43.          Data2 As Integer
  44.          Data3 As Integer
  45.          Data4(7) As Byte
  46.       End Type
  47.  
  48.         Private Const RASTERCAPS As Long = 38
  49.         Private Const RC_PALETTE As Long = &H100
  50.         Private Const SIZEPALETTE As Long = 104
  51.  
  52.         Private Type RECT
  53.            Left As Long
  54.            Top As Long
  55.            Right As Long
  56.            Bottom As Long
  57.         End Type
  58.  
  59.         Private Declare Function CreateCompatibleDC Lib "GDI32" ( _
  60.            ByVal hDC As Long) As Long
  61.         Private Declare Function CreateCompatibleBitmap Lib "GDI32" ( _
  62.            ByVal hDC As Long, ByVal nWidth As Long, _
  63.            ByVal nHeight As Long) As Long
  64.         Private Declare Function GetDeviceCaps Lib "GDI32" ( _
  65.            ByVal hDC As Long, ByVal iCapabilitiy As Long) As Long
  66.         Private Declare Function GetSystemPaletteEntries Lib "GDI32" ( _
  67.            ByVal hDC As Long, ByVal wStartIndex As Long, _
  68.            ByVal wNumEntries As Long, lpPaletteEntries As PALETTEENTRY) _
  69.            As Long
  70.         Private Declare Function CreatePalette Lib "GDI32" ( _
  71.            lpLogPalette As LOGPALETTE) As Long
  72.         Private Declare Function SelectObject Lib "GDI32" ( _
  73.            ByVal hDC As Long, ByVal hObject As Long) As Long
  74.         Private Declare Function BitBlt Lib "GDI32" ( _
  75.            ByVal hDCDest As Long, ByVal XDest As Long, _
  76.            ByVal YDest As Long, ByVal nWidth As Long, _
  77.            ByVal nHeight As Long, ByVal hDCSrc As Long, _
  78.            ByVal XSrc As Long, ByVal YSrc As Long, ByVal dwRop As Long) _
  79.            As Long
  80.         Private Declare Function DeleteDC Lib "GDI32" ( _
  81.            ByVal hDC As Long) As Long
  82.         Private Declare Function GetForegroundWindow Lib "user32" () _
  83.            As Long
  84.         Private Declare Function SelectPalette Lib "GDI32" ( _
  85.            ByVal hDC As Long, ByVal hPalette As Long, _
  86.            ByVal bForceBackground As Long) As Long
  87.         Private Declare Function RealizePalette Lib "GDI32" ( _
  88.            ByVal hDC As Long) As Long
  89.         Private Declare Function GetWindowDC Lib "user32" ( _
  90.            ByVal hwnd As Long) As Long
  91.         Private Declare Function GetDC Lib "user32" ( _
  92.            ByVal hwnd As Long) As Long
  93.         Private Declare Function GetWindowRect Lib "user32" ( _
  94.            ByVal hwnd As Long, lpRect As RECT) As Long
  95.         Private Declare Function ReleaseDC Lib "user32" ( _
  96.            ByVal hwnd As Long, ByVal hDC As Long) As Long
  97.         Private Declare Function GetDesktopWindow Lib "user32" () As Long
  98.  
  99.         Private Type PicBmp
  100.            Size As Long
  101.            Type As Long
  102.            hBmp As Long
  103.            hPal As Long
  104.            Reserved As Long
  105.         End Type
  106.  
  107.         Private Declare Function OleCreatePictureIndirect _
  108.            Lib "olepro32.dll" (PicDesc As PicBmp, RefIID As GUID, _
  109.            ByVal fPictureOwnsHandle As Long, IPic As IPicture) As Long
  110.  
  111.       '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
  112.       '
  113.       ' CreateBitmapPicture
  114.       '    - Creates a bitmap type Picture object from a bitmap and
  115.       '      palette.
  116.       '
  117.       ' hBmp
  118.       '    - Handle to a bitmap.
  119.       '
  120.       ' hPal
  121.       '    - Handle to a Palette.
  122.       '    - Can be null if the bitmap doesn't use a palette.
  123.       '
  124.       ' Returns
  125.       '    - Returns a Picture object containing the bitmap.
  126.       '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
  127.       '
  128.          Public Function CreateBitmapPicture(ByVal hBmp As Long, _
  129.             ByVal hPal As Long) As Picture
  130.  
  131.             Dim r As Long
  132.          Dim Pic As PicBmp
  133.          ' IPicture requires a reference to "Standard OLE Types."
  134.          Dim IPic As IPicture
  135.          Dim IID_IDispatch As GUID
  136.  
  137.          ' Fill in with IDispatch Interface ID.
  138.          With IID_IDispatch
  139.             .Data1 = &H20400
  140.             .Data4(0) = &HC0
  141.             .Data4(7) = &H46
  142.          End With
  143.  
  144.          ' Fill Pic with necessary parts.
  145.          With Pic
  146.             .Size = Len(Pic)          ' Length of structure.
  147.             .Type = vbPicTypeBitmap   ' Type of Picture (bitmap).
  148.             .hBmp = hBmp              ' Handle to bitmap.
  149.             .hPal = hPal              ' Handle to palette (may be null).
  150.          End With
  151.  
  152.          ' Create Picture object.
  153.          r = OleCreatePictureIndirect(Pic, IID_IDispatch, 1, IPic)
  154.  
  155.          ' Return the new Picture object.
  156.          Set CreateBitmapPicture = IPic
  157.       End Function
  158.  
  159.       '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
  160.       '
  161.       ' CaptureWindow
  162.       '    - Captures any portion of a window.
  163.       '
  164.       ' hWndSrc
  165.       '    - Handle to the window to be captured.
  166.       '
  167.       ' Client
  168.       '    - If True CaptureWindow captures from the client area of the
  169.       '      window.
  170.       '    - If False CaptureWindow captures from the entire window.
  171.       '
  172.       ' LeftSrc, TopSrc, WidthSrc, HeightSrc
  173.       '    - Specify the portion of the window to capture.
  174.       '    - Dimensions need to be specified in pixels.
  175.       '
  176.       ' Returns
  177.       '    - Returns a Picture object containing a bitmap of the specified
  178.       '      portion of the window that was captured.
  179.       '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
  180.       ''''''
  181.       '
  182.          Public Function CaptureWindow(ByVal hWndSrc As Long, _
  183.             ByVal Client As Boolean, ByVal LeftSrc As Long, _
  184.             ByVal TopSrc As Long, ByVal WidthSrc As Long, _
  185.             ByVal HeightSrc As Long) As Picture
  186.  
  187.             Dim hDCMemory As Long
  188.             Dim hBmp As Long
  189.             Dim hBmpPrev As Long
  190.             Dim r As Long
  191.             Dim hDCSrc As Long
  192.             Dim hPal As Long
  193.             Dim hPalPrev As Long
  194.             Dim RasterCapsScrn As Long
  195.             Dim HasPaletteScrn As Long
  196.             Dim PaletteSizeScrn As Long
  197.          Dim LogPal As LOGPALETTE
  198.  
  199.          ' Depending on the value of Client get the proper device context.
  200.          If Client Then
  201.             hDCSrc = GetDC(hWndSrc) ' Get device context for client area.
  202.          Else
  203.             hDCSrc = GetWindowDC(hWndSrc) ' Get device context for entire
  204.                                           ' window.
  205.          End If
  206.  
  207.          ' Create a memory device context for the copy process.
  208.          hDCMemory = CreateCompatibleDC(hDCSrc)
  209.          ' Create a bitmap and place it in the memory DC.
  210.          hBmp = CreateCompatibleBitmap(hDCSrc, WidthSrc, HeightSrc)
  211.          hBmpPrev = SelectObject(hDCMemory, hBmp)
  212.  
  213.          ' Get screen properties.
  214.          RasterCapsScrn = GetDeviceCaps(hDCSrc, RASTERCAPS) ' Raster
  215.                                                             ' capabilities.
  216.          HasPaletteScrn = RasterCapsScrn And RC_PALETTE       ' Palette
  217.                                                               ' support.
  218.          PaletteSizeScrn = GetDeviceCaps(hDCSrc, SIZEPALETTE) ' Size of
  219.                                                               ' palette.
  220.  
  221.          ' If the screen has a palette make a copy and realize it.
  222.          If HasPaletteScrn And (PaletteSizeScrn = 256) Then
  223.             ' Create a copy of the system palette.
  224.             LogPal.palVersion = &H300
  225.             LogPal.palNumEntries = 256
  226.             r = GetSystemPaletteEntries(hDCSrc, 0, 256, _
  227.                 LogPal.palPalEntry(0))
  228.             hPal = CreatePalette(LogPal)
  229.             ' Select the new palette into the memory DC and realize it.
  230.             hPalPrev = SelectPalette(hDCMemory, hPal, 0)
  231.             r = RealizePalette(hDCMemory)
  232.          End If
  233.  
  234.          ' Copy the on-screen image into the memory DC.
  235.          r = BitBlt(hDCMemory, 0, 0, WidthSrc, HeightSrc, hDCSrc, _
  236.             LeftSrc, TopSrc, vbSrcCopy)
  237.  
  238.       ' Remove the new copy of the  on-screen image.
  239.          hBmp = SelectObject(hDCMemory, hBmpPrev)
  240.  
  241.          ' If the screen has a palette get back the palette that was
  242.          ' selected in previously.
  243.          If HasPaletteScrn And (PaletteSizeScrn = 256) Then
  244.             hPal = SelectPalette(hDCMemory, hPalPrev, 0)
  245.          End If
  246.  
  247.          ' Release the device context resources back to the system.
  248.          r = DeleteDC(hDCMemory)
  249.          r = ReleaseDC(hWndSrc, hDCSrc)
  250.  
  251.          ' Call CreateBitmapPicture to create a picture object from the
  252.          ' bitmap and palette handles. Then return the resulting picture
  253.          ' object.
  254.          Set CaptureWindow = CreateBitmapPicture(hBmp, hPal)
  255.       End Function
  256.  
  257.       '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
  258.       '
  259.       ' CaptureScreen
  260.       '    - Captures the entire screen.
  261.       '
  262.       ' Returns
  263.       '    - Returns a Picture object containing a bitmap of the screen.
  264.       '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
  265.       '
  266.       Public Function CaptureScreen() As Picture
  267.         Dim hWndScreen As Long
  268.  
  269.          ' Get a handle to the desktop window.
  270.          hWndScreen = GetDesktopWindow()
  271.  
  272.          ' Call CaptureWindow to capture the entire desktop give the handle
  273.          ' and return the resulting Picture object.
  274.  
  275.          Set CaptureScreen = CaptureWindow(hWndScreen, False, 0, 0, _
  276.             Screen.Width \ Screen.TwipsPerPixelX, _
  277.             Screen.Height \ Screen.TwipsPerPixelY)
  278.       End Function
  279.  
  280.       '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
  281.       '
  282.       ' CaptureForm
  283.       '    - Captures an entire form including title bar and border.
  284.       '
  285.       ' frmSrc
  286.       '    - The Form object to capture.
  287.       '
  288.       ' Returns
  289.       '    - Returns a Picture object containing a bitmap of the entire
  290.       '      form.
  291.       '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
  292.       '
  293.       Public Function CaptureForm(frmSrc As Form) As Picture
  294.          ' Call CaptureWindow to capture the entire form given its window
  295.          ' handle and then return the resulting Picture object.
  296.          Set CaptureForm = CaptureWindow(frmSrc.hwnd, False, 0, 0, _
  297.             frmSrc.ScaleX(frmSrc.Width, vbTwips, vbPixels), _
  298.             frmSrc.ScaleY(frmSrc.Height, vbTwips, vbPixels))
  299.       End Function
  300.  
  301.       '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
  302.       '
  303.       ' CaptureClient
  304.       '    - Captures the client area of a form.
  305.       '
  306.       ' frmSrc
  307.       '    - The Form object to capture.
  308.       '
  309.       ' Returns
  310.       '    - Returns a Picture object containing a bitmap of the form's
  311.       '      client area.
  312.       '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
  313.       '
  314.       Public Function CaptureClient(frmSrc As Form) As StdPicture
  315.          ' Call CaptureWindow to capture the client area of the form given
  316.          ' its window handle and return the resulting Picture object.
  317.          Set CaptureClient = CaptureWindow(frmSrc.hwnd, True, 0, 0, _
  318.             frmSrc.ScaleX(frmSrc.ScaleWidth, frmSrc.ScaleMode, vbPixels), _
  319.             frmSrc.ScaleY(frmSrc.ScaleHeight, frmSrc.ScaleMode, vbPixels))
  320.       End Function
  321.  
  322.       '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
  323.       '
  324.       ' CaptureActiveWindow
  325.       '    - Captures the currently active window on the screen.
  326.       '
  327.       ' Returns
  328.       '    - Returns a Picture object containing a bitmap of the active
  329.       '      window.
  330.       '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
  331.       '
  332.       Public Function CaptureActiveWindow() As Picture
  333.         Dim hWndActive As Long
  334.         Dim r As Long
  335.          Dim RectActive As RECT
  336.  
  337.          ' Get a handle to the active/foreground window.
  338.          hWndActive = GetForegroundWindow()
  339.  
  340.          ' Get the dimensions of the window.
  341.          r = GetWindowRect(hWndActive, RectActive)
  342.  
  343.          ' Call CaptureWindow to capture the active window given its
  344.          ' handle and return the Resulting Picture object.
  345.       Set CaptureActiveWindow = CaptureWindow(hWndActive, False, 0, 0, _
  346.             RectActive.Right - RectActive.Left, _
  347.             RectActive.Bottom - RectActive.Top)
  348.       End Function
  349.  
  350.       '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
  351.       '
  352.       ' PrintPictureToFitPage
  353.       '    - Prints a Picture object as big as possible.
  354.       '
  355.       ' Prn
  356.       '    - Destination Printer object.
  357.       '
  358.       ' Pic
  359.       '    - Source Picture object.
  360.       '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
  361.       '
  362.       Public Sub PrintPictureToFitPage(Prn As Printer, Pic As Picture)
  363.          Const vbHiMetric As Integer = 8
  364.          Dim PicRatio As Double
  365.          Dim PrnWidth As Double
  366.          Dim PrnHeight As Double
  367.          Dim PrnRatio As Double
  368.          Dim PrnPicWidth As Double
  369.          Dim PrnPicHeight As Double
  370.  
  371.          ' Determine if picture should be printed in landscape or portrait
  372.          ' and set the orientation.
  373.          If Pic.Height >= Pic.Width Then
  374.             Prn.Orientation = vbPRORPortrait   ' Taller than wide.
  375.          Else
  376.             Prn.Orientation = vbPRORLandscape  ' Wider than tall.
  377.          End If
  378.  
  379.          ' Calculate device independent Width-to-Height ratio for picture.
  380.          PicRatio = Pic.Width / Pic.Height
  381.  
  382.          ' Calculate the dimentions of the printable area in HiMetric.
  383.          PrnWidth = Prn.ScaleX(Prn.ScaleWidth, Prn.ScaleMode, vbHiMetric)
  384.          PrnHeight = Prn.ScaleY(Prn.ScaleHeight, Prn.ScaleMode, vbHiMetric)
  385.          ' Calculate device independent Width to Height ratio for printer.
  386.          PrnRatio = PrnWidth / PrnHeight
  387.  
  388.          ' Scale the output to the printable area.
  389.          If PicRatio >= PrnRatio Then
  390.             ' Scale picture to fit full width of printable area.
  391.             PrnPicWidth = Prn.ScaleX(PrnWidth, vbHiMetric, Prn.ScaleMode)
  392.             PrnPicHeight = Prn.ScaleY(PrnWidth / PicRatio, vbHiMetric, _
  393.                Prn.ScaleMode)
  394.          Else
  395.             ' Scale picture to fit full height of printable area.
  396.             PrnPicHeight = Prn.ScaleY(PrnHeight, vbHiMetric, Prn.ScaleMode)
  397.             PrnPicWidth = Prn.ScaleX(PrnHeight * PicRatio, vbHiMetric, _
  398.                Prn.ScaleMode)
  399.          End If
  400.  
  401.          ' Print the picture using the PaintPicture method.
  402.          Prn.PaintPicture Pic, 0, 0, PrnPicWidth, PrnPicHeight
  403.       End Sub
  404.       '--------------------------------------------------------------------

Ответить

Страница: 1 |

Поиск по форуму



© Copyright 2002-2011 VBNet.RU | Пишите нам