after resizing the window-click on the button "Capture"
the prg request the desired format (png,bmp,jpg)
prg or save the application, and what name (the path is kept)
prg saw the animated displays a catch:)
press spacebar or rightmouseclick for quit
; By Dobro
; Capture avec fenetre transparente redimensionable qui sert de cadre;
; purecolor_lib
usepngimageencoder ()
usejpegimageencoder ()
usejpegimagedecoder ()
usepngimagedecoder ()
Declare CaptureScreen(left.l, top.l, Width.l, Height.l)
Declare ShowWin()
Declare OpenWindow_Window_sauve()
Declare save_image()
Declare reload(FileName.s)
Declare info_sous_souris()
Enumeration
#WIN
#bouton
#bouton_All
#Image
#bmp
#jpg
#png
#info
#Sprite
#coche
EndEnumeration
;{- Enumerations / DataSections
;{ Windows
Enumeration
#Window_sauve
#window
EndEnumeration
;}
;{ Gadgets
Enumeration
#Container_0
#Option_Jpg
#Option_BMP
#Option_Png
EndEnumeration
;}
;}
Global x_win,y_win,flag=0
Structure sprite
x.l
y.l
pas_x.l
pas_y.l
EndStructure
Global Dim sprite.sprite(1)
sprite(1)\pas_x=2
sprite(1)\pas_y=-2
examinedesktops ()
Global ecran_x= desktopwidth (0)
Global ecran_y= desktopheight (0)
If initsprite () = 0 Or initkeyboard () = 0 Or initmouse () = 0
messagerequester ( "Erreur" , "Impossible d'initialiser DirectX" , 0)
EndIf
Global FileName.s
Repeat
ShowCursor_ (1) ; montre le curseur
ShowWin()
Until flag=1
End
Procedure ShowWin()
;-------------------
If openwindow ( #WIN , 0, 0, 300, 300, "Pure_Capture By Dobro" , #PB_Window_BorderLess |#PB_Window_SizeGadget |#PB_Window_Tool|#PB_Window_SystemMenu )
stickywindow ( #WIN , 1) ; mise au premier plan
buttongadget ( #bouton ,10,10,40,30, "capture" )
PureCOLOR_SetButtonColor( #bouton , rgb ($F3,$E3,$21), rgb ($88,$0,$6C), rgb ($FD,$21,$9) , rgb ($0,$0,$0))
buttongadget ( #bouton_All ,250,10,40,30, "ALL" )
PureCOLOR_SetButtonColor( #bouton_All , rgb ($72,$10,$68 ), rgb ($FF,$FF,$80), rgb ($FD,$21,$9) , rgb ($0,$0,$0))
checkboxgadget ( #coche ,10,50,40,30, "Auto" ) : setgadgetstate ( #coche , #PB_CheckBox_Unchecked )
setwindowcolor ( #WIN , #Blue )
SetWindowLong_ ( windowid ( #WIN ), #GWL_EXSTYLE , #WS_EX_LAYERED | #WS_EX_TOPMOST )
SetLayeredWindowAttributes_ ( windowid ( #WIN ), #Blue ,0, #LWA_COLORKEY )
EndIf
Repeat
Event= waitwindowevent (2)
Select Event
Case #PB_Event_Gadget
Select eventgadget ()
Case #bouton_All
Beep_ (440,100)
CaptureScreen( 0, 0, ecran_x, ecran_y)
save_image()
ProcedureReturn
Case #bouton
Beep_ (440,100)
CaptureScreen( windowx ( #WIN )+4, windowy ( #WIN )+24, windowwidth ( #WIN ), windowheight ( #WIN ))
save_image()
reload(FileName.s)
ProcedureReturn
EndSelect
EndSelect
If getgadgetstate ( #coche )= #PB_CheckBox_Checked
hidegadget ( #bouton ,1)
hidegadget ( #bouton_All ,1)
hidegadget ( #coche ,1)
setwindowtitle ( #WIN , "Press Return" )
info_sous_souris()
If GetAsyncKeyState_ ( #VK_RETURN )
CaptureScreen( windowx ( #WIN )+4, windowy ( #WIN )+24, windowwidth ( #WIN ), windowheight ( #WIN ))
save_image()
reload(FileName.s)
ProcedureReturn
EndIf
EndIf
Until Event = #PB_Event_CloseWindow
flag=1
EndProcedure
;
Procedure CaptureScreen(left.l, top.l, Width.l, Height.l)
#CAPTUREBLT = $40000000
x_win= windowx ( #WIN )
y_win= windowy ( #WIN )
closewindow ( #WIN )
dm.DEVMODE ;structure for CreateDC()
srcDC.l
trgDC.l
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|#CAPTUREBLT )
; OpenClipboard_ ( #Null )
; ******** clipboard incompatible avec Jpg **********
;EmptyClipboard_ ()
;SetClipboardData_ (2, BMPHandle)
; CloseClipboard_ ()
; ************************************************²
If createimage ( #Image ,Width,Height)
If startdrawing ( imageoutput ( #Image ))
drawimage (BMPHandle,0,0)
EndIf
stopdrawing ()
EndIf
DeleteDC_ ( trgDC)
ReleaseDC_ ( BMPHandle, srcDC)
ProcedureReturn
EndProcedure
Procedure save_image()
If openwindow ( #Window_sauve , x_win, y_win, 133, 108, "Save image" , #PB_Window_BorderLess )
stickywindow ( #Window_sauve , 1) ; mise au premier plan
containergadget ( #Container_0 , 5, 5, 125, 95, #PB_Container_Raised )
optiongadget ( #Option_Jpg , 5, 5, 85, 25, "Jpg" )
optiongadget ( #Option_BMP , 5, 25, 85, 25, "Bmp" )
optiongadget ( #Option_Png , 5, 45, 85, 25, "Png" )
closegadgetlist ()
;{- Event loop
Repeat
Select waitwindowevent ()
; ///////////////////
Case #PB_Event_Gadget
Select eventgadget ()
Case #Container_0
Case #Option_Jpg
type = #jpg
iEvent = #PB_Event_CloseWindow
Case #Option_BMP
type= #bmp
iEvent = #PB_Event_CloseWindow
Case #Option_Png
type= #png
iEvent = #PB_Event_CloseWindow
EndSelect
EndSelect
Until iEvent = #PB_Event_CloseWindow
closewindow ( #Window_sauve )
EndIf
;}
If openfile ( #info , "capture.inf" )
path$= readstring ( #info )
closefile ( #info )
EndIf
If path$= ""
path$= "c:\"
EndIf
If getextensionpart (FileName.s) <> ""
FileName.s= mid (FileName.s,1, len (FileName.s)-4)
EndIf
Select type
Case #jpg
FileName.s= savefilerequester ( "sauve jpg" ,path$, "*.jpg" ,1)+ ".jpg"
If saveimage ( #Image , FileName.s, #PB_ImagePlugin_JPEG ,10,32 ) =0
messagerequester ( "erreur" , "pas pu enregistrer l'image" )
ProcedureReturn
EndIf
Case #bmp
FileName.s= savefilerequester ( "sauve bmp" ,path$, "*.bmp" ,1)+ ".bmp" ; bug !!
If saveimage ( #Image , FileName.s, #PB_ImagePlugin_BMP ,10,32)=0 ; bug !!!
messagerequester ( "erreur" , "pas pu enregistrer l'image" )
ProcedureReturn
EndIf
Case #png
FileName.s= savefilerequester ( "sauve png" ,path$, "*.png" ,1)+ ".png"
If saveimage ( #Image , FileName.s, #PB_ImagePlugin_PNG )=0
messagerequester ( "erreur" , "pas pu enregistrer l'image" )
ProcedureReturn
EndIf
EndSelect
If openfile ( #info , "capture.inf" )<>0
writestringn ( #info , getpathpart (FileName.s) )
closefile ( #info )
EndIf
delay (200)
EndProcedure ;
Procedure reload(FileName.s)
;- Ouverture de la fenêtre et de l'écran
hwnd = openwindow ( #window , 0, 0, ecran_x, ecran_y, "View_Capture Press Space_bar" , #PB_Window_Tool| #PB_Window_BorderLess )
stickywindow ( #window , 1) ; mise au premier plan
openwindowedscreen ( windowid ( #window ), 0, 0, ecran_x, ecran_y, 0, 0, 0)
loadsprite ( #Sprite ,FileName.s)
;- début de la boucle
resizewindow ( #window , 10, 10, spritewidth ( #Sprite )+50, spriteheight ( #Sprite )+50)
Repeat
examinemouse () ; on demande a purebasic de surveiller les event de souris !
examinekeyboard () ; on demande a purebasic de surveiller les event de clavier!
evnt= windowevent ()
delay (2)
Select evnt
Case #PB_Event_CloseWindow
End
EndSelect
sprite(1)\x=sprite(1)\x+sprite(1)\pas_x
sprite(1)\y=sprite(1)\y+sprite(1)\pas_y
If sprite(1)\x+ spritewidth ( #Sprite )>WindowWidth( #window )
sprite(1)\pas_x=-sprite(1)\pas_x
EndIf
If sprite(1)\y+ spriteheight ( #Sprite )>WindowHeight( #window )
sprite(1)\pas_y=-sprite(1)\pas_y
EndIf
If sprite(1)\x<0
sprite(1)\pas_x=-sprite(1)\pas_x
EndIf
If sprite(1)\y<0
sprite(1)\pas_y=-sprite(1)\pas_y
EndIf
displaysprite ( #Sprite ,sprite(1)\x,sprite(1)\y)
flipbuffers () : clearscreen ( rgb (0,0,0))
Until keyboardpushed ( #PB_Key_Space ) Or mousebutton ( #PB_MouseButton_Right )
closewindow ( #window )
EndProcedure
Procedure info_sous_souris()
WinMouse = WindowFromPoint_ ( desktopmousex () | desktopmousey () << 32)
GetClientRect_ (WinMouse, Fenetre.rect) :
ClientToScreen_ (WinMouse, FenetreHG.POINT)
resizewindow ( #WIN ,FenetreHG\x-4,FenetreHG\y-24,Fenetre\ right ,Fenetre\bottom )
EndProcedure