#Include "window9.bi"
#Include "linked_lists.bi"
Dim As Integer hwnd
Dim shared As Integer List_Con
Dim shared As Integer  List_Value
List_Con = NewList()
List_Value = NewList()
Sub SUBCONST()
	Var handle1=Read_file("const.txt")
	If handle1 Then
		While E_O_F(handle1)=0
			AddElement_S(List_Con,Read_String(handle1))
		Wend
	EndIf
	Close_file(handle1)
	DisableGadget(1,0):DisableGadget(3,0):DisableGadget(4,0)
	SetGadgetText(1,"")
End Sub
Sub SUBCONSTVALUE()
	Var handle=Read_file("const1.txt")
	If handle Then
		While E_O_F(handle)=0
			AddElement_S(List_Value,Read_String(handle))
		Wend
	EndIf
	Close_file(handle)
End Sub
Sub WriteClipboard(byval Text As String, byval CPFormat As Integer = CF_TEXT, byref hWnd As HWND = NULL)
	Var hGlobalClip = GlobalAlloc(GMEM_MOVEABLE Or GMEM_SHARE, Len(Text)+1)
	OpenClipboard(hWnd)
	EmptyClipboard()
	Var lpMem = GlobalLock(hGlobalClip)
	CopyMemory(lpMem, Strptr(Text), Len(text))
	GlobalUnlock(lpMem)
	SetClipboardData(CPFormat, hGlobalClip)
	CloseClipboard()
End Sub
hwnd=OpenWindow("Constants",10,10,210,130)
CenterWindow(hwnd) : WindowColor(hwnd,0)
StringGadget(1,10,10,130,20,"Loading..",ES_AUTOHSCROLL  ): DisableGadget(1,1)
TextGadget(2,10,50,130,20)
ButtonGadget(3,145,10,40,20,"Ok"):DisableGadget(3,1)
ButtonGadget(4,145,50,40,20,"Copy"):DisableGadget(4,1)
Dim As Byte flag
Var thread=ThreadCreate(@SUBCONST)
Var thread1=ThreadCreate(@SUBCONSTVALUE)
Do 
	Var ev=WindowEvent
	Select Case ev
		Case EventClose
			End
		Case EventGadget
			Select Case EventNumber
				Case 3
					Var tteexxtt=Trim(UCase(GetGadgetText(1)))
					If tteexxtt <>"" Then
						FirstElement(List_Con )
						Var index=0
						Do
							index+=1					
							If tteexxtt = UCase(GetList_S(List_Con)) Then
								SetGadgetText(2,GetValueElement_S(List_Value,index))
								flag=1
								Exit Do
							EndIf
						Loop Until NextElement(List_Con)=0
						If flag=0 Then SetGadgetText(2,"Not in database")
						flag=0
					EndIf
				Case 4
					If GetGadgetText(2)<>"" then
						WriteClipboard(GetGadgetText(2))
					endif
			End Select
	End Select
Loop

