;桌面logo
Schema_logo:
	Gui, 3:Default
	Gui, 3: -Caption +AlwaysOnTop -DPIScale ToolWindow +Owner +hwndWubi_Gui
	Gui, 3:Add, Picture,x0 y0 w12 h-1 BackgroundTrans gMoveGui vPics, ..\config/wubi86.icl
	GetKeyState, CL_State, CapsLock, T
	if CL_State ~="D"
		GuiControl,3:, Pics,*Icon17 ..\config\wubi86.icl
	else
	{
		if IMEmode~="off"
			GuiControl,3:, Pics,*Icon19 ..\config\wubi86.icl
		else
			GuiControl,3:, Pics,*Icon1 ..\config\wubi86.icl
	}
	Gui, 3:Color, 015BA3
	Gui, 3:Margin, 2,2
	if Logo_Switch ~="off"
		Gui, 3:Destroy
	else
		Gui, 3:Show, NA x%Logo_X% y%Logo_Y%,sign_wb
	WinSet, TransColor, 015BA3 240,sign_wb   ;方案Logo的透明度 数字越大透明度越低最大255，0为完全透明
Return

;logo开关
Logo_Switch:
	Logo_Switch :=(Logo_Switch~="off"?"on":"off")
	if Logo_Switch ~="off"
		Gui, 3:Destroy
	WubiIni.Settings["Logo_Switch"] :=Logo_Switch
	WubiIni.save()
	reload
Return


Del_EnKeyboard:    ;彻底删除系统美式英文键盘，因为是增删注册表的原因不能实时失效，需重启生效!调用的话直接 Gosub+空格+Del_EnKeyboard即可
	DelRegKey("HKEY_CURRENT_USER", "Keyboard Layout\Preload")
	DelRegKey("HKEY_USERS", ".DEFAULT\Keyboard Layout\Preload")
	RegDelete, HKEY_CURRENT_USER\Software\Microsoft\CTF\SortOrder\AssemblyItem\0x00000409
Return

;logo移动写入坐标
Write_Pos:
	WinGetPos, X_, Y_, , , sign_wb
	if (X_=""||Y_="")
	{
		Logo_X :=WubiIni.Settings["Logo_X"]:=200
		Logo_Y :=WubiIni.Settings["Logo_Y"]:=y2
		WubiIni.save()
	}
	else
	{
		Logo_X :=WubiIni.Settings["Logo_X"]:=X_
		Logo_Y :=WubiIni.Settings["Logo_Y"]:=Y_
		WubiIni.save()
	}
Return

;logo双击操作设定
MoveGui:
	PostMessage, 0xA1, 2, , , Ahk_Id %Wubi_Gui%
	Gosub Write_Pos
	if (A_GuiEvent = "DoubleClick")
	{
		Gosub Label_show
	}
Return

;托盘菜单
TRAY_Menu:
	global Wubi_Schema
	Menu, TRAY, NoStandard
	Menu, TRAY, DeleteAll
	program:="『柚子86五笔』"
	;Menu, Tray, Click, 2
	Menu, Tray, Add, 使用帮助,OnHelp
	Menu, TRAY, Icon, 使用帮助, ..\config\wubi86.icl, 3
	Menu, Tray, Add
	if (Initial_Mode ~="on"){
		Menu, setting, Add, 剪切板通道	√, Initial_Mode
		Menu, setting, Icon, 剪切板通道	√, ..\config\wubi86.icl, 15
	}else{
		Menu, setting, Add, 剪切板通道	×,Initial_Mode
		Menu, setting, Icon, 剪切板通道	×, ..\config\wubi86.icl, 15
	}
	Menu, setting, Add
	if (Startup ~="on"){
		Menu, setting, Add, 开机自启	√, Startup
		Menu, setting, Icon, 开机自启	√, ..\config\wubi86.icl, 15
	}else{
		Menu, setting, Add, 开机自启	×,Startup
		Menu, setting, Icon, 开机自启	×, ..\config\wubi86.icl, 15
	}
/*
	Menu, setting, Add
	if (lookup_status ~="on"){
		Menu, setting, Add, 转换查询	√, lookup_status
		Menu, setting, Icon, 转换查询	√, ..\config\wubi86.icl, 15
	}else{
		Menu, setting, Add, 转换查询	×,lookup_status
		Menu, setting, Icon, 转换查询	×, ..\config\wubi86.icl, 15
	}
*/
	Menu, setting, Add
	if (Cut_Mode ~="on"){
		Menu, setting, Add, 拆分显示	√, Cut_Mode
		Menu, setting, Icon, 拆分显示	√, ..\config\wubi86.icl, 15
	}else{
		Menu, setting, Add, 拆分显示	×,Cut_Mode
		Menu, setting, Icon, 拆分显示	×, ..\config\wubi86.icl, 15
	}
	Menu, setting, Add
	if (Prompt_Word ~="on"){
		Menu, setting, Add, 空码提示	√, Prompt_Word
		Menu, setting, Icon, 空码提示	√, ..\config\wubi86.icl, 15
	}else{
		Menu, setting, Add, 空码提示	×,Prompt_Word
		Menu, setting, Icon, 空码提示	×, ..\config\wubi86.icl, 15
	}
	Menu, setting, Add
	if (Trad_Mode ~="on"){
		Menu, setting, Add, 中文繁体, Trad_Mode
		Menu, setting, Icon, 中文繁体, ..\config\wubi86.icl, 6
	}else{
		Menu, setting, Add, 中文简体,Trad_Mode
		Menu, setting, Icon, 中文简体, ..\config\wubi86.icl, 15
	}
	Menu, setting, Add
	if (Textdirection ~="horizontal"){
		Menu, setting, Add, 候选横排, Textdirection
		Menu, setting, Icon, 候选横排, ..\config\wubi86.icl, 15
	}else{
		Menu, setting, Add, 候选竖排,Textdirection
		Menu, setting, Icon, 候选竖排, ..\config\wubi86.icl, 15
	}
	Menu, setting, Add
	if (limit_code ~="on"){
		Menu, setting, Add, 四码上屏	√, limit_code
		Menu, setting, Icon, 四码上屏	√, ..\config\wubi86.icl, 15
	}else{
		Menu, setting, Add, 四码上屏	×,limit_code
		Menu, setting, Icon, 四码上屏	×, ..\config\wubi86.icl, 15
	}
	Menu, setting, Add
/*
	if (symb_send ~="on"){
		Menu, setting, Add, 符号顶屏	√, symb_send
		Menu, setting, Icon, 符号顶屏	√, ..\config\wubi86.icl, 15
	}else{
		Menu, setting, Add, 符号顶屏	×,symb_send
		Menu, setting, Icon, 符号顶屏	×, ..\config\wubi86.icl, 15
	}
	Menu, setting, Add
*/
	if (Select_Enter ~="send"){
		Menu, setting, Add, 回车上屏, Select_Enter
		Menu, setting, Icon, 回车上屏, ..\config\wubi86.icl, 15
	}else if (Select_Enter ~="clean"){
		Menu, setting, Add, 回车清屏,Select_Enter
		Menu, setting, Icon, 回车清屏, ..\config\wubi86.icl, 15
	}
	Menu, Tray, Add, 更多设置,:setting
	Menu, TRAY, Icon, 更多设置, ..\config\wubi86.icl, 14
	Menu, Tray, Add
	if ToolTipStyle ~="on"{
		Menu, Tip_Style, Add, ToolTip样式	√,Tip_Style
		Menu, Tip_Style, Icon, ToolTip样式	√, ..\config\wubi86.icl, 15
	}else{
		Menu, Tip_Style, Add, ToolTip样式,Tip_Style
		Menu, Tip_Style, Icon, ToolTip样式, ..\config\wubi86.icl, 15
	}
	Menu, Tip_Style, Add
	if ToolTipStyle ~="off"{
		Menu, Tip_Style, Add, Gui候选样式	√,Tip_Style
		Menu, Tip_Style, Icon, Gui候选样式	√, ..\config\wubi86.icl, 15
	}else{
		Menu, Tip_Style, Add, Gui候选样式,Tip_Style
		Menu, Tip_Style, Icon, Gui候选样式, ..\config\wubi86.icl, 15
	}
	Menu, Tip_Style, Add
	if ToolTipStyle ~="i)Gdip"{
		Menu, Tip_Style, Add, Gdip候选样式	√,Tip_Style
		Menu, Tip_Style, Icon, Gdip候选样式	√, ..\config\wubi86.icl, 15
	}else{
		Menu, Tip_Style, Add, Gdip候选样式,Tip_Style
		Menu, Tip_Style, Icon, Gdip候选样式, ..\config\wubi86.icl, 15
	}
	Menu, Tray, Add, 候选样式, :Tip_Style
	Menu, TRAY, Icon, 候选样式, ..\config\wubi86.icl, 20
	Menu, Tray, Add
	;Menu, Tray, Default, 样式设置
	Menu, Tray, Add, 导入词库,OnWrite
	if Wubi_Schema~="zi"
		Menu, Tray, Disable, 导入词库
	Menu, TRAY, Icon, 导入词库, ..\config\wubi86.icl, 10
	Menu, Tray, Add
	Menu, Tray, Add, 导出词库,OnBackup
	if Wubi_Schema~="zi"
		Menu, Tray, Disable, 导出词库
	Menu, TRAY, Icon, 导出词库, ..\config\wubi86.icl, 11
	Menu, Tray, Add
	Menu, Tray, Add, 标签设置, OnLabel
	Menu, TRAY, Icon, 标签设置, ..\config\wubi86.icl, 8
	Menu, Tray, Add
	Menu, Tray, Add, 样式设置, Onconfig
	Menu, TRAY, Icon, 样式设置, ..\config\wubi86.icl, 6
	Menu, Tray, Add
	Menu, Tray, Add, 快捷造词,Add_Code
	if Wubi_Schema~="zi|chaoji"
		Menu, Tray, Disable, 快捷造词
	Menu, TRAY, Icon, 快捷造词, ..\config\wubi86.icl, 13
	Menu, Tray, Add
	Menu, Tray, Add, 显隐图标,Logo_Switch
	Menu, TRAY, Icon, 显隐图标, ..\config\wubi86.icl, 2
	Menu, Tray, Add
	Menu, Tray, Add, 启用状态	√,OnSuspend
	Menu, TRAY, Icon, 启用状态	√, ..\config\wubi86.icl, 18
	Menu, Tray, Add
	Menu, Tray, Add, 重载脚本,OnReload
	Menu, TRAY, Icon, 重载脚本, ..\config\wubi86.icl, 5
	Menu, Tray, Add
	Menu, Tray, Add, 退出程序,OnExit
	Menu, TRAY, Icon, 退出程序, ..\config\wubi86.icl, 7
	Menu,Tray,Tip,%program%
return

Disable_Tray:
	Menu, Tray, Disable, 导入词库
	Menu, Tray, Disable, 导出词库
return

Enable_Tray:
	Menu, Tray, Enable, 导入词库
	Menu, Tray, Enable, 导出词库
return

;托盘菜单候选样式选择
Tip_Style:
	if A_ThisMenuItem ~="i)ToolTip"&&ToolTipStyle<>"on"{
		Menu, Tip_Style, Rename, ToolTip样式,ToolTip样式	√
		if ToolTipStyle ~="gdip"
			Menu, Tip_Style, Rename, Gdip候选样式	√,Gdip候选样式
		else if ToolTipStyle ~="off"
			Menu, Tip_Style, Rename, Gui候选样式	√,Gui候选样式
		ToolTipStyle :=WubiIni.TipStyle["ToolTipStyle"] :="on"
		FontSize :=WubiIni.TipStyle["FontSize"] :="14"
	}
	else if A_ThisMenuItem ~="i)Gui"&&ToolTipStyle<>"off"{
		Menu, Tip_Style, Rename, Gui候选样式,Gui候选样式	√
		if ToolTipStyle ~="gdip"
			Menu, Tip_Style, Rename, Gdip候选样式	√,Gdip候选样式
		else if ToolTipStyle ~="on"
			Menu, Tip_Style, Rename, ToolTip样式	√,ToolTip样式
		ToolTipStyle :=WubiIni.TipStyle["ToolTipStyle"] :="off"
		FontSize :=WubiIni.TipStyle["FontSize"] :="16"
	}
	else if A_ThisMenuItem ~="i)Gdip"&&ToolTipStyle<>"gdip"{
		Menu, Tip_Style, Rename, Gdip候选样式,Gdip候选样式	√
		if ToolTipStyle ~="off"
			Menu, Tip_Style, Rename, Gui候选样式	√,Gui候选样式
		else if ToolTipStyle ~="on"
			Menu, Tip_Style, Rename, ToolTip样式	√,ToolTip样式
		ToolTipStyle :=WubiIni.TipStyle["ToolTipStyle"] :="gdip"
		FontSize :=WubiIni.TipStyle["FontSize"] :="24"
	}
	WubiIni.save()
	reload
Return

;挂起操作
OnSuspend:
	Suspend
	if (A_IsSuspended =1){
		Menu, TRAY, Rename, 启用状态	√ , 挂起状态	×
		Menu, TRAY, Icon, 挂起状态	×, ..\config\wubi86.icl, 4
		Traytip,  提示:,已切换至挂起状态！
	}
	else if A_IsSuspended =0
	{
		Menu, TRAY, Rename, 挂起状态	× , 启用状态	√
		Menu, TRAY, Icon, 启用状态	√, ..\config\wubi86.icl, 18
		Traytip,  提示:,已切换至启用状态！
	}
return

;重载操作
OnReload:
	if Logo_Switch ~="on"
		Gosub Write_Pos
	reload
return

;写入词库
OnWrite:
	Gosub Write_DB
Return

;导出词库
OnBackup:
	Gosub Backup_DB
Return

;帮助
OnHelp:
	Run  ..\config\ReadMe.png
return

;设置面板
Onconfig:
if WinExist("样式面板"){
	Traytip,  警告提示:,不能重复打开「样式面板」窗口！,,2
	Return
}
else
	Gosub Show_Setting
return

;标签设置页
OnLabel:
if WinExist("标签设置"){
	Traytip,  警告提示:,不能重复打开「标签设置」窗口！,,2
	Return
}
else
	Gosub Label_show
Return

;退出设定
OnExit:
	DB.closedb()
	DB_CI.closedb()
	DB_CJ.closedb()
	;Gosub Del_EnKeyboard          ;退出后从系统删除美式键盘，启用的话去掉注释符
	if Logo_Switch ~="on"
		Gosub Write_Pos
	if A_OSVersion contains 10.0
	{
		SwitchToChsIME()
		Traytip,  退出提示:,已切换至中文键盘！
	}
	ExitApp
return

;gui候选框
houxuankuangguicreate:
	Gui, houxuankuang:Destroy
	Gui, houxuankuang:+ToolWindow -Caption -DPIScale +AlwaysOnTop +hWndguihouxuankuang +Border
	Gui, houxuankuang:Font, s%FontSize%, %FontType%
	Gui, houxuankuang:Color, %BgColor%
	Gui, houxuankuang:Add, Text, x5 y3 vmyedit1 BackgroundTrans c%FontColor_Code%
	if Gdip_Line ~="off"
		Gui, houxuankuang:Add, Text, x0 yp+15 w%A_ScreenWidth% h1 0x10 vfengefu
	Gui, houxuankuang:Add, Text, x5 vmyedit2 BackgroundTrans c%FontColor%
	Gui, houxuankuang:Show, % "Hide x" A_ScreenWidth//2-A_ScreenWidth//8 " y" A_ScreenHeight-200
	Tip1hWnd:=ToolTip(1, "", "Q1 B" BgColor " T" FontColor_Code " S" FontSize*A_ScreenDPI/96 " F" FontType)
	ToolTip(2, "", "Q1 B" BgColor " T" FontColor " S" FontSize*A_ScreenDPI/96 " F" FontType)
	Height:=60
Return

;提词结果处理
srf_tooltip:
	if srf_all_Input ~="^[\,\#0-9]+"
	{
		srf_all_Input :=RegExReplace(srf_all_Input,"^\,","#")
		num_switch :=numTohz(srf_all_Input)
		StringSplit, num_for_select_arrays, num_switch, `n, `n
		if !num_switch
			tooltip(1)
		else
		{
			srf_for_select_for_tooltip :=num_for_select_arrays1 . "`n" . num_for_select_arrays2 . "`n" . num_for_select_arrays3 . "`n" . num_for_select_arrays4 . "`n" . num_for_select_arrays5
		}
	}

	If limit_code ~="on"
	{
		if (StrLen(srf_all_input)=4&&srf_all_input ~="^[a-yA-Y]")
		{
			if srf_for_select_Array.Length()=0{    ;如果无候选，则自动清空历史
				srf_for_select_for_tooltip:=
			}
			else if srf_for_select_Array.Length()=1 ;如果候选唯一，则自动上屏
			{
				srf_select(1)
				gosub srf_value_off
				srf_for_select_Array :=[]
			}
		}
		else if (StrLen(srf_all_input)>4&&srf_all_input ~="^[a-yA-Y]") ;五码顶字上屏，排除编码含z的拼音反查
		{
			if Textdirection ~="vertical"
			{
				loop,parse,srf_for_select_for_tooltip ,`n
				{
					sendinput % RegExReplace(A_LoopField,"^\d\.|〔.+|#\〔.+|>\d+\、|\d+\、|\s+","")
					break
				}
			}
			else
			{
				loop,parse,srf_for_select_for_tooltip ,%A_Space%
				{
					sendinput % RegExReplace(A_LoopField,"^\d\.|〔.+|#\〔.+|>\d+\.|\d+\.","")
					break
				}
			}
			srf_all_input :=RegExReplace(srf_all_input, "^[a-zA-Z]{4}", "")
			Gosub srf_tooltip_fanye
		}
		else if StrLen(srf_all_input)<4&&srf_for_select_Array.Length()=0&&srf_all_input ~="^[a-yA-Y]"
		{
			srf_for_select_for_tooltip :=
		}
	}
	else
	{
		if strlen(srf_all_input)>0&&srf_for_select_Array.Length()<1
			srf_for_select_for_tooltip :=
	}

	if srf_all_input ~="^z.+|^z|^``|^/|^~"
	{
		if (srf_for_select_Array.Length()<1)
			srf_for_select_for_tooltip :=
	}	
	Caret:=GetCaretPos()
	Gosub showhouxuankuang
	strlen(srf_all_input)>4&&srf_for_select_Array.Length()<1?"":(srf_for_select_for_tooltip :=)
Return

;候选下一页
MoreWait:
	If (waitnum*ListNum+ListNum<srf_for_select_Array.Length()){
		waitnum+=1
		Gosub srf_tooltip_fanye
	}
Return

;候选上一页
lessWait:
	If (waitnum>0){
		waitnum-=1
		Gosub srf_tooltip_fanye
	}
Return

;候选词条分页处理
srf_tooltip_fanye:
	if srf_all_Input ~="^``"{
		if srf_all_Input~="^``[a-z]+"
			srf_for_select_Array:=prompt_enword(RegExReplace(srf_all_Input,"``",""))
		else
			Sym_Array[1,1]:=srf_all_input, srf_for_select_Array:=Sym_Array
	}else if srf_all_Input ~="^/"{
		if srf_all_Input~="^/[a-z0-9]+"
			srf_for_select_Array:=prompt_symbols(srf_all_Input)
		else
			Sym_Array_1[1,1]:=srf_all_input, srf_for_select_Array:=Sym_Array_1
	}else if srf_all_Input ~="^z"{
		if srf_all_Input~="^z[a-z]+|^z\'[a-z]+"
			srf_all_input:=RegExReplace(srf_all_input,"^z|^z\'",srf_all_input~="'"?"z":"z'"), srf_for_select_Array:=get_word(srf_all_input, Wubi_Schema)
		else
		{

			if recent[1]{
				loop % objLength(recent)
					srf_for_select_Array[A_Index,1]:=recent[A_Index]
			}else{
				recent[1]:=srf_all_input
				loop % objLength(recent)
					srf_for_select_Array[A_Index,1]:=recent[A_Index]
			}
		}
	}else if srf_all_Input ~="^~"{
		srf_for_select_Array:=prompt_pinyin(srf_all_Input)
	}else{
		srf_for_select_Array:=get_word(srf_all_Input, Wubi_Schema)
	}
	srf_for_select_string:=""
	, loopindex:=srf_for_select_Array.Length()-ListNum*waitnum
	, loopindex:=(loopindex>ListNum?ListNum:loopindex)
	If (Textdirection="horizontal")
	{
		Loop %loopindex%
			srf_for_select_string.=A_Space A_Index "." srf_for_select_Array[ListNum*waitnum+A_Index,1] (Cut_Mode="on"&&a_FontList ~="五笔拆字字根字体|五笔字根字体"&&FontType ~="五笔拆字字根字体|五笔字根字体"&&srf_for_select_Array[ListNum*waitnum+A_Index, valueindex]<>""?Wubi_Schema~="chaoji"&&srf_all_Input~="i)z"||Wubi_Schema~="chaoji"?A_Space . srf_for_select_Array[ListNum*waitnum+A_Index, 3]:"〔" . srf_for_select_Array[ListNum*waitnum+A_Index, valueindex] . "〕":A_Space . srf_for_select_Array[ListNum*waitnum+A_Index, 3])
	}
	Else
	{
		Loop %loopindex%
			srf_for_select_string.="`n" A_Index "." srf_for_select_Array[ListNum*waitnum+A_Index, 1] (Cut_Mode="on"&&a_FontList ~="五笔拆字字根字体|五笔字根字体"&&FontType ~="五笔拆字字根字体|五笔字根字体"&&srf_for_select_Array[ListNum*waitnum+A_Index, valueindex]<>""?Wubi_Schema~="chaoji"&&srf_all_Input~="i)z"||Wubi_Schema~="chaoji"?A_Space . srf_for_select_Array[ListNum*waitnum+A_Index, 3]:"〔" . srf_for_select_Array[ListNum*waitnum+A_Index, valueindex] . "〕":A_Space . srf_for_select_Array[ListNum*waitnum+A_Index, 3])
	}

	if srf_for_select_string
		srf_for_select_for_tooltip:=Trim(srf_for_select_string,". `n") (Textdirection="vertical"?"`n":(Textdirection="horizontal"&&Ceil(srf_for_select_Array.Length()/ListNum)>1?A_Space:"")) (Ceil(srf_for_select_Array.Length()/ListNum)>1?(Cut_Mode="on"?("[ 第" waitnum+1 "页/共" Ceil(srf_for_select_Array.Length()/ListNum) "页 ]"):("[ " waitnum+1 "/" Ceil(srf_for_select_Array.Length()/ListNum) " ]")):"")
	Gosub srf_tooltip
Return

;候选框样式判断
showhouxuankuang:
	If (srf_all_Input=""){
		srf_for_select_for_tooltip:=""
		If (ToolTipStyle ~="off")
			ToolTip(1,""), ToolTip(2,"")
		Else
			Gui, houxuankuang:Hide
		Return
	}
	Caret:=GetCaretPos(), hasCaretPos:=1
	If (ToolTipStyle ~="on"){
		ToolTip(1, srf_all_Input, "x" Caret.x " y" Caret.y+Caret.h)
		WinGetPos, x, y, , Height, % "ahk_id" Tip1hWnd  ;   ;双行请启用
		ToolTip(2, srf_for_select_for_tooltip, "x" x " y" y+Height+5+Set_Range)
	} Else If (ToolTipStyle ~="off"){
		Gui, measure:Destroy
		Gui, measure:+ToolWindow -Caption -DPIScale +AlwaysOnTop
		Gui, measure:Font, s%FontSize%, %FontType%
		;WinSet, TransColor, %BgColor% 255, ahk_id %guihouxuankuang%
		Try {
			Gui, measure:Add, Text, vmeasureedit1, %srf_all_Input%
			GuiControlGet, measure_P1, measure:Pos, measureedit1
			Gui, measure:Add, Text, x0 yp+20 vmeasureedit2, % srf_for_select_for_tooltip
			GuiControlGet, measure_P2, measure:Pos, measureedit2
		}
		guihouxuankuang_width:=Max(measure_P1w, measure_P2w)+15
		if (srf_for_select_Array.Length()>0)
		{
			guihouxuankuang_height:=((srf_for_select_Array.Length()>ListNum or Textdirection ~="horizontal")?(measure_P1h+measure_P2h+25):(measure_P1h+measure_P2h))
			guihouxuankuang_x:=Max(Min(A_ScreenWidth-guihouxuankuang_width, Caret.X+15), 0)
			, guihouxuankuang_y:=Max(Min(A_ScreenHeight-guihouxuankuang_height, Caret.Y+30), 0)
			Gui, houxuankuang:Show, % "NA w" guihouxuankuang_width " h" guihouxuankuang_height " x" guihouxuankuang_x " y" guihouxuankuang_y
			;WinSet, Region, % "0-0 w" guihouxuankuang_width+3 " h" guihouxuankuang_height+3 " R15-15", ahk_id%guihouxuankuang%
			GuiControl, houxuankuang:Move, myedit1, % "w" measure_P1w " h" measure_P1h
			if Gdip_Line ~="off"{
				GuiControl, houxuankuang:Show, fengefu
				GuiControl, houxuankuang:Move, fengefu, % "y" measure_P1h+7
			}
			GuiControl, houxuankuang:Move, myedit2, % "w" measure_P2w " h" measure_P2h " y" measure_P1h+15
			GuiControl, houxuankuang:Text, myedit1, %srf_all_Input%
			GuiControl, houxuankuang:Show, myedit2
			GuiControl, houxuankuang:Text, myedit2, %srf_for_select_for_tooltip%
		}
		else
		{
			guihouxuankuang_height:=measure_P1h+measure_P2h/2
			guihouxuankuang_x:=Max(Min(A_ScreenWidth-guihouxuankuang_width, Caret.X+15), 0)
			, guihouxuankuang_y:=Max(Min(A_ScreenHeight-guihouxuankuang_height, Caret.Y+30), 0)
			Gui, houxuankuang:Show, % "NA w" guihouxuankuang_width " h" guihouxuankuang_height " x" guihouxuankuang_x " y" guihouxuankuang_y
			GuiControl, houxuankuang:Move, myedit1, % "w" measure_P1w " h" measure_P1h
			GuiControl, houxuankuang:Hide, fengefu
			GuiControl, houxuankuang:Text, myedit1, %srf_all_Input%
			GuiControl, houxuankuang:Hide, myedit2
		}
	} Else {
		GdipText(srf_all_Input, srf_for_select_for_tooltip, "x" Caret.X " y" Caret.Y+30 " h" FontColor_Code " c" FontColor " s" FontSize, BgColor, FontType)
	}
Return

;清除操作
srf_value_off:
	Critical, On
	If (ToolTipStyle ~="on")
		ToolTip(1), ToolTip(2)
	Else If (ToolTipStyle ~="off")
		Gui, houxuankuang:Hide
	Else
		GdipText("")
	num_for_select_arrays0=
	srf_for_select_for_tooltip:=""
	srf_all_Input:=output_words:="", hasCaretPos:=waitnum:=0
	jichu_for_select_Array:=[]
Return

;样式面板
More_Setting:
	Menu, StyleMenu, Add, Tooltip样式, Export
	Menu, StyleMenu, Add
	Menu, StyleMenu, Add, Gui候选框样式, Export
	Menu, StyleMenu, Add
	Menu, StyleMenu, Add, Gdip候选框样式, Export
	HMENU := Menu_GetMenuByName("StyleMenu")
	if (ToolTipStyle~="i)on")
		Menu_CheckRadioItem(HMENU, 1)
	else if (ToolTipStyle~="i)off")
		Menu_CheckRadioItem(HMENU, 3)
	else if (ToolTipStyle~="i)Gdip")
		Menu_CheckRadioItem(HMENU, 5)
	Gui, 86: +hwndhwndgui86
	Gui,86:Font, s11 Bold, songti
	Gui 86:Add, Tab3, x0 y0 w300 h300, 候选框选色|字体设置|其它设置|关于
	Gui, 86:Tab, 1
	Gui,86:Font
	Gui,86:Font, s11, songti
	Gui, 86:Add, Text,
	Gui, 86:Add, Text, xm-15 y+5 w100 Right, 编码选色：
	Gui, 86:Add, Button, x+0 w100 hwndhwndfontcolor_code gsetcolor vFontColor_Code
	Gui, 86:Add, Text,
	Gui, 86:Add, Text, xm-15 y+5 w100 Right, 选词选色：
	Gui, 86:Add, Button, x+0 w100 hwndhwndfontcolor gsetcolor vFontColor
	Gui, 86:Add, Text,
	Gui, 86:Add, Text, xm-15 y+5 w100 Right, 背景选色：
	Gui, 86:Add, Button, x+0 w100 hwndhwndbgcolor gsetcolor vBgColor
	CreateImageButton(hwndfontcolor_code,[{BC: fontcolor_code, 3D: 0}],5)
	CreateImageButton(hwndfontcolor,[{BC: fontcolor, 3D: 0}],5)
	CreateImageButton(hwndbgcolor,[{BC: bgcolor, 3D: 0}],5)
	;Menu_BarRightJustify(hwndgui86, 2)
	Gui, 86:Add, Text, xm-15 y+30 w100 Right, 选框风格：
	Gui, 86:Add, Button,x+0 w135 hwndHExportBtn gStyleMenu vStyleMenu, % ToolTipStyle~="on"?"Tooltip样式":ToolTipStyle~="off"?"Gui候选框样式":"Gdip候选框样式"
	Gui, 86:Tab, 2
	Gui, 86:Add, Text,
	Gui, 86:Add, Text, xm+5 y+5 w100 left, 字体选择：
	Gui, 86:Add, ComboBox,x+0 w120 choose%a_FontNow% gfonts_type vFontType, % a_FontList
	Gui, 86:Add, Text, xm+5 y+15 w100 left, 字号选择：
	Gui, 86:Add, Edit, x+0 w120 Limit2 Number vfont_value gfont_value
	Gui, 86:Add, UpDown, x+0 w120 vMyUpDown Range9-40 gfont_size vfontsize, %FontSize%
	Gui, 86:Add, Text, xm+5 y+15 w100 left, 候选数选择：
	Gui, 86:Add, Edit, x+0 w120 Limit2 Number vselect_value gselect_value
	Gui, 86:Add, UpDown, x+0 w120 vMyUpDown Range4-10 gset_select_value vset_select_value, %ListNum%
	Gui, 86:Add, Text, xm+5 y+15 w100 left, ToolTip框偏移值：
	Gui, 86:Add, Edit, x+0 w120 Limit2 Number vset_regulate_Hx gset_regulate_Hx
	if ToolTipStyle ~="off|gdip"
		GuiControl, 86:Disable, set_regulate_Hx
	Gui, 86:Add, UpDown, x+0 w120 vMyUpDown Range3-25 gset_regulate vset_regulate, %Set_Range%
	if ToolTipStyle ~="off|gdip"
		GuiControl, 86:Disable, set_regulate
	Gui, 86:Add, Text, xm+5 y+15 w100 left, Gdip编码与候选距离：
	Gui, 86:Add, Edit, x+0 w120 Limit2 Number vGdip_Hx gGdip_Hx
	if ToolTipStyle ~="off|on"
		GuiControl, 86:Disable, Gdip_Hx
	Gui, 86:Add, UpDown, x+0 w120 vMyUpDown Range1-20 gSet_Gdip_Hx vSet_Gdip_Hx, %Gdip_Down%
	if ToolTipStyle ~="off|on"
		GuiControl, 86:Disable, Set_Gdip_Hx
	Gui, 86:Tab, 3
	Gui, 86:Add, Text,
	Gui, 86:Tab, 4
	Gui,86:Font
	Gui,86:Font, s12 Bold, songti
	Gui 86:Add, Picture
	Gui,86:Add, Text, y+5, 详细帮助
	Gui 86:Add, Text, y+5 w260 h2 0x10
	Gui,86:Font
	Gui,86:Font, s11, songti
	Gui,86:Add, Text, y+5, 了解更多信息
	Gui,86:Add, Link, y+5, 关于：<a href="https://wubi98.gitee.io/">https://wubi98.gitee.io/</a>`n资源库：<a href="http://98wb.ys168.com">http://98wb.ys168.com</a>
	Gui,86:Add, Text, y+5, 版本日期：%Versions%
	Gui 86:Font, cRed
	Gui 86:Add, GroupBox, y+5 w260 h150, 更新说明
	Gui,86:Font
	Gui,86:Font, s9, songti
	FileRead, readme_, ..\config\ReadMe.txt
	Gui, 86:Add, Edit, xm+10 ym+150 w245 h118 Uppercase gAbout vAbout, %readme_%
	Gui,86:Color, ffffff
	Gui,86:Margin, 25, 35
	Gui,86:hide
Return

Show_Setting:
	Gosub More_Setting
	Gui, 86:Show,w300 h300, 样式面板
Return

StyleMenu:
	WinGetPos, X, Y, W, H, ahk_id %HExportBtn%
	X += W // 2
	Menu_ShowAligned(HMENU, hwndgui86, X, Y, "Center", "Bottom")
Return

Export:
	Menu_CheckRadioItem(HMENU, A_ThisMenuItemPos)
	if A_ThisMenuItem~="i)gdip"{
		GuiControl, 86:Text, StyleMenu , % A_ThisMenuItem
		ToolTipStyle :=WubiIni.TipStyle["ToolTipStyle"] :="Gdip"
		FontSize :=WubiIni.TipStyle["FontSize"] :="24"
	}else if A_ThisMenuItem~="i)Gui"{
		GuiControl, 86:Text, StyleMenu , % A_ThisMenuItem
		ToolTipStyle :=WubiIni.TipStyle["ToolTipStyle"] :="off"
		FontSize :=WubiIni.TipStyle["FontSize"] :="14"
	}else if A_ThisMenuItem~="i)ToolTip"{
		GuiControl, 86:Text, StyleMenu , % A_ThisMenuItem
		ToolTipStyle :=WubiIni.TipStyle["ToolTipStyle"] :="on"
		FontSize :=WubiIni.TipStyle["FontSize"] :="14"
	}
Return

About:
	GuiControlGet, About,, About, text
	FileDelete, ..\config\ReadMe.txt
	FileAppend,%About%, ..\config\ReadMe.txt,UTF-8
return

;gdip边框线开关（边框线开则中间的分割线消除，反之）
Gdip_Line:
	Gdip_Line :=(Gdip_Line~="off"?"on":"off")
	WubiIni.TipStyle["Gdip_Line"] :=Gdip_Line
	WubiIni.save()
Return

;剪切板通道
Initial_Mode:
	Initial_Mode :=(Initial_Mode~="off"?"on":"off")
	if Initial_Mode~="off"
		Menu, setting, Rename, 剪切板通道	√ , 剪切板通道	×
	else
		Menu, setting, Rename, 剪切板通道	× , 剪切板通道	√
	WubiIni.Settings["Initial_Mode"] :=Initial_Mode
	WubiIni.save()
Return

;选色面板结果处理
setcolor:
	CustomColors :=[]
	loop,parse,Color_Row1,`,
	{
		StrLen(A_LoopField)=8?(A_LoopField:=A_LoopField):(A_LoopField :=RegExReplace(A_LoopField,"0x","0x0"))
		CustomColors[A_index] := SubStr(A_LoopField,1,2) SubStr(A_LoopField,7,2) SubStr(A_LoopField,5,2) SubStr(A_LoopField,3,2)
	}
	loop,parse,Color_Row2,`,
	{
		StrLen(A_LoopField)=8?(A_LoopField:=A_LoopField):(A_LoopField :=RegExReplace(A_LoopField,"0x","0x0"))
		CustomColors[A_index+8] := SubStr(A_LoopField,1,2) SubStr(A_LoopField,7,2) SubStr(A_LoopField,5,2) SubStr(A_LoopField,3,2)
	}
	if (CustomColors.Length()<>16){   ;色值区域超规默认值设置
		CustomColors :=[0x99731C,0xECEEEE,0x8B4E01,0x444444,0xE89F00,0xFAF9DE,0x2DB6F8,0xFFC90,0xD77800,0x0A1B0D,0x97D4B9,0xEFAD00,0xBF7817,0xE3F6FD,0x362B00,0xDEDEDE]
		WubiIni.CustomColors["Color_Row1"]:= "0x1C7399,0xEEEEEC,0x014E8B,0x444444,0x009FE8,0xDEF9FA,0xF8B62D,0x90FC0F"
		WubiIni.CustomColors["Color_Row2"]:= "0x0078D7,0x0D1B0A,0xB9D497,0x00ADEF,0x1778BF,0xFDF6E3,0x002B36,0xDEDEDE"
	}
	If Dlg_Color(tempColor, hwndgui86, CustomColors*){
		WubiIni.TipStyle[A_GuiControl]:=%A_GuiControl%:=SubStr(tempColor, 3)
		CreateImageButton(hwnd%A_GuiControl%,[{BC: %A_GuiControl%, 3D: 0}],5)
	}
Return

;设置页面字号输入结果处理
font_value:
	GuiControlGet, font_value,, font_value, text
	FontSize :=WubiIni.TipStyle["FontSize"]:= font_value
Return

;设置页面字号选择结果处理
font_size:
	FontSize :=WubiIni.TipStyle["FontSize"]:= fontsize
Return

;设置页面字体选择结果处理
fonts_type:
	GuiControlGet, fonts_type_add,, FontType, text
	FontType :=WubiIni.TipStyle["FontType"]:= fonts_type_add
	Gdip_Down :=WubiIni.TipStyle["Gdip_Down"]:=8
	WubiIni.Settings["Cut_Mode"] :="off"
Return

;设置页面候选数量输入结果处理
select_value:
	GuiControlGet, select_value,, select_value, text
	ListNum := WubiIni.TipStyle["ListNum"]:= select_value
Return

;设置页面候选数量选择结果处理
set_select_value:
	ListNum := WubiIni.TipStyle["ListNum"]:= set_select_value
Return

;ToolTip偏移距离选择结果处理
set_regulate:
	Set_Range :=WubiIni.TipStyle["Set_Range"]:= set_regulate
Return

;ToolTip偏移距离输入结果处理
set_regulate_Hx:
	GuiControlGet, set_regulate_Hx,, set_regulate_Hx, text
	Set_Range :=WubiIni.TipStyle["Set_Range"]:= set_regulate_Hx
Return

;Gdip候选距离选择结果处理
Set_Gdip_Hx:
	Gdip_Down :=WubiIni.TipStyle["Gdip_Down"]:= Set_Gdip_Hx
Return

;Gdip候选距离输入结果处理
Gdip_Hx:
	GuiControlGet, Gdip_Hx,, Gdip_Hx, text
	Gdip_Down :=WubiIni.TipStyle["Gdip_Down"]:= Gdip_Hx
Return

;样式面板关闭销毁保存操作
86GuiClose:
	86GuiEscape:
	Gui, 86:Destroy
	WubiIni.Save()
	reload
Return

;开机自启动>>>批处理创建系统自启任务
Startup:
	If Startup ~="off" {
		Startup_path:=RegExReplace(DllCall("GetCommandLine", "Str"),"i)""( | /restart )"""," ")
		Command = schtasks /Create /TN "柚子86五笔" /TR %Startup_path% /SC ONLOGON /RL HIGHEST /F
		Try {
			Run *RunAs cmd.exe /c %Command%, , Hide
			Startup :=WubiIni.Settings["Startup"]:="on", WubiIni.save()
			Menu, setting, Rename, 开机自启	× , 开机自启	√
			Traytip,自启提示:,已设为开机自启!
		} Catch {
			Startup :="off"
		}
	} Else {
		Command = schtasks /Delete /TN "柚子86五笔" /F
		Try {
			Run *RunAs cmd.exe /c %Command%, , Hide
			Startup :=WubiIni.Settings["Startup"]:="off", WubiIni.save()
			Menu, setting, Rename, 开机自启	√ , 开机自启	×
			Traytip,自启提示:,已取消开机自启!
		} Catch {
			Startup :="on"
		}
	}
Return

/*创建快捷方式到系统启动目录的自启方法不稳，容易自动退出
;开机自启动
Startup:
	global Startup
	If Startup ~="off"
	{
		FileGetShortcut, %A_Startup%\AHK五笔86版.lnk , OutTarget,,,,,,
		Startup_Name :=RegExReplace(A_ScriptFullPath,".ahk", ".exe")
		Loop, %A_Startup%\*.*
		{
			FileGetShortcut, %A_Startup%\%A_LoopFileName% , FileTarget,,,,,,
			if (FileTarget = Startup_Name)
				FileDelete, %A_Startup%\%A_LoopFileName%
		}
		if (OutTarget <> Startup_Name)
		{
			FileCreateShortcut, %Startup_Name%, %A_Startup%\AHK五笔86版.lnk,, "%A_ScriptFullPath%", AHK五笔86版, %A_ScriptDir%\wubi86.ico
			Startup :="on"
			WubiIni.Settings["Startup"]:="on", WubiIni.save()
			Menu, setting, Rename, 开机自启	× , 开机自启	√
			Traytip,自启提示:,已设为开机自启!
		}
	} Else {
		FileGetShortcut, %A_Startup%\AHK五笔86版.lnk , OutTarget,,,,,,
		Startup_Name :=RegExReplace(A_ScriptFullPath,".ahk", ".exe")
		Loop, %A_Startup%\*.*
		{
			FileGetShortcut, %A_Startup%\%A_LoopFileName% , FileTarget,,,,,,
			if (FileTarget = Startup_Name)
				FileDelete, %A_Startup%\%A_LoopFileName%
		}
		Traytip,自启提示:,已取消开机自启!
		FileDelete, %A_Startup%\AHK五笔86版.lnk
		Startup :="off"
		Menu, setting, Rename, 开机自启	√ , 开机自启	×
		WubiIni.Settings["Startup"]:="off", WubiIni.save()
	}
Return
*/


;符号顶屏
symb_send:
	symb_send :=(symb_send~="off"?"on":"off")
/*
	if symb_send~="off"
		Menu, setting, Rename, 符号顶屏	√ , 符号顶屏	×
	else
		Menu, setting, Rename, 符号顶屏	× , 符号顶屏	√
*/
	WubiIni.Settings["symb_send"] :=symb_send
	WubiIni.save()
Return

;Gdip候选框圆角
Radius:
	Radius :=(Radius~="off"?"on":"off")
	if Radius~="on"
		WubiIni.TipStyle["Gdip_Line"] :="on"
	WubiIni.TipStyle["Radius"] :=Radius
	WubiIni.save()
	reload
return

;查询转换功能开关
lookup_status:
	lookup_status :=(lookup_status~="off"?"on":"off")
	if lookup_status~="off"
		Menu, setting, Rename, 转换查询	√ , 转换查询	×
	else
		Menu, setting, Rename, 转换查询	× , 转换查询	√
	WubiIni.Settings["lookup_status"] :=lookup_status
	WubiIni.save()
return

;空码提示
Prompt_Word:
	Prompt_Word :=(Prompt_Word~="off"?"on":"off")
	if Prompt_Word ~="off"
		Menu, setting, Rename, 空码提示	√,空码提示	×
	else
		Menu, setting, Rename,空码提示	×,空码提示	√
	WubiIni.Settings["Prompt_Word"] :=Prompt_Word
	WubiIni.save()
return

;含词/单字选择
Wubi_Schema:
	Wubi_Schema :=(Wubi_Schema~="zi|chaoji"?"ci":"zi")
	if Wubi_Schema ~="zi"{
		Gosub Disable_Tray
		Menu, Tray, Disable, 快捷造词
	}
	else if Wubi_Schema~="ci|chaoji"{
		Gosub Enable_Tray
		if Wubi_Schema~="ci"
			Menu, Tray, Enable, 快捷造词
		else
			Menu, Tray, Disable, 快捷造词
	}
	WubiIni.Settings["Wubi_Schema"] :=Wubi_Schema

	WubiIni.save()
return

;98超集方案选择
Extend_Schema:
	Wubi_Schema :=(Wubi_Schema~="zi|ci"&&a_FontList ~="98WB-V|98WB-P0|98WB-1"?"chaoji":"ci")
	if Wubi_Schema~="ci|chaoji"{
		Gosub Enable_Tray
		if Wubi_Schema~="ci"
			Menu, Tray, Enable, 快捷造词
		else
			Menu, Tray, Disable, 快捷造词
	}else{
		Gosub Disable_Tray
		Menu, Tray, Disable, 快捷造词
	}
	if (Wubi_Schema<>"chaoji"){
		Traytip,  失败提示,您的电脑可能没有安装支持98超集的字体`n或多次操作无效，当前切换为「86含词」方案!
		WubiIni.Settings["Wubi_Schema"]:=Wubi_Schema
	}else{
		WubiIni.Settings["Wubi_Schema"]:=Wubi_Schema
		Traytip,  切换提示,已切换至「五笔98超集方案」!
	}
	WubiIni.save()
return

;字根拆分
Cut_Mode:
	Cut_Mode :=(Cut_Mode~="off"?"on":"off")
	if Cut_Mode~="off"
		Menu, setting, Rename, 拆分显示	√ , 拆分显示	×
	else
		Menu, setting, Rename, 拆分显示	× , 拆分显示	√
	WubiIni.Settings["Cut_Mode"] :=Cut_Mode
	WubiIni.save()
return

;四码上屏
limit_code:
	limit_code :=(limit_code~="off"?"on":"off")
	if limit_code~="off"
		Menu, setting, Rename, 四码上屏	√ , 四码上屏	×
	else
		Menu, setting, Rename, 四码上屏	× , 四码上屏	√
	WubiIni.Settings["limit_code"] :=limit_code
	WubiIni.save()
return

;简繁转换
Trad_Mode:
	Trad_Mode :=(Trad_Mode~="off"?"on":"off")
	if Trad_Mode~="off"
		Menu, setting, Rename, 中文繁体 , 中文简体
	else
		Menu, setting, Rename, 中文简体 , 中文繁体
	WubiIni.Settings["Trad_Mode"] :=Trad_Mode
	WubiIni.save()
return

SwitchToEngIME:
	SwitchToEngIME()
return

SwitchToChsIME:
	SwitchToChsIME()
return

;候选样式标签选择处理
ToolTipStyle:
	if ToolTipStyle ~="on"
	{
		ToolTip(1), ToolTip(2)
		ToolTipStyle :="off"
		FontSize :=WubiIni.TipStyle["FontSize"]:=16
		WubiIni.TipStyle["ToolTipStyle"]:=ToolTipStyle
		WubiIni.save()
		reload
	}
	else if ToolTipStyle ~="off"
	{
		Gui, houxuankuang:Hide
		ToolTipStyle :="gdip"
		FontSize :=WubiIni.TipStyle["FontSize"]:=24
		WubiIni.TipStyle["ToolTipStyle"]:=ToolTipStyle
		WubiIni.save()
		reload
	}
	else if ToolTipStyle ~="gdip"
	{
		GdipText("")
		ToolTipStyle :="on"
		FontSize :=WubiIni.TipStyle["FontSize"]:=14
		WubiIni.TipStyle["ToolTipStyle"]:=ToolTipStyle
		WubiIni.save()
		reload
	}
return

;快捷造词
Add_Code:
if WinExist("造词窗口"){
	Traytip,  警告提示:,不能重复打开「快捷造词」窗口！,,2
	Return
}
else
{
	Gui, 29:Default
	Gui,29:Add, Edit, xp+0 yp+10 r10 w300 vSet_Value WantTab,请输入中文词语，多个词语请分行输入！`n如果输入自定义请遵循以下格式：uqid=http://98wb.ys168.com/`n无码造词和自由模式可以同时进行需分行输入。。。
	Gui, 29:Add, Button, gSave, 确定
	Gui, 29:Margin, 10 10
	Gui, 29:Submit
	Gui,29:show,,造词窗口
}
return

;造词窗口关闭销毁
29GuiClose:
	Gui, 29:Destroy
	29GuiEscape:
Return

;造词保存处理
Save:
	GuiControlGet, mb_add,, Set_Value, text
	return_num :=Save_word(mb_add)
	if (return_num>0)
	{
		Gui, 29:Destroy
		TrayTip,, 写入成功%return_num%个
	}
	else
		TrayTip,, 该词条已存在或自由选词格式不正确！
return

;标签设置页
Label_show:
	Gui, 25:Default
	Gui, 25:Add, text, ,<<<<<<<标签调用以/引导！「/+标签别名」>>>>>>>
	If DB.gettable("SELECT * FROM label", Result){
		label_RowCount := Result.RowCount
		Gui, 25:Add, ListView, r%label_RowCount% w500 Grid AltSubmit -ReadOnly -Multi -LV0x10 gMyLabel hwndHLV, 标签别名|label标签名|标签说明|当前状态
		GuiControl, +Hdr, MyLabel
		loop, % Result.RowCount
		{
			LV_Add("", Result.Rows[A_index,2], Result.Rows[A_index,3],Result.Rows[A_index,4],(WubiIni.Settings[Result.Rows[A_index,3]]!=""?(WubiIni.Settings[Result.Rows[A_index,3]]):(WubiIni.TipStyle[Result.Rows[A_index,3]])))
		}
		Loop, % LV_GetCount("Column"){
			LV_ModifyCol(1,"60 Integer center")
			LV_ModifyCol(2,"220 Integer left")
			LV_ModifyCol(3,"150 Integer left")
			LV_ModifyCol(4,"100 Integer left")
		}
		CLV := New LV_Colors(HLV)
		CLV.SelectionColors(0xfecd1b)
	}
	Gui, 25:Add, Button, gRest, 重置标签页
	Gui, 25:Add, Button,x+25 gBackup_label, 标签页导出
	Gui, 25:Add, Button,x+25 gWrite_label, 标签页导入
	Gui, 25:Add, CheckBox,xm+25 yp+30 w120 vColorsOn gSubShowColors Checked, 行列色开/关
	Gui, 25:Add, Radio, x+0 yp wp Checked vAltRows gSubColors, 行色错开
	CLV.AlternateRows(0x808080, 0xFFFFFF)
	Gui, 25:Add, Radio, x+0 yp wp vAltCols gSubColors, 列色错开
	Gui, 25:Add, Radio, x+0 yp wp vColors gSubColors, 行列色错开
	Gui, 25:Add, text, xm+0 yp+25,时间标签添加时以A_开头的多个内置变量以空格隔开，中间夹中文字符也以空格隔开！
	WinSet, Redraw, , ahk_id %HLV%
	Gui, 25:show,w520, 标签设置页

return

;标签页关闭销毁处理
25GuiClose:
	25GuiEscape:
	Gui, 25:Destroy
Return

SubShowColors:
	Gui, 25:Submit, NoHide
	If (ColorsOn)
		CLV.OnMessage()
	Else
		CLV.OnMessage(False)
	GuiControl, Focus, %HLV%
Return

SubColors:
	Gui, 25:Submit, NoHide
	GuiControl, -Redraw, %HLV%
	CLV.Clear(1, 1)
	If (Colors)
		GoSub, SetColors
	If (AltRows)
		CLV.AlternateRows(0x808080, 0xFFFFFF)
	If (AltCols)
		CLV.AlternateCols(0x808080, 0xFFFFFF)
	GuiControl, +Redraw, %HLV%
Return

SetColors:
	Loop, % LV_GetCount() {
		If (A_Index & 1) {
			CLV.Cell(A_Index, 1, 0x808080, 0xFFFFFF)
			CLV.Cell(A_Index, 3, 0x808080, 0xFFFFFF)
			CLV.Cell(A_Index, 5, 0x808080, 0xFFFFFF)
		} Else {
			CLV.Cell(A_Index, 2, 0x808080, 0xFFFFFF)
			CLV.Cell(A_Index, 4, 0x808080, 0xFFFFFF)
			CLV.Cell(A_Index, 6, 0x808080, 0xFFFFFF)
		}
	}
Return

;标签导入
Write_label:
	FileSelectFile, LabelFile, 3, , 导入标签文件, Text Documents (*.txt)
	SplitPath, LabelFile, , , , filename
	If (LabelFile = ""){
		TrayTip,, 取消导入
		Return
	} Else {
		TrayTip,, 你选择了文件「%filename%」
	}
	If !filename
		Return
	MsgBox, 52, 提示, 要导入以下标签文件进行替换？`n标签格式为：标签别名+Tab+标签名+Tab+标签说明
	IfMsgBox, No
	{
		TrayTip,, 导入已取消！
		Return
	} Else {
		TrayTip,, 标签写入中，请稍后...
		Create_label(DB,LabelFile)
		tarr:=[],count :=0
		FileEncoding, UTF-8
		FileRead, label_all, %LabelFile%
		Loop, Parse, label_all, `n, `r
		{
			count++
			If (A_LoopField = "")
				Continue
			tarr:=StrSplit(A_LoopField,A_Tab,A_Tab)
			Insert_label .="(null,'" tarr[1] "','" tarr[2] "','" tarr[3] "')" ","
		}
		Insert_label :=RegExReplace(Insert_label,"\,$","")
		if DB.Exec("INSERT INTO label VALUES" Insert_label "")>0
		{
			Gosub 25GuiClose
			Gosub Label_show
			TrayTip,, 写入%count%行label标签！
		}
		else
		{
			TrayTip,, 格式不对...
			return
		}
	}
	label_all:=Insert_label:=""
Return

;标签导出
Backup_label:
	FileSelectFolder, OutFolder,,3,请选择导出后保存的位置
	if OutFolder<>
	{
		if DB.gettable("SELECT B_Key,C_Key,D_Key FROM label",Result){
			FileDelete, %OutFolder%\label.txt
			Loop % Result.RowCount
			{
				Resoure_ .=Result.Rows[A_index,1] A_tab Result.Rows[A_index,2] A_tab Result.Rows[A_index,3] "`n"
			}
			FileAppend,%Resoure_%,%OutFolder%\label.txt, UTF-8
			TrayTip,, 导出完成，文件名路径为：`n「%OutFolder%\label.txt」
			Resoure_ :=OutFolder :=""
		}
	}
Return

;标签重置为默认
Rest:
	msgbox,1, 重置页面,是否重置标签页所有内容?
	IfMsgBox OK
	{
		if DB.Exec("DROP TABLE label")>0
		{
			DB.Exec("create table label as select * from label_init")
			Gosub reload_label
		}
	}
return

;标签页右击操作
MyLabel:
	if (A_GuiEvent = "RightClick")
	{
		LV_GetText(Out_value, A_EventInfo)
		Gosub GuiRightMenu
	}
return

;标签页右击菜单
GuiRightMenu:
	Menu, CONFIG,Add,编辑标签, update_label
	Menu, CONFIG, add,
	Menu, CONFIG,Add,刷新界面, reload_label
	Menu, CONFIG, add,
	Menu, CONFIG,Add,删除标签, delete_label
	MouseGetPos, xpos, ypos
	if (A_GuiEvent = "RightClick")
	{
		LV_GetText(pos, A_EventInfo)
		x_pos :=xpos-600,y_pos :=ypos-""
	}
	label_value :=pos
	label_num :=A_EventInfo
	Menu, CONFIG, Show, %A_careX%, %A_careY%
	Menu, CONFIG, delete

return

;刷新标签页
reload_label:
	Gosub 25GuiClose
	Gosub Label_show
Return

;标签页标签更名
update_label:
	InputBox, label_name, 标签自定义, 当前的标签名为`n「%label_value%」, ,150, 150
	if (ErrorLevel=0)
	{
		if (DB.Exec(SQL:="UPDATE label SET B_Key ='" label_name "' WHERE B_Key ='" label_value "';"))>0
		{
			LV_Modify(label_num,"text",label_name)
			TrayTip,, 修改成功
		}
	}
return

;标签删除
delete_label:
	msgbox,1, 删除确认,是否删除「%label_value%」标签
	IfMsgBox OK
	{
		if (label_value ="")
			SQL :="delete from label where C_Key is null or C_Key is null"
		else
			SQL :="DELETE FROM label WHERE B_Key ='" label_value "';"
		if (DB.Exec(SQL))>0
		{
			LV_Delete(label_num)
			TrayTip,, 删除成功
		}
	}
return

;方案词库导入（超集+含词）
Write_DB:
	FileSelectFile, MaBiaoFile, 3, , 导入词库, Text Documents (*.txt)
	SplitPath, MaBiaoFile, , , , filename
	If (MaBiaoFile = ""){
		TrayTip,, 取消导入
		Return
	} Else {
		TrayTip,, 你选择了文件「%filename%」
	}
	If !filename
		Return
	MsgBox, 52, 提示, 要导入以下词库进行替换？`n词库格式为：词条+Tab+编码
	IfMsgBox, No
	{
		TrayTip,, 导入已取消！
		Return
	} Else {
		Start:=A_TickCount
		TrayTip,, 词库写入中，请稍后...
		Wubi_Schema ~="chaoji"?(Create_Ci(DB_CJ,MaBiaoFile)):(Create_Ci(DB_CI,MaBiaoFile))
		tarr:=[],count :=0
		FileEncoding, UTF-8
		FileRead, MaBiao, %MaBiaoFile%
		Loop, Parse, MaBiao, `n, `r
		{
			count++
			If (A_LoopField = "")
				Continue
			tarr:=StrSplit(A_LoopField,A_Tab,A_Tab)
			Insert_ci .="('" tarr[1] "','" tarr[2] "')" ","
		}
		Insert_ci :=RegExReplace(Insert_ci,"\,$","")
		if Wubi_Schema ~="chaoji"?(DB_CJ.Exec("INSERT INTO chaoji VALUES" Insert_ci "")):(DB_CI.Exec("INSERT INTO ci VALUES" Insert_ci ""))>0
		{
			Time_count :=A_TickCount - Start
			TrayTip,, 写入%count%行！完成用时 %Time_count%ms
		}
		else
		{
			TrayTip,, 格式不对...
			return
		}
	}
	MaBiao:=Insert_ci:=""
return

;词库导出（98超集+86含词）	
Backup_DB:
	FileSelectFolder, OutFolder,,3,请选择导出后保存的位置
	if OutFolder<>
	{
		Start_out:=A_TickCount
		if Wubi_Schema ~="chaoji"?(DB_CJ.gettable("SELECT aim_chars,A_Key FROM chaoji",Result)):(DB_CI.gettable("SELECT aim_chars,A_Key FROM ci",Result)){
			if Wubi_Schema ~="chaoji"
				FileDelete, %OutFolder%\wubi98-%Wubi_Schema%.txt
			else
				FileDelete, %OutFolder%\wubi86-%Wubi_Schema%.txt
			Loop % Result.RowCount
			{
				Resoure_ .=Result.Rows[A_index,1] A_tab Result.Rows[A_index,2] "`n"
			}
			Backup_Time :=A_TickCount - Start_out
			if Wubi_Schema ~="chaoji"
				FileAppend,%Resoure_%,%OutFolder%\wubi98-%Wubi_Schema%.txt, UTF-8
			else
				FileAppend,%Resoure_%,%OutFolder%\wubi86-%Wubi_Schema%.txt, UTF-8
			Resoure_ :=OutFolder :=""
		}	TrayTip,, 导出完成用时 %Backup_Time%ms
	}
return

;候选横竖排
Textdirection:
	Textdirection :=(Textdirection="vertical"?"horizontal":"vertical")
	if Textdirection~="horizontal"
		Menu, setting, Rename, 候选竖排 , 候选横排
	else
		Menu, setting, Rename, 候选横排 , 候选竖排
	WubiIni.TipStyle["Textdirection"] :=Textdirection
	WubiIni.save()
return

;回车设定
Select_Enter:
	Select_Enter :=(Select_Enter="send"?"clean":"send")
	if Select_Enter~="send"
		Menu, setting, Rename, 回车清屏 , 回车上屏
	else
		Menu, setting, Rename, 回车上屏 , 回车清屏
	WubiIni.Settings["Select_Enter"] :=Select_Enter
	WubiIni.save()
return

;划词反查ToolTip窗口关闭设定
RemoveToolTip:
	SetTimer, RemoveToolTip, Off
	ToolTip(1,"")
return

;当前时间获取
get_time_now:
	StringRight, wk, A_YWeek, 2
	FormatTime, TimeVar, , tth时mm分ss秒
	FormatTime, DateVar, , ggyyyy年M月d日-ddd
	time=「%TimeVar%%A_MSec%"」
	send %time%
return

;农历日期时间获取
get_lunarDate_now:
	FormatTime, MIVar, , H
	FormatTime, RQVar, , yyyyMMdd
	lunar :=Date_GetLunarDate(RQVar)
	lunar_time :=Time_GetShichen(MIVar)
	send %lunar%%lunar_time%
return

;当前日期获取
get_date_now:
	StringRight, wk, A_YWeek, 2
	FormatTime, TimeVar, , tth时mm分ss秒
	FormatTime, DateVar, , ggyyyy年M月d日-ddd
	date=「%DateVar%｜第%wk%周」
	send %date%
return

;当前日期+时间获取
get_week_now:
	StringRight, wk, A_YWeek, 2
	FormatTime, TimeVar, , tth时mm分ss秒
	FormatTime, DateVar, , ggyyyy年M月d日-ddd
	week=「%DateVar%｜第%wk%周｜%TimeVar%%A_MSec%"」
	send %week%
return
