habe mal einen Snippertest am Windows 8.1 ausprobiert. Läuft nicht mehr, weil Maus und Bildausschnitt nicht zusammen passen! Hab die Sache mit PB 5.23 und 5.30 x64 getest, kein unterschied!
Mache es momentan so das ich das Bild Resize von 2160,1440 auf 1440,960.
Code: Alles auswählen
; Snipping TEST am Microsoft SURFACE 3 Pro
; Desktopauflösung 2160 x 1440
;
; Bildausschneiden am Desktop
; Dient zum Ausschneiden von Bilder am Desktop
; Mittels ESC kann abgebrochen werden
AnzahlDesktop.i = ExamineDesktops() ; Gibt die Anzahl der Desktops zurück
Debug "AnzahlDesktop= " + AnzahlDesktop
Debug DesktopWidth(0)
Debug DesktopHeight(0)
;DesktopMouseY()
InitMouse()
Enumeration
#FrameMain; Für MainWindows
#ParentWindow; für SnipperParentWindows
#ChildWindow ; für SnipperChildWindows
EndEnumeration
;{-Image Plugin
UsePNGImageDecoder(); Encoder
UsePNGImageEncoder(); Decoder
;}
Enumeration
#TastenDruckEscape
#BildAusschneiden
#BildVomDesktop
#FensterKlick
#XI_ChildButton
#XI_SnipperEinAus
#XI_Image
#XI_StartP
#XI_EndeP
#XI_VirtStartP
#XI_VirtStartP2
#XI_VirtEndeP
#XI_SchnittP
#Snipperaktiv
EndEnumeration
Enumeration
#imgCapture
#DesktopImage
#myImage
#myImage2
#Testbild
#myKleinDisplay
#ProcedureImage
EndEnumeration
Global MeinWindows
Global Showline
Global yy
Global ww
Global frc.RECT
Global X1
Global Y1
Global IX
Global IY
Global MX
Global MY
Global SnipperAktivted
Global myKleinDisplay
Global myGrossDisplay
Global LeseBild_Breite
Global LeseBild_Hoehe
Global LeseBild_Tiefe
Global ImageGadget_Format.i
Global ImageGadget_Position_X.i
Global ImageGadget_Position_Y.i
Global LeseBild_Verhaeltinis.f
Global LeseBild_Verhaeltinis_Hoehe.i
Global ImageGadget_Position_Y.i
Global ImageGadget_LadeBildHoehe.i
Global ImageGadget_NeuePosition_Y.i
Global ImageGadget_Position_X.i
Global Fensterklick=false
Global ScreenCaptureAddress
Procedure Snipper_Display_Klein(ProcedureImage)
;Protected #ProcedureImage
;Format vom Sony 1366 x 768 x 16
;Fehler beim Ausschneiden = 1382 x 784
myKleinDisplay = CopyImage(ProcedureImage, #myKleinDisplay); Bild kopieren ?????? Wenn Bild kopiert funktioniert die Sache auch!
;Werte des Bild
LeseBild_Breite = ImageWidth(ProcedureImage) ;#imgCapture
;Debug LeseBild_Breite
LeseBild_Hoehe = ImageHeight(ProcedureImage)
;Debug LeseBild_Hoehe
LeseBild_Tiefe = ImageDepth(#imgCapture)
;Debug LeseBild_Tiefe
; format de Bildes
If LeseBild_Breite > LeseBild_Hoehe:
LeseBild_Format = 1; =>Horizontales Bild
ElseIf LeseBild_Breite < LeseBild_Hoehe:
LeseBild_Format = 2 ; => Vertikales Bild
Else :
LeseBild_Format = 0 :
EndIf ; => Quadratisches Bild :
;Debug "LeseBild_Format= "+Str(LeseBild_Format)
SetGadgetText(#XI_VirtStartP,Str(LeseBild_Breite))
SetGadgetText(#XI_VirtEndeP,Str(LeseBild_Hoehe))
; Position des Bildes
ImageGadget_Format = 230
ImageGadget_Position_X = 10
ImageGadget_Position_Y = 10
;==========================================================================================================
If LeseBild_Format = 1 ; Horizontales Bild
; Image Umrechnen
;myKleinDisplay = CatchImage(#myKleinDisplay, *ImageMemory, MemSize)
LeseBild_Verhaeltinis = LeseBild_Hoehe / LeseBild_Breite;Debug LeseBild_Verhaeltinis
LeseBild_Verhaeltinis_Hoehe = ImageGadget_Format* LeseBild_Verhaeltinis;Debug LeseBild_Verhaeltinis_Hoehe
ResizeImage (#myKleinDisplay, ImageGadget_Format, LeseBild_Verhaeltinis_Hoehe);Resize Bild
;>>> Image kopieren
;>>> Image in Memomry
SetGadgetState(#XI_Image,ImageID(#myKleinDisplay))
; Wieter gehts zum Gadget
ImageGadget_LadeBildHoehe = (ImageGadget_Format - LeseBild_Verhaeltinis_Hoehe)/2; ImageGadget positionieren
;Debug "ImageGadget_LadeBildHoehe = "+Str(ImageGadget_LadeBildHoehe)
ImageGadget_NeuePosition_Y = ImageGadget_Position_Y + ImageGadget_LadeBildHoehe
;Debug ImageGadget_NeuePosition_Y
ResizeGadget(#XI_Image, ImageGadget_Position_X, ImageGadget_NeuePosition_Y, ImageGadget_Format, LeseBild_Verhaeltinis_Hoehe)
;==========================================================================================================
ElseIf LeseBild_Format = 2 ; Vertikales Bild
LeseBild_Verhaeltinis = LeseBild_Breite / LeseBild_Hoehe
;Debug LeseBild_Verhaeltinis
LeseBild_Verhaeltinis_Breite = ImageGadget_Format* LeseBild_Verhaeltinis
;Debug LeseBild_Verhaeltinis_Breite
ResizeImage (#myKleinDisplay, LeseBild_Verhaeltinis_Breite, ImageGadget_Format)
SetGadgetState(#XI_Image,ImageID(#myKleinDisplay))
; ImageGadget positionieren
ImageGadget_LadeBildBreite = (ImageGadget_Format - LeseBild_Verhaeltinis_Breite)/2
ImageGadget_NeuePosition_X = ImageGadget_Position_X + ImageGadget_LadeBildBreite
ResizeGadget(#XI_Image,ImageGadget_NeuePosition_X , ImageGadget_Position_Y, LeseBild_Verhaeltinis_Breite, ImageGadget_Format)
;==========================================================================================================
ElseIf LeseBild_Format = 0 ;Quadratisches Bild
SetGadgetState(#XI_Image,myKleinDisplay)
ResizeGadget(#XI_Image, ImageGadget_Position_X, ImageGadget_Position_Y, ImageGadget_Format, ImageGadget_Format)
;==========================================================================================================
EndIf; End of Bildformat
EndProcedure
Procedure Snipper_Desktop()
GetWindowRect_(GetDesktopWindow_(), @r.rect)
Width= DesktopWidth(0);-735
Height = DesktopHeight(0);-520
Debug Width
Debug Height
CreateImage(#imgCapture, Width, Height)
DC = StartDrawing(ImageOutput(#imgCapture))
BitBlt_(DC, 0, 0, Width, Height, GetWindowDC_(GetDesktopWindow_()), 0, 0, #SRCCOPY)
StopDrawing()
ResizeImage(#imgCapture,1440,960) ;- Hier der Eintrag
SetClipboardImage(#imgCapture)
EndProcedure
Procedure.l CaptureScreen(Left.l, Top.l, Width.l, Height.l)
dm.DEVMODE
BMPHandle.l
srcDC = CreateDC_("DISPLAY", "", "", dm)
trgDC = CreateCompatibleDC_(srcDC)
BMPHandle = CreateCompatibleBitmap_(srcDC, Width, Height)
SelectObject_( trgDC, BMPHandle)
BitBlt_( trgDC, 0, 0, Width, Height, srcDC, Left, Top, #SRCCOPY)
DeleteDC_( trgDC)
ReleaseDC_( BMPHandle, srcDC)
ProcedureReturn BMPHandle
EndProcedure
Procedure CopyActiveWindow()
Protected Handle.i = GetForegroundWindow_()
Protected hDC.i = GetWindowDC_(Handle)
Protected pID.i, pDrawID.i, RECT.RECT
GetWindowRect_(Handle, @RECT.RECT)
With RECT
\right - \left
\bottom - \top
pID = CreateImage(#imgCapture, \right, \bottom)
pDrawID = StartDrawing(ImageOutput(#imgCapture))
If pDrawID
BitBlt_(pDrawID, 0, 0, \right, \bottom, hDC, 0, 0, #SRCCOPY)
StopDrawing()
SetClipboardImage(#imgCapture)
EndIf
EndWith
ReleaseDC_(Handle, hDC)
SetClipboardImage(#imgCapture)
EndProcedure
Procedure Snipper_Transparency(win,level)
If level>=0 And level<=100
SetWindowLong_(WindowID(win),#GWL_EXSTYLE,GetWindowLong_(WindowID(win),#GWL_EXSTYLE)|$00080000) ; #WS_EX_LAYERED = $00080000
SetLayeredWindowAttributes_(WindowID(win),0,255*level/100,2)
EndIf
EndProcedure
Procedure Snipper_WorkCallback2(WindowID, Message, wParam, lParam)
Protected MyCallBackResult2
Snipper_WorkCallbackResult2 = #PB_ProcessPureBasicEvents
Select Message
Case #WM_LBUTTONDOWN ; #WM_LBUTTONDOWN => Linker Mausbuttun gedrückt
ShowLine = #True
Debug "#WM_LBUTTONDOWN"
Case #WM_LBUTTONDBLCLK
EndSelect
ProcedureReturn Snipper_WorkCallbackResult2
EndProcedure
Procedure Snipper_WorkCallback(WindowID, Message, wParam, lParam)
Protected MyCallBackResult
Snipper_WorkCallbackResult = #PB_ProcessPureBasicEvents
Select Message
Case #WM_LBUTTONDOWN
ShowLine = #True
IX = DesktopMouseX() : IY = DesktopMouseY()
X1 = DesktopMouseX()
Y1 = DesktopMouseY()
Debug DesktopMouseX()
Debug DesktopMouseY()
Debug "#WM_LBUTTONDOWN"
Case #WM_LBUTTONUP
ShowLine = #False
; - Snipper Maus Up (Losgelassen)
; Mauswert in X/Y(2)
X2 = DesktopMouseX()
Y2 = DesktopMouseY()
SetGadgetText(#XI_StartP, "Start Maus-Klick-Position: X1= "+Str(X1)+", Y1= "+Str(Y1))
SetGadgetText(#XI_EndeP, "Stop Maus-Klick-Position: X1= "+Str(X2)+", Y1= "+Str(Y2))
; Festlegen des Ausschnitts
;Bildausschnitt RECHTS UNTEN
If X2>X1 And Y2>Y1
BX1=X1
BY1=Y1
BX2=X2
BY2=Y2
Delay(20)
EndIf
;Bildausschnitt RECHTS OBEN
If X2>X1 And Y2<Y1
BX1=X1
BY1=Y2
BX2=X2
BY2=Y1
Delay(20)
EndIf
;Bildausschnitt LINKS UNTEN
If X2<X1 And Y2>Y1
BX1=X2
BY1=Y1
BX2=X1
BY2=Y2
Delay(20)
EndIf
;Bildausschnitt LINKS OBEN
If X2<X1 And Y2<Y1
BX1=X2
BY1=Y2
BX2=X1
BY2=Y1
Delay(20)
EndIf
SetGadgetText(#XI_VirtStartP, "VirtualStart Maus-Klick-Position: X1= "+Str(BX1)+", Y1= "+Str(BY1))
SetGadgetText(#XI_VirtEndeP, "VirtualStop Maus-Klick-Position: X2= "+Str(BX2)+", Y2= "+Str(BY2))
; Berechnen des Bildauschnittes
Speicherbild_Breite = BX2-BX1
Speicherbild_Hoehe = BY2-BY1
SetGadgetText(#XI_VirtStartP2, "Bildausschnitt STARTPunkt BX1="+Str(BX1)+", BY1= "+Str(BY1))
SetGadgetText(#XI_SchnittP, "Desktop Bildausschnitt Width="+Str(Speicherbild_Breite)+", Height= "+Str(Speicherbild_Hoehe))
GrabImage(#imgCapture,#myImage2, BX1, BY1, Speicherbild_Breite, Speicherbild_Hoehe)
SetClipboardImage(#myImage2)
Snipper_Display_Klein(#myImage2)
CloseWindow(#ChildWindow); SnipperWindows schliessen
CloseWindow(#ParentWindow); SnipperWindows schliessen
SetWindowState(#FrameMain, #PB_Window_Normal)
HideWindow(#FrameMain, #False ); Windows wieder einschalten
SetActiveWindow(#FrameMain) ; Windows wieder als Aktiv
StickyWindow(#FrameMain,0) ; Windows ganz nach vorne
SetWindowCallback(@Snipper_WorkCallback2()); Zweiten Callback bereitstellen
Debug "#WM_LBUTTONUP"
Case #WM_MOUSEMOVE
If ShowLine
Debug "#WM_MOUSEMOVE"
If EventwParam() = #MK_LBUTTON
; - Snipper Maus Move (in Bewegung)
;MX=0:MY=0
MX = DesktopMouseX() : MY = DesktopMouseY()
Bildauschnitt=A
hdc = GetDC_(WindowID(#ChildWindow))
DrawFocusRect_(hdc,frc.RECT)
If ((IX < MX) And (IY > MY))
SetRect_(frc,IX,MY, MX,IY)
ElseIf ((IX > MX) And (IY > MY))
SetRect_(frc,MX, MY, IX,IY)
ElseIf ((IX > MX) And (IY < MY))
SetRect_(frc,MX,IY, IX, MY)
Else
SetRect_(frc,IX,IY,MX,MY)
EndIf
DrawFocusRect_(hdc,frc)
;ClearRect_(frc,IX,IY,MX,MY)
ReleaseDC_(WindowID(#ChildWindow),hdc)
EndIf
EndIf
EndSelect
ProcedureReturn Snipper_WorkCallbackResult
EndProcedure
Procedure Snipper_Window()
ExamineDesktops(); Ermittelt Informationen Desktops für folgende Befehle Desktopheight()
OpenWindow(#ParentWindow,0,0,DesktopWidth(0),DesktopHeight(0),"Snipping Test",#PB_Window_Invisible)
;Unser Fenster mit dem wir auf den Desktop malen wollen
OpenWindow(#ChildWindow,0,0,DesktopWidth(0),DesktopHeight(0),"Snipping Test",#PB_Window_BorderLess|#PB_Window_Invisible,GetDesktopWindow_())
;Window auf Layered Child Window umschalten
SetWindowLong_(WindowID(#ChildWindow),#GWL_HWNDPARENT,WindowID(#ParentWindow))
;Snap Windows vom Desktop
Snipper_Desktop(); Bild vom Desktop
;Window auf Transparent Layered Window umschalten
Snipper_Transparency(#ChildWindow,40)
;Fenster fixieren
;SetWindowPos_(WindowID(#ChildWindow),#HWND_BOTTOM,0,0,0,0,#SWP_NOMOVE|#SWP_NOREPOSITION|#SWP_NOSIZE)
;Window anzeigen
HideWindow(#ChildWindow,#False)
; Windows in den Vordergrund
StickyWindow(#ChildWindow,0)
;SetActiveWindow(#ParentWindow)
; Fokus auf das Windows setzen
SetActiveWindow(#ChildWindow)
; ESC Taste freischalten ?
;AddKeyboardShortcut(#ChildWindow, #PB_Shortcut_Escape, #TastenDruckEscape) ; Escape einschalten
; Snipper Callback einschalten
SetWindowCallback(@Snipper_WorkCallback(),#ChildWindow);Snipper_WorkCallback einschalten
SetRect_(frc,0,0,0,0)
EndProcedure
MeinWindows=OpenWindow(#FrameMain,683, 0,667, 350,"Velindos Snipping Test",#PB_Window_SystemMenu|#PB_Window_SizeGadget); |#PB_Window_BorderLess
TextGadget(#XI_SnipperEinAus,150,250,150,25,Str(SnipperEinAus))
ButtonGadget(#BildAusschneiden,150,270,150,25,"Bild ausschneiden")
ButtonGadget(#BildVomDesktop,320,270,150,25,"Bild vom Desktop")
ButtonGadget(#FensterKlick,490,270,150,25,"Bild vom Fenster")
TextGadget(#XI_StartP, 250, 6, 290, 20, "Start")
TextGadget(#XI_EndeP, 250, 26, 290, 20, "Ende")
TextGadget(#XI_VirtStartP, 250, 66, 290, 20, "VirtualStart")
TextGadget(#XI_VirtEndeP, 250, 86, 290, 20, "VirtualEnde")
TextGadget(#XI_VirtStartP2, 250, 126, 290, 20, "VirtualStart")
TextGadget(#XI_SchnittP, 250, 146, 290, 20, "Bildausschnitt")
AddKeyboardShortcut(#FrameMain, #PB_Shortcut_Escape, #TastenDruckEscape) ; Escape einschalten
SetWindowCallback(@Snipper_WorkCallback2(),#FrameMain)
SetActiveWindow(#FrameMain)
CreateImage(#Testbild,230,230)
ImageGadget(#XI_Image,10,10,230,230,ImageID(#Testbild));,#PB_Image_Raised|#PB_Image_Border<============================================ BILD
DesktopMouseX()
;-REPEAT
Repeat
EventID=WaitWindowEvent()
Select EventID
Case #PB_Event_CloseWindow:End
Case #PB_Event_Gadget
Select EventGadget()
Case #BildAusschneiden
SetGadgetText(#XI_SnipperEinAus,"1")
HideWindow(#FrameMain, #True ); Window ausblenden
SetWindowState(#FrameMain, #PB_Window_Minimize)
Snipper_Window(); Aufruf des Snipper Fenster
Case #BildVomDesktop
Snipper_Desktop()
Snipper_Display_Klein(#imgCapture)
Case #FensterKlick
;Hier beginnt die Abfrage für den Fensterklick
;If Fensterklick = #True
Debug "Fensterklick ausgelöst"
SetWindowState(#FrameMain, #PB_Window_Minimize)
Delay(3000)
CopyActiveWindow()
Snipper_Display_Klein(#imgCapture)
SetWindowState(#FrameMain, #PB_Window_Normal )
StickyWindow(#FrameMain,0); Windows ganz nach vorne
EndSelect
Case #PB_Event_Menu
Select EventMenu() ;PopUp und Einträge für Kategorie und ESC
Case #TastenDruckEscape:End ;Escape Taste gedrückt, soll Snipper Quittieren
EndSelect
EndSelect
Until event = #PB_Event_CloseWindow
Gruss ... Velindos