18. december 2001 - 13:50
#4
Hvad så med (i et modul):
Private Const WM_KEYDOWN = &H100
Private Const WM_KEYUP = &H101
Private Const WM_CHAR = &H102
Private Declare Function PostMessage Lib \"user32\" Alias \"PostMessageA\" (ByVal hWnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
Public Sub PostKeys(ByVal S As String, Optional ByVal wnd As Long = 0, Optional Now As Boolean = False)
Dim i As Integer
Dim KeyCode As Long
On Error Resume Next
If wnd = 0 Then
wnd = frmStartUp.ActiveForm.ActiveControl.hWnd
If wnd = 0 Then wnd = Screen.ActiveForm.ActiveControl.hWnd
If wnd = 0 Then Exit Sub
End If
For i = 1 To Len(S)
KeyCode = ASC(Mid(S, i, 1))
If Now Then
If (KeyCode >= 32) Or (KeyCode = vbKeyEscape) Then SendMessage wnd, WM_CHAR, KeyCode, 0&
If (KeyCode = vbKeyTab) Then
SendMessage wnd, WM_KEYDOWN, KeyCode, 0&
SendMessage wnd, WM_KEYUP, KeyCode, 0&
End If
Else
If (KeyCode >= 32) Or (KeyCode = vbKeyEscape) Then PostMessage wnd, WM_CHAR, KeyCode, 0&
If (KeyCode = vbKeyTab) Then
PostMessage wnd, WM_KEYDOWN, KeyCode, 0&
PostMessage wnd, WM_KEYUP, KeyCode, 0&
End If
End If
Next i
End Sub
og så kalde denne i Timer1_Timer:
PostKeys Chr(vbKeyPrint)
18. december 2001 - 14:49
#11
husk en Timer på Form1. :-)
\'----------------------------------------- Form1 -----------------------------------------
Const RC_PALETTE As Long = &H100
Const SIZEPALETTE As Long = 104
Const RASTERCAPS As Long = 38
Private Type RECT
Left As Long
Top As Long
Right As Long
Bottom As Long
End Type
Private Type PALETTEENTRY
peRed As Byte
peGreen As Byte
peBlue As Byte
peFlags As Byte
End Type
Private Type LOGPALETTE
palVersion As Integer
palNumEntries As Integer
palPalEntry(255) As PALETTEENTRY
End Type
Private Type GUID
Data1 As Long
Data2 As Integer
Data3 As Integer
Data4(7) As Byte
End Type
Private Type PicBmp
Size As Long
Type As Long
hBmp As Long
hPal As Long
Reserved As Long
End Type
Private Declare Function OleCreatePictureIndirect Lib \"olepro32.dll\" (PicDesc As PicBmp, RefIID As GUID, ByVal fPictureOwnsHandle As Long, IPic As IPicture) As Long
Private Declare Function CreateCompatibleDC Lib \"gdi32\" (ByVal hdc As Long) As Long
Private Declare Function CreateCompatibleBitmap Lib \"gdi32\" (ByVal hdc As Long, ByVal nWidth As Long, ByVal nHeight As Long) As Long
Private Declare Function SelectObject Lib \"gdi32\" (ByVal hdc As Long, ByVal hObject As Long) As Long
Private Declare Function GetDeviceCaps Lib \"gdi32\" (ByVal hdc As Long, ByVal iCapabilitiy As Long) As Long
Private Declare Function GetSystemPaletteEntries Lib \"gdi32\" (ByVal hdc As Long, ByVal wStartIndex As Long, ByVal wNumEntries As Long, lpPaletteEntries As PALETTEENTRY) As Long
Private Declare Function CreatePalette Lib \"gdi32\" (lpLogPalette As LOGPALETTE) As Long
Private Declare Function SelectPalette Lib \"gdi32\" (ByVal hdc As Long, ByVal hPalette As Long, ByVal bForceBackground As Long) As Long
Private Declare Function RealizePalette Lib \"gdi32\" (ByVal hdc As Long) As Long
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 DeleteDC Lib \"gdi32\" (ByVal hdc As Long) As Long
Private Declare Function GetDC Lib \"user32\" (ByVal hwnd As Long) As Long
Private Declare Function GetWindowRect Lib \"user32\" (ByVal hwnd As Long, lpRect As RECT) As Long
Private Function CreateBitmapPicture(ByVal hBmp As Long, ByVal hPal As Long) As Picture
Dim R As Long, Pic As PicBmp, IPic As IPicture, IID_IDispatch As GUID
With IID_IDispatch
.Data1 = &H20400
.Data4(0) = &HC0
.Data4(7) = &H46
End With
With Pic
.Size = Len(Pic)
.Type = vbPicTypeBitmap
.hBmp = hBmp
.hPal = hPal
End With
R = OleCreatePictureIndirect(Pic, IID_IDispatch, 1, IPic)
Set CreateBitmapPicture = IPic
End Function
Private Function hDCToPicture(ByVal hDCSrc As Long, ByVal LeftSrc As Long, ByVal TopSrc As Long, ByVal WidthSrc As Long, ByVal HeightSrc As Long) As Picture
Dim hDCMemory As Long, hBmp As Long, hBmpPrev As Long, R As Long
Dim hPal As Long, hPalPrev As Long, RasterCapsScrn As Long, HasPaletteScrn As Long
Dim PaletteSizeScrn As Long, LogPal As LOGPALETTE
hDCMemory = CreateCompatibleDC(hDCSrc)
hBmp = CreateCompatibleBitmap(hDCSrc, WidthSrc, HeightSrc)
hBmpPrev = SelectObject(hDCMemory, hBmp)
RasterCapsScrn = GetDeviceCaps(hDCSrc, RASTERCAPS)
HasPaletteScrn = RasterCapsScrn And RC_PALETTE
PaletteSizeScrn = GetDeviceCaps(hDCSrc, SIZEPALETTE)
If HasPaletteScrn And (PaletteSizeScrn = 256) Then
LogPal.palVersion = &H300
LogPal.palNumEntries = 256
R = GetSystemPaletteEntries(hDCSrc, 0, 256, LogPal.palPalEntry(0))
hPal = CreatePalette(LogPal)
hPalPrev = SelectPalette(hDCMemory, hPal, 0)
R = RealizePalette(hDCMemory)
End If
R = BitBlt(hDCMemory, 0, 0, WidthSrc, HeightSrc, hDCSrc, LeftSrc, TopSrc, vbSrcCopy)
hBmp = SelectObject(hDCMemory, hBmpPrev)
If HasPaletteScrn And (PaletteSizeScrn = 256) Then
hPal = SelectPalette(hDCMemory, hPalPrev, 0)
End If
R = DeleteDC(hDCMemory)
Set hDCToPicture = CreateBitmapPicture(hBmp, hPal)
End Function
Private Sub Form_Load()
Clipboard.SetData hDCToPicture(GetDC(0), 0, 0, Screen.Width / Screen.TwipsPerPixelX, Screen.Height / Screen.TwipsPerPixelY)
Set Me.Picture = hDCToPicture(GetDC(0), 0, 0, Screen.Width / Screen.TwipsPerPixelX, Screen.Height / Screen.TwipsPerPixelY)
Timer1.Interval = 60000
End Sub
Private Sub Timer1_Timer()
Clipboard.SetData hDCToPicture(GetDC(0), 0, 0, Screen.Width / Screen.TwipsPerPixelX, Screen.Height / Screen.TwipsPerPixelY)
Set Me.Picture = hDCToPicture(GetDC(0), 0, 0, Screen.Width / Screen.TwipsPerPixelX, Screen.Height / Screen.TwipsPerPixelY)
End Sub
\'----------------------------------------- Form1 -----------------------------------------
18. december 2001 - 14:54
#12
Jeg fandt den her også:
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 KEYEVENTF_KEYUP = &H2
\'Copy the contents of the screen or the active window
Function GetScreenBitmap(Optional ActiveWindow As Boolean) As
Picture
\' save the current picture in the clipboard, if any
Dim pic As StdPicture
Set pic = Clipboard.GetData(vbCFBitmap)
\' Alt-Print Screen captures the active window only
If ActiveWindow Then
\' Press the Alt key
keybd_event vbKeyMenu, 0, 0, 0
End If
\' Press the Print Screen key
keybd_event vbKeySnapshot, 0, 0, 0
DoEvents
\' Release the Print Screen key
keybd_event vbKeySnapshot, 0, KEYEVENTF_KEYUP, 0
If ActiveWindow Then
\' Release the Alt key
keybd_event vbKeyMenu, 0, KEYEVENTF_KEYUP, 0
End If
DoEvents
\' return the bitmap now in the clipboard
Set GetScreenBitmap = Clipboard.GetData(vbCFBitmap)
\' restore the original contents of the clipboard
Clipboard.SetData pic, vbCFBitmap
End Function
Link:
http://www.vbxtras.com/vbhowto/VBHowTo80.txt