Results 1 to 4 of 4

Thread: Or to be more precise, how do I code a print screen command?

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Aug 2000
    Posts
    31
    Thanks.

  2. #2
    _______ HeSaidJoe's Avatar
    Join Date
    Jun 1999
    Location
    Canada
    Posts
    3,946

    <?>

    DIM:

    My guess is you haven't tested Matthew's answer:

    Timbo: Screen Grab.

    Code:
    'screen grab...command1 and picture1 required
    'saves the picture of the screen to C:\MyDocuments\MyScreen.bmp just change it
     
    Option Explicit
     
    Private Declare Function GetDC Lib "user32" _
    (ByVal hwnd As Long) As Long
    
    Private 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 hSrcDC As Long, ByVal xSrc As Long, ByVal ySrc As Long, _
    ByVal nSrcWidth As Long, ByVal nSrcHeight As Long, ByVal dwRop As Long) As Long
    
    
    Private Sub Command1_Click()
    Dim wScreen As Long
    Dim hScreen As Long
    Dim sWidth As Long
    Dim sHeight As Long
    Dim hdcScreen As Long
    Dim sReturn As Long
    
    Picture1.Cls
    
    wScreen = Screen.Width \ Screen.TwipsPerPixelX
    hScreen = Screen.Height \ Screen.TwipsPerPixelY
    
    Picture1.ScaleMode = vbPixels
    Picture1.AutoRedraw = True
    sWidth = Picture1.ScaleWidth
    sHeight = Picture1.ScaleHeight
    
    
    hdcScreen = GetDC(0)
    
    sReturn = StretchBlt(Picture1.hdc, 0, 0, sWidth, sHeight, hdcScreen, 0, 0, wScreen, hScreen, vbSrcCopy)
    'put the picture in the box
     Picture1.Picture = Picture1.Image
    'Now you can save it using SavePicture
    SavePicture Picture1.Picture, "C:\My Documents\myScree.bmp"
     
    Close
    
    End Sub
    "A myth is not the succession of individual images,
    but an integerated meaningful entity,
    reflecting a distinct aspect of the real world."

    ___ Adolf Jensen

  3. #3
    Guest
    HeSaidJoe, your picture comes out so small.

    But here is to take a screen shot and save it to a file.

    Code:
    Private Declare Sub keybd_event Lib "user32" (ByVal bVk As Byte, ByVal bScan As Byte, _
      ByVal dwFlags As Long, ByVal dwExtraInfo As Long)
    
    Public Function SaveScreen(ByVal theFile As String) As Boolean
    On Error Resume Next
    
        Call keybd_event(vbKeySnapshot, 1, 0, 0)
    
        SavePicture Clipboard.GetData(vbCFBitmap), theFile
    
    SaveScreen = True
    Exit Function
    End Function
    
    Usage:
    
    Call SaveScreen("C:\Windows\Desktop\screen.bmp")

  4. #4
    Addicted Member
    Join Date
    Jan 2000
    Location
    Fresno, California, USA
    Posts
    195
    Try this:


    frmPrintPIC.Picture = CaptureForm(Screen.ActiveForm)
    Call PrintPicture(Printer, frmPrintPIC.Picture)
    Printer.EndDoc

    Public Sub PrintPicture(Prn As Printer, Pic As Picture)

    Const vbHiMetric As Integer = 8

    Dim flScaleAmount As Double

    Dim PrnWidth As Double
    Dim PrnHeight As Double
    Dim PrnPicWidth As Double
    Dim PrnPicHeight As Double

    Prn.Orientation = vbPRORPortrait

    PrnWidth = Prn.ScaleX(Prn.ScaleWidth, Prn.ScaleMode, vbHiMetric)
    PrnHeight = Prn.ScaleY(Prn.ScaleHeight, Prn.ScaleMode, vbHiMetric)

    PrnPicWidth = Prn.ScaleX(PrnWidth, vbHiMetric, Prn.ScaleMode)
    PrnPicHeight = Prn.ScaleY(Pic.Height / PrnWidth * PrnHeight, vbHiMetric, Prn.ScaleMode)
    Prn.PaintPicture Pic, 0, 0, PrnPicWidth, PrnPicHeight

    End Sub

    frmPrintPIC is just a work form with no controls

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width