Jump to content

Sky Slate Blueberry Blackcurrant Watermelon Strawberry Orange Banana Apple Emerald Chocolate
Photo

Check if mouse is on visible text area of edit



  • Please log in to reply
5 replies to this topic
Masonjar13
  • Members
  • 1517 posts
  • Last active:
  • Joined: 16 Sep 2012

I'm trying to check if the mouse is on the visible text area of an edit, that is, it will return false if it's on a scroll bar. This is my progress thus far.
 

onEditClient(){
    editRect:=EM_getRect("ahk_id " dlhwnd,"Edit1")
    mouseGetPos,mx,my
    if(mx>editRect.x1 && mx<editRect.x2)
        if(my>editRect.y1 && my<editRect.y2)
            return 1
    return 0
}
EM_getRect(winTitle,control="",winText="",excludeTitle=""){
    static EM_GETRECT:=0xB2
    varSetCapacity(rect,16,0)
    sendMessage,EM_GETRECT,0,&rect,% control,% winTitle,% winText,% excludeTitle
    return {x1: numGet(rect,0),y1: numGet(rect,4),x2: numGet(rect,8),y2: numGet(rect,12)}
}

dlhwnd is a global window ID. It does retrieve the formatting rect of the edit, but I don't know how to translate those to be relative to the window/client/screen to compare to the mouse coords. So the question would be: how do I translate the formatting rect of an edit to be compared to the mouse coords? Alternatively, how would I translate mouse coords to be compared to the formatting rect of an edit? Or is there a better solution not dependant on coords?


OS: Windows 7 Ultimate / Windows 8.1 Pro | Editor: Notepad++


space
  • Members
  • 520 posts
  • Last active:
  • Joined: 12 Aug 2014
You need to take into account the TOP LEFT corner of the Edit control + the width and height of the control?

- CoordMode, Mouse, Window
- Edit1 position within Gui: 100,100 (assuming you know this)
- Edit1 is say w200 h100
- So if mousepos (x > 100 and < 100+200) and (y > 100 and < 100+100)
- plus check for the scrollbar

?

Jack Dunning
  • Members
  • 217 posts
  • Last active: Nov 11 2015 08:40 PM
  • Joined: 08 Apr 2013

Oops! I don't think the option I was contemplating would work for your situation.


I currently do a regular blog for AutoHotkey beginners and have posted a number of AutoHotkey help pages at ComputorEdge.com. As I learn, I pass it on.

 

AutoHotkey scripts and apps for beginners and more ideas.


noname
  • Members
  • 650 posts
  • Last active:
  • Joined: 12 Nov 2011
✓  Best Answer

 

Or is there a better solution not dependant on coords?

 

Checking the shape of the mousepointer maybe ?


winXP  and ahk unicode


Jack Dunning
  • Members
  • 217 posts
  • Last active: Nov 11 2015 08:40 PM
  • Joined: 08 Apr 2013

While this doesn't solve the scrollbar problem, using the next two parameters in the MouseGetPos command should help to narrow down the possibilities. 

MouseGetPos, mx, my, id, control

The variables id and control should tell you when you are over the Edit1 box. Then it's a matter of knowing the location of a scrollbar for comparison—when it exists.


I currently do a regular blog for AutoHotkey beginners and have posted a number of AutoHotkey help pages at ComputorEdge.com. As I learn, I pass it on.

 

AutoHotkey scripts and apps for beginners and more ideas.


Masonjar13
  • Members
  • 1517 posts
  • Last active:
  • Joined: 16 Sep 2012

Checking the shape of the mousepointer maybe ?

Good idea; it implemented well and is much simpler.
 

cursorOnEdit(hwnd,controlText){
    mouseGetPos,,,cw,cc
    if(cw=hwnd && cc=controlText && a_cursor="IBeam")
        return 1
    return 0
}

OS: Windows 7 Ultimate / Windows 8.1 Pro | Editor: Notepad++