#Include "UcScrin.bi"
#Include "UcScrinHotkey.bas"
#Include "UcScrinSelect.bas"
#Include "UcScrinOption.bas"
#Include "UcScrinMenuTray.bas"
#Include "UcScrinSnap.bas"
#Include "UcScrinResize.bas"

' Запуск

a.Event


'Функция, отвечающая за изменение курсора

Function Obj.windowproc(hwnd As HWND,msg As UINT,wParam As WPARAM,lParam As LPARAM) As Integer
	If msg= WM_MOUSEMOVE Then
		If IsMouseOver(GadgetID(TopSize)) Or IsMouseOver(GadgetID(BottomSize)) Then
			SetCursor(LoadCursor(0,IDC_SIZENS))
		ElseIf IsMouseOver(GadgetID(LeftSize)) Or IsMouseOver(GadgetID(RightSize)) Then
			SetCursor(LoadCursor(0,IDC_SIZEWE))
		ElseIf IsMouseOver(GadgetID(BottomLeftSize)) Then
			SetCursor(LoadCursor(0,IDC_SIZENESW))
		ElseIf IsMouseOver(GadgetID(BottomRightSize)) Then
			SetCursor(LoadCursor(0,IDC_SIZENWSE))
		Else
			Return 0
		EndIf
	EndIf
End Function


'---------------------------Обработчик сообщений------------------------------

Sub Obj.Event
	SaveLoadOption(0)
	SelectScreenshootWindow
	OptionWindow
	Hotkey
	LoadSaveHotkey(0)
	CreateResizeSnapWindow
	menu
	SetTimer(SelectHwnd,1,1,Cast(timerproc,@Size()))
	HideWindow(SelectHwnd,1)
	SaveLoad.Hide=1
	Do
		ev=WaitEvent
		Select Case ev
			Case EventRBDown
				If EventNumber = SysTray Then
					DisplayPopupMenu(H_MENU,GlobalMouseX,GlobalMouseY)
				ElseIf EventNumberListView = ListViewHotkey Then
					DisplayPopupMenu(H_MENU_3,GlobalMouseX,GlobalMouseY)
				EndIf
			Case EventMenu
				Select Case EventNumber
					Case MenuOptionWindow
						HideWindow(a.OptionhWnd,0)
					Case MemuColorFrameGreen To MemuColorFrameWhite
						Color(DimColor(EventNumber))
					Case MemuColorTextGreen To MemuColorTextWhite
						Color(,DimColor(EventNumber-5))
					Case MenuHotKey
						Hot_Key.Hide=0
						ThreadCreate(@EventHotkey())
						HideWindow(HotKeyHWND,0)
					Case menuDeleteItem
						DeleteHotKey()
					Case MenuAbout
						RunProgram("http://mneniya.ucoz.ru/")
					Case MenuExit
						Deletesystrayicon(SysTray)
						UnRegHotKey()
						Exit Do
				End Select
			Case EventGadget
				Select Case EventNumber
					Case ButtonCancel
						HideWindow(OptionhWnd,1)
					Case ButtonOK
						SaveLoadOption(1)
						HideWindow(OptionhWnd,1)
					Case ButtonHotkeyOK
						NewHotKey
					Case ButtonHotKeyPath
						dir_=ShellFolder( "Выбрать папку или файл для запуска", "C:\",BIF_BROWSEINCLUDEFILES Or BIF_USENEWUI)
						If dir_<>"" Then
							SetGadgetText(StringHotkeyPATH,dir_)
						EndIf
					Case ButtonChangePATH
						SaveLoad.temppath=ShellFolder("",ExePath())
						If SaveLoad.temppath<>"" Then
							SetGadgetText(StringGadgetPATH,SaveLoad.temppath)
						EndIf
					Case TextHotkeyExit
						HideWindow(HotKeyHWND,1)
						Hot_Key.Hide=1
					Case Exit_W
						HideWindow(SelectHwnd,1)
						SaveLoad.Hide=1
					Case ButtonHotkeyS '<- открываем или закрываем список
						Hot_Key.flag = Hot_Key.flag xor 1
						ResizeWindow(HotKeyHWND,,,,115+(Hot_Key.flag*205))
					Case ButtonHotKeyClear
						Clear()
					Case SizeValue
						ReleaseCapture()
						SendMessage(SelectHwnd, WM_NCLBUTTONDOWN, HTCAPTION, NULL)
					Case TopSize
						SetCursor(LoadCursor(0,IDC_SIZENS))
						SendMessage(SelectHwnd, WM_NCLBUTTONDOWN, HTTOP	 , NULL)
					Case LeftSize
						SetCursor(LoadCursor(0,IDC_SIZEWE))
						SendMessage(SelectHwnd, WM_NCLBUTTONDOWN,HTLEFT, NULL)
					Case BottomSize
						SetCursor(LoadCursor(0,IDC_SIZENS))
						SendMessage(SelectHwnd, WM_NCLBUTTONDOWN,HTBOTTOM, NULL)
					Case RightSize
						SetCursor(LoadCursor(0,IDC_SIZEWE))
						SendMessage(SelectHwnd, WM_NCLBUTTONDOWN,HTRIGHT, NULL)
					Case BottomLeftSize
						SetCursor(LoadCursor(0,IDC_SIZENESW))
						SendMessage(SelectHwnd, WM_NCLBUTTONDOWN, HTBOTTOMLEFT, NULL)
					Case BottomRightSize
						SetCursor(LoadCursor(0,IDC_SIZENWSE))
						SendMessage(SelectHwnd, WM_NCLBUTTONDOWN, HTBOTTOMRIGHT, NULL)
				End Select
			Case WM_HOTKEY
				Select Case EventWParam
					Case 1 To Hot_Key.CountHotKey
						HotKeyRun(EventWParam)
					Case 1000 To 1005
						Snap(EventWParam)
				End Select
		End Select
	Loop
End Sub
