Jump to content

Recommended Posts

Posted

Larry/Jon/team, please consider this un-official submission for obtaining the current column in an edit control. It seems to work, but there may be bugs

Addition to ControlCommand documentation:

"GetCurrentCol", ""
    Returns the column # where the caret is in an Edit

Example usage:

; Shows coordinates of caret cursor in Notepad
Opt("WinTitleMatchMode", 2)
While 1
   $x = ControlCommand("Notepad", "", "Edit1", "getCurrentLine", "" )
   $y = ControlCommand("Notepad", "", "Edit1", "getCurrentCol", "" )
   ToolTip("Ln " & $x & " , Col " & $y,  0,0)
   sleep(100)
WEnd

Add this code like this to the Win_ControlCommand() function in file script_win.cpp

if ( strcmpi(szCmd,"GETCURRENTCOL")==0 )
{
    uint nStart, nEnd, nOriginal;
    int  nLine;
    SendMessage(m_ControlSearchHWND,EM_GETSEL,(WPARAM)&nStart,(LPARAM)&nEnd);
    nOriginal = nStart;  //the charcter index

    //Decrement the character index until the row changes
    //Difference between this char index and original is the column.

    nLine = (int)SendMessage(m_ControlSearchHWND,EM_LINEFROMCHAR,(WPARAM)nStart,0);
    if (nLine >= 1)
    {
        while (nLine == (int)SendMessage(m_ControlSearchHWND,EM_LINEFROMCHAR,(WPARAM)nStart,0))
        {
           nStart--;
        }
        vResult = (int)nOriginal - (int)nStart;  //no off-by one error :)
    }
    else
        vResult = (int)nStart + 1;  //add 1 because first char index is 0
    break;
}
Use Mozilla | Take a look at My Disorganized AutoIt stuff | Very very old: AutoBuilder 11 Jan 2005 prototype I need to update my sig!

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...