Sign in to follow this  
Followers 0
CyberSlug

Get Edit1 Current Column

2 posts in this topic

Is it possible* to retrieve the column position of the caret cursor in an edit control? Assume a generic edit control (created via AutoGUI, for example).

ControlCommand ( "title", "text", "Edit", "GetCurrentLine", "")

works well for finding the row.... so what about columns?

*Please don't give me workarounds that involve selecting text; I already know that :whistle:


Use Mozilla | Take a look at My Disorganized AutoIt stuff | Very very old: AutoBuilder 11 Jan 2005 prototype I need to update my sig!

Share this post


Link to post
Share on other sites



I have an idea how to implement my request--but my C++ is rusty:

Look at the code for ControlCommand(..."GetSelected"...) in script_win.cpp around line 1370 or so.

else

vResult = (int)nStart;

SetFuncErrorCode(1);

if(pBuffer)

free(pBuffer);

break;

Adding the line in bold causes ControlCommand(..."GetSelected"...) to return the character index (in addition to settting @error) if no text is selected in the edit control. This index can be used to computer the column number.

Better yet would be to use character index with EM_LINEFROMCHAR

Here's some untested C-like psuedo-implementation:

// ...

UINT    nLen,nStart,nOriginal;
char    *pBuffer = NULL;

SendMessage(m_ControlSearchHWND,EM_GETSEL,(WPARAM)&nStart,(LPARAM)&nEnd);
// nStart now equals the character index
nOriginal = nStart;

//Check the row corresponding to the character index
//  Decrement the character index until the row changes
//  Then you will know the index of the first character on the row
//  The difference between the new char index and the original is the COLUMN!

vResult = (int)SendMessage(m_ControlSearchHWND,EM_LINELENGTH,(WPARAM)&nStart,0);
while (nStart > 1 && vResult == (int)SendMessage(m_ControlSearchHWND,EM_LINELENGTH,(WPARAM)&nStart,0))
{
    nStart--;
}
vResult = nStart - nOriginal + 1;

//...

Use Mozilla | Take a look at My Disorganized AutoIt stuff | Very very old: AutoBuilder 11 Jan 2005 prototype I need to update my sig!

Share this post


Link to post
Share on other sites

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
Sign in to follow this  
Followers 0