A few additional HiEdit functions that I've been using lately. Please feel free to add, modify, and/or ignore.
Code:
;-------------------------------------------------------------------------------
; Function: HE_GetRect
;
; Gets the formatting rectangle of the HiEdit control.
;
;
; Parameters:
;
; Left, Right, Top, Botttom - These parameters, which must contain
; valid variable names, are used to return the formatting rectangle of
; the HiEdit control.
;
;
; Returns:
;
; {None}. Coordinates are returned in the ByRef parameters.
;
;
HE_GetRect(hEdit,ByRef Left,ByRef Top,ByRef Right,ByRef Bottom)
{
Static EM_GETRECT:=0xB2
VarSetCapacity(RECT_Structure,16,0)
SendMessage EM_GETRECT,0,&RECT_Structure,,ahk_id %hEdit%
Left :=NumGet(RECT_Structure,0,"Int")
Top :=NumGet(RECT_Structure,4,"Int")
Right :=NumGet(RECT_Structure,8,"Int")
Bottom:=NumGet(RECT_Structure,12,"Int")
return
}
;-------------------------------------------------------------------------------
; Function: HE_CharFromPos
;
; Gets information about the character closest to a specified point
; in the client area of the HiEdit control.
;
;
; Parameters:
;
; x, y - The x/y-coordinates of a point in the HiEdit control's client
; area relative to the upper-left corner of the client area.
;
;
; Returns:
;
; The character index of the specified point or the character index to
; the last character if the given point is beyond the last character
; in the control.
;
;
HE_CharFromPos(hEdit,x,y)
{
Static EM_CHARFROMPOS:=0xD7
SendMessage EM_CHARFROMPOS,0,(y<<16)|x,,ahk_id %hEdit%
return ErrorLevel
}
;-------------------------------------------------------------------------------
; Function: HE_PosFromChar
;
; Gets the client area coordinates of a specified character in the
; HiEdit control.
;
;
; Parameters:
;
; iChar - The zero-based index of the character.
;
; x, y - These parameters, which must contain valid variable names,
; are used to return the x/y-coordinates of a point in the HiEdit
; control's client relative to the upper-left corner of the client
; area.
;
;
; Returns:
;
; {None}. The coordinates are returned in ByRef parameters.
;
; Note: If iChar is greater than the index of the last character in
; the control, the returned coordinates are of the position just past
; the last character of the control.
;
;
HE_PosFromChar(hEdit,iChar,ByRef x,ByRef y)
{
Static EM_POSFROMCHAR:=0xD6
VarSetCapacity(POINTL_Structure,8,0)
SendMessage EM_POSFROMCHAR,&POINTL_Structure,iChar,,ahk_id %hEdit%
x:=NumGet(POINTL_Structure,0,"Int")
y:=NumGet(POINTL_Structure,4,"Int")
return
}
;-------------------------------------------------------------------------------
; Function: HE_GetLastVisibleLine
;
; Returns the zero-based line index of the last visible (including
; partially displayed) line on the HiEdit control.
;
; Remarks:
;
; To calculate the total number of visible lines, use the following:
;
; HE_GetLastVisibleLine(hEdit)-HE_GetFirstVisibleLine(hEdit)+1
;
;
HE_GetLastVisibleLine(hEdit)
{
HE_GetRect(hEdit,Left,Top,Right,Bottom)
return HE_LineFromChar(hEdit,HE_CharFromPos(hEdit,0,Bottom))
}
;-------------------------------------------------------------------------------
; Function: Cut, Copy, Paste, Clear (aka Delete)
;
; Standard edit commands for the HiEdit control.
;
;
; Returns:
;
; {None}
;
;
; Remarks:
;
; These messages are more efficent/reliable than sending the
; associated shortcut keys (Ctrl+X, Ctrl+C, etc.) to the HiEdit
; control.
;
;
HE_Cut(hEdit)
{
Static WM_CUT:=0x300
SendMessage WM_CUT,0,0,,ahk_id %hEdit%
return
}
HE_Copy(hEdit)
{
Static WM_COPY:=0x301
SendMessage WM_COPY,0,0,,ahk_id %hEdit%
return
}
HE_Paste(hEdit)
{
Static WM_PASTE:=0x302
SendMessage WM_PASTE,0,0,,ahk_id %hEdit%
return
}
HE_Clear(hEdit)
{
Static WM_CLEAR:=0x303
SendMessage WM_CLEAR,0,0,,ahk_id %hEdit%
return
}
;-------------------------------------------------------------------------------
; Function: HE_CanPaste
;
; Determines whether a HiEdit control can paste a specified clipboard
; format.
;
;
; Parameters:
;
; ClipboardFormat - The default is 0x1 (CF_TEXT).
;
;
; Returns:
;
; TRUE if the clipboard format can be pasted otherwise FALSE.
;
;
; Remarks:
;
; The HiEdit control supports the standard clipboard text formats --
; CF_TEXT, CF_OEMTEXT, CF_UNICODETEXT (for Windows versions that
; support Unicode), and CF_LOCALE (used by the OS to implicitly
; convert from CF_TEXT to CF_UNICODETEXT). If any application copies
; text of any type to the clipboard, it will usually copy the text to
; one (usually all, depending on the OS) of these clipboard formats.
;
; For additional information on clipboard formats, see the following:
;
; http://msdn.microsoft.com/en-us/library/ms649013(VS.85).aspx
;
;
; Observations:
;
; Despite the HiEdit documentation, sending zero as the clipboard
; format never returns a non-zero (can paste) value regardless of
; the contents of the clipboard. [Bug]
;
;
HE_CanPaste(hEdit,ClipboardFormat=0x1) ;-- 0x1=CF_TEXT
{
Static EM_CANPASTE:=1074 ;-- 1074=WM_USER+50
SendMessage EM_CANPASTE,ClipboardFormat,0,,ahk_id %hEdit%
return ErrorLevel ? True : False
}