IsMouseIn, IsMouseInDlg

Def SetCursorPos(2)!"User32","SetCursorPos"
Windowstyle 10
WindowTitle "Beispiel für GetwindowRect, GetCursorPos, ScreenToClient, WindowfromPoint und ihre Anwendung"
CLS
WindowZ(%hwnd,-1)
Var pic1&=Create("hNewPic", 100, 100, RGB(0,0,255))
Var pic2&=Create("hNewPic", 100, 100, RGB(255,0,0))
Var picbt&=Create("PicButton",%hwnd,0,(width(%hwnd)-100)/2,(height(%hwnd)-100)/2,100,100)
Settext picbt&,"Bildbutton zur Demonstration eines Hoverbuttons mit HandleHover"
Var text&=Create("Text",%hwnd,"",0,0,width(%hwnd),16)
Var pos&=Create("Text",%hwnd,"",0,height(%hwnd)-16,width(%hwnd),16)
Var Dlg&=Create("Text",%hwnd,"",0,16,width(%hwnd),16)
Line width(%hwnd)/2,0 - width(%hwnd)/2,height(%hwnd)
Usermessages 16

WhileNot (%umessage=16) or iskey(27)

    Waitinput 30
    Sendmessage(picbt&,$F7 | 247,0,If(HandleHover()=picbt&,pic1&,pic2&))'Hover-Button mit HandleHover(), Alternativ die Verwendung von IsMouseHover()
    Settext text&,IF(IsMouseInDg(%hwnd, 0, 0, width(%hwnd)/2, height(%hwnd))=1,"Maus auf linker Seite",IF(IsMouseInDg(%hwnd, width(%hwnd)/2, 0, width(%hwnd), height(%hwnd))=1,"Maus auf rechter Seite","Maus außerhalb des Client_Bereichs von hWnd"))
    Settext pos&, "Position von %hwnd (global): "+Str$(WindowRect(%hwnd,"X1"))+"x"+Str$(WindowRect(%hwnd,"Y1"))
    Settext Dlg&, "Maus über den Handle '"+Str$(HandleHover())+"' mit dem Titel '"+Mid$(Gettext$(HandleHover()),1,45)+"...'"
    Settext %hwnd, "CursorPosGlobal: "+Str$(CursorPos("X1"))+"x"+Str$(CursorPos("Y1"))+" - CursorPosLokal auf hWnd: "+Str$(CursorPos("X1",%hwnd))+"x"+Str$(CursorPos("Y1",%hwnd))

EndWhile

deleteobject pic1&
deleteobject pic2&
end

Proc IsMouseHover

    Parameters hdl&
    Return Between(CursorPos("X1"), WindowRect(hdl&,"X1"), WindowRect(hdl&,"X2"), CursorPos("Y1"), WindowRect(hdl&,"Y1"), WindowRect(hdl&,"Y2"))

EndProc

Proc IsMouseIn

    Parameters x1%,y1%,x2%,y2%
    Return Between(CursorPos("X1"), x1%, x2%, CursorPos("Y1"), y1%, y2%)

EndProc

Proc IsMouseInDg

    Parameters hdl&,x1%,y1%,x2%,y2%
    Return Between(CursorPos("X1",hdl&), x1%, x2%, CursorPos("Y1",hdl&), y1%, y2%)

EndProc

Proc WindowSize

    Parameters hdl&,x%,y%
    SetWindowPos hdl& = WindowRect(hdl&,"X1"),WindowRect(hdl&,"Y1") - x%,y%

EndProc

Proc WindowZ

    Parameters hdl&, modus%
    'Modus =  0 : TOP| 1 : BOTTOM | -1 : TOP-MOST | -2 : BOTTOM-MOST
    SetWindowPos hdl& = WindowRect(hdl&,"X1"),WindowRect(hdl&,"Y1") - WindowRect(hdl&,"Breite"),WindowRect(hdl&,"Höhe"); modus%

EndProc

Proc HandleHover

    Declare mpos#
    Dim mpos#,8
    External("user32","GetCursorPos",mpos#)
    Var hdl&=External("USER32","WindowFromPoint",long(mpos#,0),long(mpos#,4))
    Dispose mpos#
    Return hdl&

EndProc

Proc HandleHoverPos

    Parameters x&,y&
    Return External("USER32","WindowFromPoint",x&,y&)

EndProc

Proc CursorPos

    Parameters Modus$
    Modus$=Lower$(Modus$)
    Declare x%, mpos#
    Dim mpos#,8
    External("user32","GetCursorPos",mpos#)
    Case @&(2)<>0 : External("USER32","ScreenToClient",@&(2),mpos#)
    Case Modus$="x1" : x%=long(mpos#,0)
    Case Modus$="y1" : x%=long(mpos#,4)
    Case Modus$="x2" : x%=IF(@&(2)<>0,WindowRect(@&(2),"Breite"),%maxx)-long(mpos#,0)
    Case Modus$="y2" : x%=IF(@&(2)<>02,WindowRect(@&(2),"Höhe"),%maxy)-long(mpos#,4)
    Dispose mpos#
    Return x%

EndProc

Proc WindowRect

    Parameters hdl&,Modus$
    Modus$=Lower$(Modus$)
    Declare x%, b#
    Dim b#,16
    External("USER32", "GetWindowRect",hdl&,b#)
    Case @&(3)<>0 : External("USER32","ScreenToClient",@&(3),b#) : External("USER32","ScreenToClient",@&(3),b#+8)
    Case Modus$="breite" : x%=Long(b#,8)-Long(b#,0)
    Case Modus$="höhe" : x%=Long(b#,12)-Long(b#,4)
    Case Modus$="x1" : x%=Long(b#,0)
    Case Modus$="y1" : x%=Long(b#,4)
    Case Modus$="x2" : x%=Long(b#,8)
    Case Modus$="y2" : x%=Long(b#,12)
    Dispose b#
    Return x%

EndProc

Proc Workarea

    Parameters Modus$
    modus$=lower$(modus$)
    Declare Rect#,x%
    Dim Rect#,16
    External("User32","SystemParametersInfoA",48,0,Rect#,0)
    case modus$="x1" : x%=Long(Rect#,0)
    case modus$="y1" : x%=Long(Rect#,4)
    case modus$="x2" : x%=Long(Rect#,8)
    case modus$="y2" : x%=Long(Rect#,12)
    Dispose Rect#
    Return x%

EndProc