; 客服小助手.ahk /* [config] ahk_version=ANSI icon=kfHelper.ico */ #NoEnv #SingleInstance force #Include Anchor.ahk #include Fnt.ahk #include TreeView_Drag.ahk SetWorkingDir, %A_ScriptDir% SetBatchLines, -1 gui_title := "客服小助手 v3.00" ini_file := A_ScriptDir "" SubStr(A_ScriptName, 1, -4) ".ini" ini_file2 := A_ScriptDir "" SubStr(A_ScriptName, 1, -4) "_font.ini" Gosub, font_Initialize /* 1.更改字体,微软雅黑,字体调整到9号就行。文字的颜色最好是可以随便的设置的。 2.在文字前面加上序列号,1 2 3 4 5 3.直接拖拽文字无法到聊天出口。可以取消上方的窗口,直接拖拽下面的文字到聊天窗口就行了。 4.软件需要可调整大小。 5.给第一级目录也添加个文件夹的小图标。 */ ; --------------------------------------- GUI --------------------------------------- gui, +LastFound +Resize gui_id := WinExist() GroupAdd, ThisGui, ahk_id %gui_id% ; --------- ; 拖拽需要的代码 ; --------- ; Set the message handlers OnMessage( 0x4E, "Treeview_BeginDrag" ) ; WM_NOTIFY OnMessage( 0x200, "Treeview_Dragging" ) ; WM_MOUSEMOVE OnMessage( 0x202, "Treeview_EndDrag" ) ; WM_LBUTTONUP hgui := WinExist() ; --------- ; 菜单 ; --------- Menu, gui_menu, Add, 添加分组(&G), menu_AddGroup Menu, gui_menu, Add, 添加内容(&I), menu_AddContent Menu, gui_menu, Add Menu, gui_menu, Add, 修 改(&M), menu_ModifyGroup Menu, gui_menu, Add, 选中删除(&D), menu_DeleteSelected Menu, gui_menu, Add, 选中复制(&C), menu_CopySelected Menu, gui_menu, Add, 全部删除(&E), menu_DeleteAll ;Menu, gui_menu, Add, 全部收起, menu_MinAll Menu, gui_menu, Add, 设置字体(&F), ChooseFont Menu, gui_menu, Icon, 添加分组(&G), shell32.dll, 4, 0 Menu, gui_menu, Icon, 添加内容(&I), shell32.dll, 2, 0 Menu, gui_menu, Icon, 修 改(&M), shell32.dll, 58, 0 Menu, gui_menu, Icon, 选中删除(&D), shell32.dll, 132, 0 Menu, gui_menu, Icon, 选中复制(&C), shell32.dll, 134, 0 Menu, gui_menu, Icon, 全部删除(&E), shell32.dll, 32, 0 Menu, gui_menu, Icon, 设置字体(&F), shell32.dll, 75, 0 ;loop, 200 ;{ ; Menu, menu1, Add, %A_Index%, menu_DeleteAll ; Menu, menu1, Icon, %A_Index%, shell32.dll, %A_Index%, 0 ;} ; --------- ; Shell.Explorer ; --------- html = Gui, Add, ActiveX, w500 h100 vWB, Shell.Explorer WB.silent := true WB.Navigate("about:tabs") WB.document.write(html) ; --------- ; TreeView ; --------- gui, font, %$FontOptions%, %$FontName% ImageListID := IL_Create(10) ; Create an ImageList with initial capacity for 10 icons. IL_Add(ImageListID, "shell32.dll", 4) IL_Add(ImageListID, "shell32.dll", 2) Gui, Add, TreeView, xm w500 h500 vMyTreeView gMyTreeView AltSubmit ImageList%ImageListID% HWNDhTreeview ; 载入上次退出时的 TreeView 列表 LoadTreeView() ;TVX("MyTreeView", "Handler", "HasRoot CollapseOnMove ") ; --------- ; 子窗口 ; --------- gui, inputbox:Font, s12 gui, inputbox:add, Text, vPromptText w200 gui, inputbox:add, edit, vGroupText w300 h200 gui, inputbox:add, Button, x50 w100 Section gbtn_ok, 确定 gui, inputbox:add, Button, ys w100 gbtn_cancel, 取消 Gui, Show,, %gui_title% WB.document.getElementById("txt").value := "可直接在此处拖拽文字到QQ聊天窗口" WB.document.getElementById("txt").focus ControlSend, Internet Explorer_Server1, {CtrlDown}{End}{ShiftDown}{Home}{ShiftUp}{CtrlUp}, A return ; ------------------------------------------------------------------------------------------------- ; =================== ; 添加分组 ; =================== menu_AddGroup: IsModifyGroup = GuiControl, inputbox:, GroupText GuiControl, inputbox:, PromptText, 请输入分组信息 Gui 1:+Disabled gui, inputbox:+owner1 GuiControl, inputbox:Focus, GroupText gui, inputbox:show,, 添加分组 Return ; ------------- ; 确定 ; ------------- btn_ok: gui 1:-Disabled gui, inputbox:Submit if GroupText != { gui, 1:default ;GroupText := RegExReplace(GroupText, "[rn]", "#") if IsModifyGroup = 2 TV_Add(GroupText, id, "expand Icon2") else if IsModifyGroup TV_Modify(id , "", GroupText) else TV_Add(GroupText, "", "bold expand") } return ; ------------- ; 取消 ; ------------- btn_cancel: inputboxGuiClose: inputboxGuiEscape: gui 1:-Disabled gui, inputbox:Cancel Return ; =================== ; 修改分组 ; =================== menu_ModifyGroup: if !id := TV_GetSelection() Return IsModifyGroup = yes TV_GetText(GroupText_Old, id) GuiControl, inputbox:, GroupText, %GroupText_Old% GuiControl, inputbox:, PromptText, 请输入新的分组信息 Gui 1:+Disabled gui, inputbox:+owner1 GuiControl, inputbox:Focus, GroupText gui, inputbox:show,, 修 改 Return ; =================== ; 添加内容 ; =================== menu_AddContent: if !id := TV_GetSelection() Return IsModifyGroup = 2 GuiControl, inputbox:, GroupText GuiControl, inputbox:, PromptText, 请输入内容 Gui 1:+Disabled gui, inputbox:+owner1 GuiControl, inputbox:Focus, GroupText gui, inputbox:show,, 添加内容 Return ; =================== ; 选中删除 ; =================== menu_DeleteSelected: if id := TV_GetSelection() TV_Delete(id) Return ; =================== ; 选中复制 ; =================== menu_CopySelected: if TV_GetSelection() { TV_GetText(SelectedText, TV_GetSelection()) StringReplace, SelectedText, SelectedText, #, `r`n, All Clipboard := SelectedText ToolTip, 已复制 Sleep, 1000 ToolTip } Return ; =================== ; 全部删除 ; =================== menu_DeleteAll: MsgBox2("确定要全部删除吗?", "确认删除", 36) IfMsgBox, Yes TV_Delete() Return ; =================== ; 全部收起 ; =================== menu_MinAll: Gui, Font, s18 cRed, Verdana ; If desired, use a line like this to set a new default font for the window. GuiControl, Font, MyTreeView Return ; ------------------------------------ 显示右键菜单 ---------------------------------------- GuiContextMenu: if A_GuiControl MyTreeView return ;Menu, menu1, Show Menu, gui_menu, Show Return ; ------------------------------------------------------------------------------------------ ; ------------------------------------ 处理单击、双击事件 --------------------------------- MyTreeView: if A_GuiEvent = Normal ; 左键点击则修改 Shell.Explorer 控件文字,并且全选 { KeyWait, LButton ; 等待鼠标松开 TV_GetText(SelectedText, TV_GetSelection()) ; 获取选中文字 WB.document.getElementById("txt").value := SelectedText ; 修改 Shell.Explorer 控件文字 WB.document.getElementById("txt").focus ; 调整焦点至 Shell.Explorer 控件 ControlSend, Internet Explorer_Server1, {CtrlDown}{End}{ShiftDown}{Home}{ShiftUp}{CtrlUp}, A ; 全选 GuiControl, Focus, MyTreeView ; 调整焦点至 TreeView } if A_GuiEvent = DoubleClick ; 双击则复制选中文字 goto, menu_CopySelected return ; ------------------------------------------------------------------------------------------ ; ------------------------------------ 判断拖拽 -------------------------------------------- ; 判断是否拖拽文字到其他的窗口。如果是,则拖拽完后恢复 Shell.Explorer 控件文字,并且全选 #IfWinActive, ahk_group ThisGui ~LButton:: KeyWait, LButton MouseGetPos,,, win_id if (win_id != gui_id) { WB.document.getElementById("txt").value := SelectedText WB.document.getElementById("txt").focus ControlSend, Internet Explorer_Server1, {CtrlDown}{End}{ShiftDown}{Home}{ShiftUp}{CtrlUp}, A } return ; ------------------------------------------------------------------------------------------ ; ---------------- 调整窗口大小时,修改控件位置/大小 ------- GuiSize: Anchor("WB", "w") Anchor("MyTreeView", "wh") Return ; ---------------------------------------------------------- ; ---------------- 退出时保存 TreeView 列表 ---------------- GuiClose: savetreeview() ExitApp ; ---------------------------------------------------------- font_Initialize: GUI_Effects = 1 ;-- ChooseFont flags CF_SCRIPTSONLY :=0x400 ;-- Allow selection of fonts for all non-OEM and Symbol character sets, as ; well as the ANSI character set. CF_NOOEMFONTS :=0x800 ;-- (Despite what the documentation states, this flag is used to) prevent ; the dialog box from displaying and selecting OEM fonts. Ex: Terminal CF_NOSIMULATIONS :=0x1000 ;-- Prevent the dialog box from displaying or selecting font simulations. CF_LIMITSIZE :=0x2000 ;-- Select only font sizes within the range specified by the nSizeMin and ; nSizeMax members. This flag is automatically added if the SizeMin ; and/or the SizeMax options (p_Options parameter) are used. CF_FIXEDPITCHONLY :=0x4000 ;-- Show and allow selection of only fixed-pitch fonts. CF_FORCEFONTEXIST :=0x10000 ;-- Display an error message if the user attempts to select a font or style ; that is not listed in the dialog box. CF_SCALABLEONLY :=0x20000 ;-- Show and allow selection of only scalable fonts. Scalable fonts include ; vector fonts, scalable printer fonts, TrueType fonts, and fonts scaled ; by other technologies. CF_TTONLY :=0x40000 ;-- Show and allow the selection of only TrueType fonts. CF_NOFACESEL :=0x80000 ;-- Prevent the dialog box from displaying an initial selection for the font ; name combo box. CF_NOSTYLESEL :=0x100000 ;-- Prevent the dialog box from displaying an initial selection for the ; Font Style combo box. CF_NOSIZESEL :=0x200000 ;-- Prevent the dialog box from displaying an initial selection for the Font ; Size combo box. CF_NOSCRIPTSEL :=0x800000 ;-- Disables the Script combo box. CF_NOVERTFONTS :=0x1000000 ;-- Display only horizontally oriented fonts. ;-- Initialize ;$FontName :="Arial" ;$FontOptions:="s20 " IniRead, $FontName, %ini_file2%, Settings, FontName, Arial IniRead, $FontOptions, %ini_file2%, Settings, FontOptions, s20 ;;;;;$FontOptions:="s48 SizeMin10 " ;;;;;$FontOptions:="s48 SizeMax12 " ;;;;;$FontOptions:="s48 SizeMin10 SizeMax12 " ;-- Collect window handle gui +LastFound WinGet hWindow,ID Return ChooseFont: ;gui Submit,NoHide Flags :=0 if GUI_SCRIPTSONLY Flags|=CF_SCRIPTSONLY if GUI_NOOEMFONTS Flags|=CF_NOOEMFONTS if GUI_FIXEDPITCHONLY Flags|=CF_FIXEDPITCHONLY if GUI_SCALABLEONLY Flags|=CF_SCALABLEONLY if GUI_TTONLY Flags|=CF_TTONLY if GUI_NOFACESEL Flags|=CF_NOFACESEL if GUI_NOSTYLESEL Flags|=CF_NOSTYLESEL if GUI_NOSIZESEL Flags|=CF_NOSIZESEL if GUI_NOSCRIPTSEL Flags|=CF_NOSCRIPTSEL if GUI_NOVERTFONTS Flags|=CF_NOVERTFONTS if not Fnt_ChooseFont(hWindow,$FontName,$FontOptions,GUI_Effects,Flags) return ;-- Create and set font (via AutoHotkey) gui Font, %$FontOptions%, %$FontName% GUIControl Font, MyTreeView ;-- Reset font to system default gui Font ;-- Update text on the Edit control. To show that the correct font with ; the specified options has been created, collect the font name/size using ; library functions. GUIControl , ,MyTreeView ,% Fnt_GetFontName(Fnt_GetFont(hEdit)) . "`nSize: " . Fnt_GetFontSize(Fnt_GetFont(hEdit)) . "`nOptions: " . $FontOptions IniWrite, %$FontOptions%, %ini_file2%, Settings, FontOptions IniWrite, %$FontName%, %ini_file2%, Settings, FontName return ; ================================================== Functions ================================================== MsgBox2(Text, Title = "", Options = "") { gui, +OwnDialogs MsgBox, % Options, %Title%, %Text% } LoadTreeView() { global IfExist, %ini_file% { FileRead, treelist, %ini_file% treelist := Trim(treelist, "`t`r`n ") if treelist { loop, parse, treelist, `n, `r { StringSplit, a, A_LoopField, =| options := (a3 = "0") ? "expand bold Icon1" : "expand Icon2" g%A_Index% := TV_Add(uriDecode(a2), %a3%, options) } } } } savetreeview() { global ini_file ItemID = 0 Loop { if !id:= TV_GetNext(id, "Full") break TV_GetText(text,id) if parentid:=TV_GetParent(id) if parentid not in %parentlist% { parentlist.=parentid "," g%parentid%:="g" . a_index-1 } if parentid list.="g" . a_index . "=" uriEncode(text) "|" g%parentid% "`n" else list.="g" . a_index . "=" uriEncode(text) "|0`n" } FileDelete, %ini_file% FileAppend, %list%, %ini_file% } uriEncode(str) { ; v 0.3 / (w) 24.06.2008 by derRaphael / zLib-Style release b_Format := A_FormatInteger data := "" SetFormat,Integer,H Loop,Parse,str if ((Asc(A_LoopField)>0x7f) || (Asc(A_LoopField)