; Программа для сниятия скриншотов.
; Нужен компилятор PureBasic 4.00 или выше. Требуются библиотеки Droopy Library и XP_Menu_Lib
Enumeration 0
#Window_0
EndEnumeration
;- Gadget Constants
;
Enumeration
#Text_0
#Path
#Button_Path
#Frame3D_0
#Radio_BMP
#Radio_JPEG
#Radio_PNG
#Text_1
#Spin_0
#CheckBox_0
#Text_2
#Text_3
#Text_4
#Text_5
EndEnumeration
;- Fonts
Global FontID1
FontID1 = LoadFont(1, "MS Sans Serif", 8, #PB_Font_Bold)
UseJPEGImageEncoder()
UsePNGImageEncoder()
#ProgName="Skrinhot v1.0"
Procedure IconWidth(Icon)
BmpInf.BITMAP:GetIconInfo_(Icon,Info.ICONINFO)
GetObject_(Info\hbmColor,SizeOf(BmpInf),BmpInf)
ProcedureReturn BmpInf\bmWidth
EndProcedure
Procedure IconHeight(Icon)
BmpInf.BITMAP:GetIconInfo_(Icon,Info.ICONINFO)
GetObject_(Info\hbmColor,SizeOf(BmpInf),BmpInf)
ProcedureReturn BmpInf\bmHeight
EndProcedure
Procedure ConvertIcon2Image(ImageNr,Icon,IconWidth,IconHeight)
CreateImage(ImageNr, IconWidth, IconHeight)
StartDrawing(ImageOutput(ImageNr))
DrawImage(Icon,0,0)
StopDrawing()
EndProcedure
Procedure SkrinActiveWindow(FileName.s,ImagePlugin,Pak)
Handle=ForegroundWindowGet()
If Handle
WindowSize.RECT
GetWindowRect_(Handle, @WindowSize)
IconWidth=WindowSize\Right - WindowSize\Left
IconHeight=WindowSize\Bottom - WindowSize\Top
*Image= CaptureScreenPart(WindowSize\Left, WindowSize\Top, IconWidth,IconHeight)
EndIf
If *Image=0
ProcedureReturn
EndIf
ConvertIcon2Image(1,*Image,IconWidth,IconHeight)
If IsImage(1)>0
SaveImage(1,FileName,ImagePlugin,Pak)
EndIf
;FreeMemory(*Image)
EndProcedure
Procedure Open_Window_0()
If OpenWindow(#Window_0, 275, 242, 383, 276, "Настройки "+#ProgName, #PB_Window_SystemMenu | #PB_Window_Invisible | #PB_Window_TitleBar | #PB_Window_ScreenCentered )
If CreateGadgetList(WindowID(#Window_0))
TextGadget(#Text_0, 15, 15, 105, 15, "Папка для снимков")
StringGadget(#Path, 15, 30, 325, 20, "")
ButtonGadget(#Button_Path, 345, 30, 25, 20, "...")
Frame3DGadget(#Frame3D_0, 15, 70, 325, 85, "Сохранять как")
OptionGadget(#Radio_BMP, 30, 90, 110, 15, "BMP (без сжатия)")
OptionGadget(#Radio_JPEG, 30, 110, 105, 15, "JPEG")
OptionGadget(#Radio_PNG, 30, 130, 110, 15, "PNG")
TextGadget(#Text_1, 170, 110, 90, 15, "Степень сжатия")
SpinGadget(#Spin_0, 265, 105, 40, 20, 1, 100)
CheckBoxGadget(#CheckBox_0, 25, 250, 215, 15, "Добавить программу в автозагрузку")
TextGadget(#Text_2, 10, 170, 240, 15, "Горячая клавиша для снимка всего экрана —")
TextGadget(#Text_3, 265, 170, 100, 15, "PrintScreen")
SetGadgetFont(#Text_3, FontID1)
TextGadget(#Text_4, 10, 195, 245, 15, "Горячая клавиша для снимка активного окна —")
TextGadget(#Text_5, 265, 195, 115, 15, "Ctrl + PrintScreen")
SetGadgetFont(#Text_5, FontID1)
EndIf
EndIf
EndProcedure
Procedure CreateSkrinAll()
If GetGadgetState(#Radio_BMP)=1
Part.s=".BMP" : ImagePlugin=#PB_ImagePlugin_BMP
ElseIf GetGadgetState(#Radio_JPEG)=1
Part.s=".JPEG" : ImagePlugin=#PB_ImagePlugin_JPEG
ElseIf GetGadgetState(#Radio_PNG)=1
Part.s=".PNG" : ImagePlugin=#PB_ImagePlugin_PNG
EndIf
File.s=GetGadgetText(#Path)+FormatDate("%hh_%ii_%ss", Date())+Part
CaptureFullScreen()
SaveCapture(File,ImagePlugin,GetGadgetState(#Spin_0)/10)
EndProcedure
Procedure CreateSkrinWindow()
If GetGadgetState(#Radio_BMP)=1
Part.s=".BMP" : ImagePlugin=#PB_ImagePlugin_BMP
ElseIf GetGadgetState(#Radio_JPEG)=1
Part.s=".JPEG" : ImagePlugin=#PB_ImagePlugin_JPEG
ElseIf GetGadgetState(#Radio_PNG)=1
Part.s=".PNG" : ImagePlugin=#PB_ImagePlugin_PNG
EndIf
File.s=GetGadgetText(#Path)+FormatDate("%hh_%ii_%ss", Date())+Part
SkrinActiveWindow(File,ImagePlugin,GetGadgetState(#Spin_0)/10)
EndProcedure
Procedure GlavWindowCallback(WindowID, Message, wParam, lParam)
XP_Menu_CB(WindowID, Message, wParam, lParam)
ProcedureReturn #PB_ProcessPureBasicEvents
EndProcedure
Procedure SetStyleMenu(Style, IconState)
If Style>0 And Style<8
XP_MenuRegister(MenuID(0), #XP_RegMenu, #XP_RegPopupMenu)
XP_SetMenuStyle(Style-1)
SetMenuItemState(0,18,IconState)
DisableMenuItem(0,18,0)
If IconState=1
XP_SetMenuIcon(MenuID(0),1,ImageID(3))
XP_SetMenuIcon(MenuID(0),2,ImageID(4))
XP_SetMenuIcon(MenuID(0),3,ImageID(5))
XP_SetMenuIcon(MenuID(0),4,ImageID(2))
Else
XP_SetMenuIcon(MenuID(0),1,0)
XP_SetMenuIcon(MenuID(0),2,0)
XP_SetMenuIcon(MenuID(0),3,0)
XP_SetMenuIcon(MenuID(0),4,0)
EndIf
For i=6 To 12
If i=Style+5
SetMenuItemState(0,i,1)
Else
SetMenuItemState(0,i,0)
EndIf
Next i
Else
SetMenuItemState(0,5,1)
For i=6 To 12
SetMenuItemState(0,i,0)
Next i
XP_MenuRegister(MenuID(0), #XP_DelMenu, #XP_RegPopupMenu)
SetMenuItemState(0,18,0)
DisableMenuItem(0,18,1)
EndIf
DrawMenuBar_(WindowID(0))
EndProcedure
Open_Window_0()
SetWindowCallback(@GlavWindowCallback())
DirTemp.s=GetTemporaryDirectory()
PathPref.s=DirTemp+"Skrinhot v1.0.ini"
Gosub OpenPreferences
Gosub WinS
CatchImage(2,?IconClose, ?IconCloseEnd-?IconClose)
CatchImage(3,?IconOpenDir, ?IconOpenDirEnd-?IconOpenDir)
CatchImage(4,?IconPreference, ?IconPreferenceEnd-?IconPreference)
CatchImage(5,?Iconhelp, ?IconhelpEnd-?Iconhelp)
If CreatePopupMenu(0)
MenuItem(1,"Папка снимков")
MenuBar()
OpenSubMenu("Стиль меню")
MenuItem(5,"Стандартный")
MenuItem(6,"Офис 2000")
MenuItem(7,"Офис XP")
MenuItem(8,"Офис 2003")
MenuItem(9,"Фиолетовый")
MenuItem(10,"Чёрный")
MenuItem(11,"Серый")
MenuItem(12,"Зелёный")
MenuBar()
MenuItem(18,"Значки")
CloseSubMenu()
MenuItem(2,"Настройки")
MenuItem(3,"О программе")
MenuBar()
MenuItem(4,"Выход")
EndIf
SetStyleMenu(StyleMenu, IconState)
If AddSysTrayIcon(1,WindowID(#Window_0),CatchImage(1,?Icon,?IconEnd-?Icon))=0
MessageRequester("Skrinhot v1.0", "Не удалось создать иконку в трее", #MB_OK|#MB_ICONERROR)
End
EndIf
Exit=0
HotKeysInit()
HotKeyAdd(WindowID(#Window_0), 44, @CreateSkrinAll(), "SkrinAll", 0,0,0)
HotKeyAdd(WindowID(#Window_0), 44, @CreateSkrinWindow(), "SkrinWin", 0,0,1)
Repeat
Event=HotkeyWaitWindowEvent()
Gadget=EventGadget()
Menu=EventMenu()
Type=EventType()
If Event=#PB_Event_SysTray
If Type=#PB_EventType_RightClick
DisplayPopupMenu(0, WindowID(#Window_0)) ; показ вспывающего меню
EndIf
If Type=#PB_EventType_LeftDoubleClick
If IsWindow(#Window_0)=0
Open_Window_0()
Gosub WinS
HideWindow(#Window_0,0)
Else
SetActiveWindow(#Window_0)
HideWindow(#Window_0,0)
EndIf
EndIf
EndIf
If Event=#PB_Event_Menu
Select Menu
Case 1
PathDir.s=GetGadgetText(#Path)
If PathDir<>""
If FileSize(PathDir)= -2
RunProgram(PathDir)
EndIf
EndIf
Case 2
If IsWindow(#Window_0)=0
Open_Window_0()
Gosub WinS
HideWindow(#Window_0,0)
Else
SetActiveWindow(#Window_0)
HideWindow(#Window_0,0)
EndIf
Case 3
MessageRequester("О программе", #ProgName+" — программа для снятия скриншотов с экрана компьютера"+Chr(10)+"Она была разработана в системе PureBasic — http://pbasic.spb.ru/"+Chr(10)+Chr(10)+"Автор: Пётр"+Chr(10)+"E-Mail: purik4.0@rambler.ru", #MB_OK|#MB_ICONINFORMATION)
Case 4
Exit=1
Case 5 To 12
For i=5 To 12
If i=Menu
SetMenuItemState(0,i,1)
Else
SetMenuItemState(0,i,0)
EndIf
Next i
StyleMenu=Menu-5
SetStyleMenu(StyleMenu, IconState)
If OpenPreferences(PathPref)
WritePreferenceLong("StyleMenu",StyleMenu)
WritePreferenceLong("IconState",IconState)
ClosePreferences()
EndIf
Case 18
IconState=GetMenuItemState(0,18)!1
SetMenuItemState(0,18,IconState)
SetStyleMenu(StyleMenu, IconState)
If OpenPreferences(PathPref)
WritePreferenceLong("StyleMenu",StyleMenu)
WritePreferenceLong("IconState",IconState)
ClosePreferences()
EndIf
EndSelect
EndIf
If Event=#PB_Event_Gadget
Select Gadget
Case #Button_Path
TempPath.s=PathRequester("Выберите папку, где будут сохранятся снимки.",PathSkrin.s)
If TempPath<>""
SetGadgetText(#Path,TempPath) : PathSkrin=TempPath
EndIf
Case #Spin_0
SetGadgetText(#Spin_0,Str(GetGadgetState(#Spin_0)))
Case #Radio_BMP
DisableGadget(#Text_1,1) : DisableGadget(#Spin_0,1)
Case #Radio_JPEG
DisableGadget(#Text_1,0) : DisableGadget(#Spin_0,0)
Case #Radio_PNG
DisableGadget(#Text_1,1) : DisableGadget(#Spin_0,1)
EndSelect
EndIf
If Event=#PB_Event_CloseWindow
PathSkrin.s=GetGadgetText(#Path)
If GetGadgetState(#Radio_BMP)=1
SkrinType=0
ElseIf GetGadgetState(#Radio_JPEG)=1
SkrinType=1
ElseIf GetGadgetState(#Radio_PNG)=1
SkrinType=2
EndIf
JPGPAK=GetGadgetState(#Spin_0)
AutoRunState=GetGadgetState(#CheckBox_0)
If AutoRunState=1
If IsProgramRunAtStartup(0,1,"Skrinhot")=""
RunProgramAtStartup(0,1,"Skrinhot",HandleToFileName(WindowID(#Window_0)))
EndIf
ElseIf AutoRunState=0
If IsProgramRunAtStartup(0,1,"Skrinhot")<>""
DelProgramAtStartup(0,1,"Skrinhot")
EndIf
EndIf
Gosub SavePreferences
HideWindow(#Window_0,1)
EndIf
Until Exit=1
TimerKill(1,WindowID(#Window_0))
End
OpenPreferences:
PathPrefState=OpenPreferences(PathPref)
PathSkrin.s=ReadPreferenceString("PathSkrin",GetPathPart(GetProgramName()))
SkrinType=ReadPreferenceLong("SkrinType",0)
JPGPAK=ReadPreferenceLong("JPGPAK",85)
AutoRunState=ReadPreferenceLong("AutoRunState",0)
StyleMenu=ReadPreferenceLong("StyleMenu",3)
IconState=ReadPreferenceLong("IconState",1)
If PathPrefState=0
CreatePreferences(PathPref)
EndIf
ClosePreferences()
Return
SavePreferences:
If OpenPreferences(PathPref)
WritePreferenceString("PathSkrin",PathSkrin.s)
WritePreferenceLong("SkrinType",SkrinType)
WritePreferenceLong("JPGPAK",JPGPAK)
WritePreferenceLong("AutoRunState",AutoRunState)
WritePreferenceLong("StyleMenu",StyleMenu)
WritePreferenceLong("IconState",IconState)
ClosePreferences()
EndIf
Return
WinS:
SetGadgetText(#Path,PathSkrin)
Select SkrinType
Case 0
SetGadgetState(#Radio_BMP,1) : DisableGadget(#Text_1,1) : DisableGadget(#Spin_0,1)
Case 1
SetGadgetState(#Radio_JPEG,1) : DisableGadget(#Text_1,0) : DisableGadget(#Spin_0,0)
Case 2
SetGadgetState(#Radio_PNG,1) : DisableGadget(#Text_1,1) : DisableGadget(#Spin_0,1)
EndSelect
SetGadgetState(#Spin_0,JPGPAK)
SetGadgetText(#Spin_0,Str(JPGPAK))
SetGadgetState(#CheckBox_0,AutoRunState)
Return
DataSection
Icon:
IncludeBinary "Значки\Значок.ico"
IconEnd:
IconClose:
IncludeBinary "Значки\Close.ico"
IconCloseEnd:
IconOpenDir:
IncludeBinary "Значки\OpenDir.ico"
IconOpenDirEnd:
IconPreference:
IncludeBinary "Значки\Preference.ico"
IconPreferenceEnd:
Iconhelp:
IncludeBinary "Значки\help.ico"
IconhelpEnd:
EndDataSection