AutoHotkey Community

It is currently May 27th, 2012, 10:58 am

All times are UTC [ DST ]




Post new topic Reply to topic  [ 5 posts ] 
Author Message
PostPosted: February 2nd, 2007, 8:46 pm 
Offline

Joined: January 1st, 2005, 11:54 am
Posts: 75
Is there any way to identify an edit control?

I want to copy content of editable controls by sending CTRL-SHIFT-{left}. A lot of programs use that for navigation when a non-editable control has the focus. I would like to identify edit controls to prevent side-effects by sending this hotkey to the wrong control.

Thanks
Boskoop


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: February 2nd, 2007, 10:38 pm 
Online
User avatar

Joined: December 26th, 2005, 4:40 pm
Posts: 8776
Run the following code - move the mouse pointer to the desired control and press F2. IsEdit() will ascertain whether the control's contents are editable.

Code:
F2::
MouseGetPos,,,,CtrlID, 2
Result := IsEdit( CtrlID )
IfEqual, Result,-1, Msgbox, Not an Edit Control
IfEqual, Result, 0, Msgbox, Edit Control (Readonly)
IfEqual, Result, 1, Msgbox, Edit Control
Return

IsEdit( CtrlID=0x0 ) {
 SendMessage, 0x00BA, 0, 0,, ahk_id %CtrlID%      ; EM_GETLINECOUNT = 0x00BA
 If (errorLevel > 0) {
     ControlGet, Style, Style,,, ahk_id %CtrlID%
     if (Style & 0x800)                           ; ES_READONLY = 0x800
          Return 0   
    }
 else
    Return -1
Return 1
}


About IsEdit()

You have to pass the handle of a control and the function tries to fetch the line count of the control. SendMessage should probably fail if the control is not an EDIT or RichEDIT control. Next step involves ascertainment of whether the Edit control is Readonly or not.

IsEdit() shall return -1 for non-Edit controls, 0 for a readonly Edit control, and 1 for an editable Edit control.

:)

PS: I have not tested it much except on Wordpad, Metapad, IE/WE address bar, Startmenu Run, Calculator, AHK GUI with a readonly Edit control.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: February 3rd, 2007, 12:16 am 
Offline

Joined: January 1st, 2005, 11:54 am
Posts: 75
Thank you very much for your prompt and original answer.

I tried it- an unfortunately it didn't work with the first three controls (Textpad's and Word's edit window, Opera's adress line). It works fine with other controls, but I'm afraid this isn't reliable enough to be of real use.

I liked the idea of using SendMessage and went through the message lists. WM_cut or WM_paste seemed to be good candidates- but they don't return error codes. Until now I couldn't come up with something else specific for edit controls.

Thanks again
Boskoop


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: February 3rd, 2007, 1:55 am 
Online
User avatar

Joined: December 26th, 2005, 4:40 pm
Posts: 8776
Boskoop wrote:
It works fine with other controls, but I'm afraid this isn't reliable enough to be of real use.


EM_GETLINECOUNT will work only with EDIT / RICHEDIT Control.
I do not have Word/Opera installed, but downloaded and checked with Textpad and yes, it does not work :(. The control shows as HSEditor1 in Spy utility. The text in the control is not seen by Spy.

So I understand that it is not a regular EDIT / RICHEDIT Control.
Allow me sometime for research.

Thanks .. :)


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: February 9th, 2007, 8:25 pm 
Offline

Joined: January 1st, 2005, 11:54 am
Posts: 75
Thanks for helping.

I use some sort of workaround now, but I'm not really satisfied. It still has side effects. Any better idea is appreciated.


Code:
F12::
if (CheckEditable()="1")
   msgbox, Copy&Paste works
else
   msgbox, Sorry, no Copy&Paste in this control
return

CheckEditable()
; Checks if an control is editable by checking if its possible
; to paste and cut content from the control
{
   Clipboard=
   send, |{left}+{right}
   send ^x
   If (clipboard = "" )
      Editable := 0
   Else
      Editable := 1
   If (Editable=0)
      send, +{left}
   return Editable
}


Boskoop


Report this post
Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 5 posts ] 

All times are UTC [ DST ]


Who is online

Users browsing this forum: BrandonHotkey, Exabot [Bot], HotkeyStick, Yahoo [Bot] and 14 guests


You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Powered by phpBB® Forum Software © phpBB Group