; 以下函数来自AHK-Rare,测试都失效了。留个备份

; 如果在编辑控件中选择了文本,则返回布尔值
Edit_TextIsSelected(Control="", WinTitle="") {
  Edit_Standard_Params(Control, WinTitle)
  return Edit_GetSelection(start, end, Control, WinTitle) and (start!=end)
}

; 在编辑控件中获取选定的文本
Edit_GetSelection(ByRef start, ByRef end, Control="", WinTitle="") {				
  Edit_Standard_Params(Control, WinTitle)
  VarSetCapacity(start, 4), VarSetCapacity(end, 4)
  SendMessage, 0xB0, &start, &end, %Control%, %WinTitle%  ; EM_GETSEL
  if (ErrorLevel="FAIL")
    return false
  start := NumGet(start), end := NumGet(end)
  return true
}

; 在编辑控件中选择文本
Edit_Select(start=0, end=-1, Control="", WinTitle="") {									
  ; Selects text in a text box, given absolute character positions (starting at 0.)
  ; start:    Starting character offset, or -1 to deselect.
  ; end:      Ending character offset, or -1 for "end of text."

  Edit_Standard_Params(Control, WinTitle)
  SendMessage, 0xB1, start, end, %Control%, %WinTitle%  ; EM_SETSEL
  return (ErrorLevel != "FAIL")
}


; 在编辑控件中选择一行
Edit_SelectLine(line=0, include_newline=false, Control="", WinTitle="") {		
  ; Selects a line of text.
  ; line:             One-based line number, or 0 to select the current line.
  ; include_newline:  Whether to also select the line terminator (`r`n).

  Edit_Standard_Params(Control, WinTitle)

  ControlGet, hwnd, Hwnd,, %Control%, %WinTitle%
  if (!WinExist("ahk_id " hwnd))
    return false

  if (line<1)
    ControlGet, line, CurrentLine

  SendMessage, 0xBB, line-1, 0  ; EM_LINEINDEX
  offset := ErrorLevel

  SendMessage, 0xC1, offset, 0  ; EM_LINELENGTH
  lineLen := ErrorLevel

  if (include_newline) {
    WinGetClass, class
    lineLen += (class="Edit") ? 2 : 1 ; `r`n : `n
  }

  ; Select the line.
  SendMessage, 0xB1, offset, offset+lineLen  ; EM_SETSEL
  return (ErrorLevel != "FAIL")
}

; 在编辑控件中删除一行
Edit_DeleteLine(line=0, Control="", WinTitle="") {
  ; Deletes a line of text.
  ; line:     One-based line number, or 0 to delete current line.

  Edit_Standard_Params(Control, WinTitle)
  ; Select the line.
  if (Edit_SelectLine(line, true, Control, WinTitle))
  {   ; Delete it.
    ControlSend, %Control%, {Delete}, %WinTitle%
    return true
  }
  return false
}

; 这些是用于编辑控件的辅助函数
Edit_Standard_Params(ByRef Control, ByRef WinTitle) {
  if (Control = "A" && WinTitle="") { ; Control is "A", use focused control.
    ControlGetFocus, Control, A
    WinTitle = A
  } else if (Control+0!="" && WinTitle="") {  ; Control is numeric, assume its a ahk_id.
    WinTitle := "ahk_id " . Control
    Control := ""
  }
}

 

声明:站内资源为整理优化好的代码上传分享与学习研究,如果是开源代码基本都会标明出处,方便大家扩展学习路径。请不要恶意搬运,破坏站长辛苦整理维护的劳动成果。本站为爱好者分享站点,所有内容不作为商业行为。如若本站上传内容侵犯了原著者的合法权益,请联系我们进行删除下架。