Also in meinem Lupen Projekt nutze ich folgenden Code...
' Form1
Option Explicit
Private Declare Function GetDesktopWindow Lib "user32" () 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 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 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 GetCursorPos Lib "user32" (lpPoint As pointAPI) As Long
Private Declare Function GetWindowRect Lib "user32" (ByVal hWND As Long, lpRect _
As RECT) As Long
Private Type pointAPI
x As Long
y As Long
End Type
Private Type RECT
Left As Long
Top As Long
Right As Long
Bottom As Long
End Type
Private Const SRCCOPY = &HCC0020
Private Const SRCAND = &H8800C6
Private Const SRCERASE = &H440328
Private Const SRCINVERT = &H660046
Private Const SRCPAINT = &HEE0086
Dim DhDC As Long
Dim DhWnd As Long
Private Sub Form_Load()
DhWnd = GetDesktopWindow
DhDC = GetDC(DhWnd)
CreateHotKey vbKeyF2, Me.hWND
End Sub
Private Sub Form_Unload(Cancel As Integer)
Call ReleaseDC(DhWnd, hDC)
DestroyHotKey Me.hWND
End Sub
Private Sub Timer1_Timer()
Dim mPos As pointAPI
Dim x As Integer, y As Integer, w As Integer, h As Integer, sw As Integer, _
sh As Integer
GetCursorPos mPos
Picture1.Cls
Picture1.ScaleMode = vbPixels
w = Picture1.ScaleWidth
h = Picture1.ScaleHeight
sw = w * (1 / 2)
sh = h * (1 / 2)
x = mPos.x - sw \ 2
y = mPos.y - sh \ 2
StretchBlt Picture1.hDC, 0, 0, w, h, DhDC, x, y, sw, sh, SRCCOPY
End Sub ' Modul1
Option Explicit
Public Const GWL_WNDPROC As Long = (-4)
Public Const WM_HOTKEY As Long = &H312
Public Const MOD_ALT = &H1
Public Const MOD_CONTROL = &H2
Public Const MOD_SHIFT = &H4
Public Declare Function GlobalAddAtom Lib "kernel32" Alias "GlobalAddAtomA" _
(ByVal lpString As String) As Long
Public Declare Function GlobalDeleteAtom Lib "kernel32" _
(ByVal nAtom As Long) As Long
Public Declare Function RegisterHotKey Lib "user32" _
(ByVal hWND As Long, _
ByVal id As Long, _
ByVal fsModifiers As Long, _
ByVal vk As Long) As Long
Public Declare Function UnregisterHotKey Lib "user32" _
(ByVal hWND As Long, _
ByVal id As Long) As Long
Public Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" _
(ByVal hWND As Long, _
ByVal nIndex As Long, _
ByVal dwNewLong As Long) As Long
Public Declare Function CallWindowProc Lib "user32" Alias "CallWindowProcA" _
(ByVal lpPrevWndFunc As Long, _
ByVal hWND As Long, _
ByVal Msg As Long, _
ByVal wParam As Long, _
ByVal lParam As Long) As Long
Public mlngLastWndProc As Long
Public mlngAtom As Long
Function WindowProc(ByVal hWND As Long, _
ByVal uMsg As Long, _
ByVal wParam As Long, _
ByVal lParam As Long) As Long
If hWND = Form1.hWND And uMsg = WM_HOTKEY Then
Form1.Timer1.Enabled = False
Else
Form1.Timer1.Enabled = True
End If
WindowProc = CallWindowProc(mlngLastWndProc, hWND, uMsg, wParam, lParam)
End Function
Public Sub CreateHotKey(ByVal intKeyCode As Integer, _
ByVal hWND As Long)
mlngAtom = GlobalAddAtom(CStr(Now))
mlngLastWndProc = SetWindowLong(hWND, GWL_WNDPROC, _
AddressOf WindowProc)
RegisterHotKey hWND, mlngAtom, 0, intKeyCode
End Sub
Public Sub DestroyHotKey(ByVal hWND As Long)
UnregisterHotKey hWND, GlobalDeleteAtom(mlngAtom)
Call SetWindowLong(hWND, GWL_WNDPROC, mlngLastWndProc)
End Sub So nun das Problem...wenn ich das Projekt starte und F2 drücke wird das Bild in meiner Lupe "eingefroren". Das funktioniert auch so wie es soll, aber wenn ich nochmal F2 drücke passiert gar nichts, eigentlich sollte es weiter gehen mit dem Anzeigen in der Lupe. Es geht aber erst weiter, wenn ich mit der Maus über meine Form fahre.
Wo liegt nun der fehler, das beim 2ten mal F2 drücken nichts passiert?
mfg
Lexx |