Visual Basic Code , VB.NET Code, VB Code
  Home   :  Code   :  Forums   :  Submit   :  Mailing List   :  About   :  Contact


Snapshot via ActiveX Control


Snapshot via ActiveX Control

Author
Message
Olaf83
Olaf83
Forum God
Forum God (893 reputation)Forum God (893 reputation)Forum God (893 reputation)Forum God (893 reputation)Forum God (893 reputation)Forum God (893 reputation)Forum God (893 reputation)Forum God (893 reputation)Forum God (893 reputation)

Group: Forum Members
Posts: 3, Visits: 1

hey I'm new here and have a big problem with ActiveX

I want to create a snapshot from my .htm,

but the code doesn't work.

could you find any mistakes?

###############

Option Explicit

Private Declare Function BitBlt Lib "gdi32" ( _
  ByVal hDestDC 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 dwRop As Long) As Long

Private Declare Function GetDC Lib "user32" ( _
  ByVal hWnd As Long) As Long

Private Declare Function ReleaseDC Lib "user32" ( _
  ByVal hWnd As Long, _
  ByVal hdc As Long) As Long

Private Declare Function GetDesktopWindow Lib "user32" () As Long


Public Sub Snapshot(oForm As Form, ByVal sFile As String, _
  Optional ByVal x As Variant, _
  Optional ByVal y As Variant, _
  Optional ByVal nWidth As Variant, _
  Optional ByVal nHeight As Variant)

  Dim hWnd As Long
  Dim nDC As Long
  Dim oPicBox As Control


  hWnd = GetDesktopWindow()
  nDC = GetDC(hWnd)

    If IsMissing(x) Then x = 0
  If IsMissing(y) Then y = 0
  If IsMissing(nWidth) Then nWidth = Screen.Width * Screen.TwipsPerPixelX
  If IsMissing(nHeight) Then nHeight = Screen.Height * Screen.TwipsPerPixelY

  Set oPicBox = oForm.Controls.Add("VB.PictureBox", "myPicTemp")
  With oPicBox
    .ScaleMode = vbPixels
    .Width = oForm.ScaleX(nWidth, vbPixels, oForm.ScaleMode)
    .Height = oForm.ScaleY(nHeight, vbPixels, oForm.ScaleMode)


    .AutoRedraw = True
    BitBlt .hdc, 0, 0, nWidth, nHeight, nDC, x, y, vbSrcCopy

    SavePicture .Image, sFile

    ' DC wieder freigeben
    ReleaseDC hWnd, nDC
  End With

  oForm.Controls.Remove "myPicTemp"
End Sub

Private Sub Command1_Click()
Snapshot Me, "c:\bild.bmp", 100, 100, 400, 400
End Sub

Private Sub Command1_Click()
Snapshot Me, "c:\bild.bmp", 100, 100, 400, 400
End Sub

 

#########

 

so one Error with Public at "Sub Screenshot" ? but I do not understand this error

 

can you help me?


DigiRev
DigiRev
Forum God
Forum God (23K reputation)Forum God (23K reputation)Forum God (23K reputation)Forum God (23K reputation)Forum God (23K reputation)Forum God (23K reputation)Forum God (23K reputation)Forum God (23K reputation)Forum God (23K reputation)

Group: Forum Members
Posts: 511, Visits: 265
Here's a good example of doing it with the API, it also lets you save as a JPG file.
http://www.Planet-Source-Code.com/vb/scripts/ShowCode.asp?txtCodeId=7270&lngWId=1
 
Or, you can do it like this:
 
1.) Add a CommandButton to your form and named it: Command1
2.) Add a PictureBox to your form and name it: PicSS
3.) Remove all code from the form and paste this in there:

Private Declare Sub keybd_event Lib "user32" (ByVal bVk As Byte, ByVal bScan As Byte, ByVal dwFlags As Long, ByVal dwExtraInfo As Long)

Private Const VK_SNAPSHOT = &H2C

Private Sub Command1_Click()
Clipboard.Clear
keybd_event VK_SNAPSHOT, 0, 0, 0
DoEvents
picSS.Picture = Clipboard.GetData
SavePicture picSS.Image, "C:\Screenshot.bmp"
End Sub


Olaf83
Olaf83
Forum God
Forum God (893 reputation)Forum God (893 reputation)Forum God (893 reputation)Forum God (893 reputation)Forum God (893 reputation)Forum God (893 reputation)Forum God (893 reputation)Forum God (893 reputation)Forum God (893 reputation)

Group: Forum Members
Posts: 3, Visits: 1

oh thanx.. this work fine.. but I need some code to define an explicit area on the screen!

can you help me in this case too?

 

kind regards


DigiRev
DigiRev
Forum God
Forum God (23K reputation)Forum God (23K reputation)Forum God (23K reputation)Forum God (23K reputation)Forum God (23K reputation)Forum God (23K reputation)Forum God (23K reputation)Forum God (23K reputation)Forum God (23K reputation)

Group: Forum Members
Posts: 511, Visits: 265

http://www.Planet-Source-Code.com/vb/scripts/ShowCode.asp?txtCodeId=7270&lngWId=1

In that source code, there is a function to capture a certain part of the screen, judging by the Left, Top, Width, and Height values. You'll have to look through it a bit and find it.


Olaf83
Olaf83
Forum God
Forum God (893 reputation)Forum God (893 reputation)Forum God (893 reputation)Forum God (893 reputation)Forum God (893 reputation)Forum God (893 reputation)Forum God (893 reputation)Forum God (893 reputation)Forum God (893 reputation)

Group: Forum Members
Posts: 3, Visits: 1

i can't open this project.. i've only vb5 CCE so i can't see the sourcecode!

can you post the code or send me via mail

thomas83@gmx.de

 

king regards


TrickyRic
TrickyRic
Forum God
Forum God (92K reputation)Forum God (92K reputation)Forum God (92K reputation)Forum God (92K reputation)Forum God (92K reputation)Forum God (92K reputation)Forum God (92K reputation)Forum God (92K reputation)Forum God (92K reputation)

Group: Forum Members
Posts: 711, Visits: 6
vb files are just plain text, you should be able to view them all in notepad .




API Guide - VB/MySQL - W3Schools - WinsockVB

GO


Similar Topics


Reading This Topic


Login
Existing Account
Email Address:


Password:


Social Logins

Select a Forum....

















A1VBCode Forums


Search