Wird ein Control überlappt? [VB.NET]

NRFi

Erfahrenes Mitglied
Hallo auch,

ich habe ein Problem mit einer Funktion, die nachguckt, ob ein Control evtl. von einem anderen Fenster überdeckt wird. :rolleyes:

Die Funktion sieht so aus:

Code:
Public Function IsOverlappedWnd(ByRef hwnd As IntPtr) As Boolean
        Dim CurRect As Rectangle
        Dim hWndTest As IntPtr
        Dim isWnd As Boolean = True

        mytestweiseeingebautescontrolanstelleGetWindowPointOderÄhnlich.RectangleToScreen(CurRect)

        hWndTest = WindowFromPoint(CurRect.Left, CurRect.Top)
        isWnd = isWnd And (hWndTest.ToInt32 = hwnd.ToInt32)

        hWndTest = WindowFromPoint(CurRect.Left, CurRect.Bottom)
        isWnd = isWnd And (hWndTest.ToInt32 = hwnd.ToInt32)

        hWndTest = WindowFromPoint(CurRect.Right, CurRect.Top)
        isWnd = isWnd And (hWndTest.ToInt32 = hwnd.ToInt32)

        hWndTest = WindowFromPoint(CurRect.Right, CurRect.Bottom - 1)
        isWnd = isWnd And (hWndTest.ToInt32 = hwnd.ToInt32)

        Return Not isWnd

    End Function

Mit VB 6 klappte es immer (seitdem leicht verändert).
Also ich habe den hwnd(handle) des Controls und übergebe es dieser Funktion. Diese prüft, ob an irgendeiner Ecke des Controls ein Fenster darüber ist. Aber der hwnd, der von WindowFromPoint zurückgegeben wird, ist ein anderer. ich weiß nicht, woran es liegt. :rolleyes:

Ich wäre über schnelle Hilfe dankbar.

Gruß, ich ;-]
 
die geschichte ging nicht, weil getwindowrect zwar x und y korrekt ausgibt, aber irgendwie was mit right und bottom falsch macht. mit einem kleinen workarround ging es dann.
das -1 war dann auch sehr wichtig hab ich dann gemerkt... :google:

Code:
        Dim CurRect As Rectangle
        Dim hWndTest As IntPtr
        Dim isWnd As Boolean = True

        GetWindowRect(hwnd.ToInt32, CurRect)

        hWndTest = WindowFromPoint(CurRect.Left, CurRect.Top)
        isWnd = isWnd And (hWndTest.ToInt32 = hwnd.ToInt32)

        hWndTest = WindowFromPoint(CurRect.Left, CurRect.Top + MyCtrl.Height - 1)
        isWnd = isWnd And (hWndTest.ToInt32 = hwnd.ToInt32)

        hWndTest = WindowFromPoint(CurRect.Left + MyCtrl.Width - 1, CurRect.Top)
        isWnd = isWnd And (hWndTest.ToInt32 = hwnd.ToInt32)

        hWndTest = WindowFromPoint(CurRect.Left + MyCtrl.Width - 1, CurRect.Top + MyCtrl.Height - 1)
        isWnd = isWnd And (hWndTest.ToInt32 = hwnd.ToInt32)
 

Neue Beiträge

Zurück