Results 1 to 4 of 4

Thread: WindowFromPoint

  1. #1

    Thread Starter
    Fanatic Member alexandros's Avatar
    Join Date
    Oct 2002
    Location
    Milky Way Galaxy
    Posts
    694

    WindowFromPoint

    hello i used this vb6 code in order to get the handle of any window from a point.
    VB Code:
    1. Dim myhwnd As Long
    2.     Dim typPt As POINTAPI
    3.     Dim hwnd As Long
    4.      typPt.x = MY_X
    5.      typPt.y = MY_Y
    6.     myhwnd = WindowFromPoint(typPt.x, typPt.y)
    now the problem is that this code seems not to work with vb.net.
    I could get a handle to any window even if it did not belong to the form.
    Now the following code can find the handle a control that does only exist on the form ,i think. Is there a way to get a handle to any control of any windows window ?

    thanks !


    VB Code:
    1. Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    2.         Dim pt As System.Drawing.Point
    3.         pt.X = 500
    4.         pt.Y = 100
    5.         Dim co As Control
    6.         co = Me.GetChildAtPoint(pt)
    7.         If Not co Is Nothing Then
    8.             MsgBox(co.Name)
    9.         Else
    10.             MsgBox("NO CONTROL FOUND", MsgBoxStyle.ApplicationModal)
    11.         End If
    12.  
    13.  
    14.     End Sub

  2. #2
    I wonder how many charact
    Join Date
    Feb 2001
    Location
    Savage, MN, USA
    Posts
    3,704
    You will only be able to retrieve controls (windows or others) that are part of your application using those functions.

    However, you can, just like in your vb6 code, use your WindowFromPoint function. In VB.NET, you need to change any Long variables to Integers, because Integers are 4 bytes long in .Net.

    VB Code:
    1. Declare Function WindowFromPoint Lib "user32" (ByVal xPoint As Integer, ByVal yPoint As Integer) As Integer
    2.  
    3.  
    4.  Private Structure typPT 'public or private, up to you
    5.         Public x As Integer
    6.         Public y As Integer
    7.  End Structure
    8.  
    9.  Private myhwnd As Integer
    10.   typPt.x = MY_X
    11.   typPt.y = MY_Y
    12.   myhwnd = WindowFromPoint(typPt.x, typPt.y)
    Last edited by nemaroller; Jul 10th, 2004 at 07:24 AM.

  3. #3

    Thread Starter
    Fanatic Member alexandros's Avatar
    Join Date
    Oct 2002
    Location
    Milky Way Galaxy
    Posts
    694
    did microsoft restrict this function for security reasons ?

  4. #4
    I wonder how many charact
    Join Date
    Feb 2001
    Location
    Savage, MN, USA
    Posts
    3,704
    Maybe, maybe not... I think it has more to do with how the .Net framework is designed to exist on a system, which, like Java, is designed to operate mostly system-independent. Low-level calls are not part of the framework, since they are operating system dependent.

    So while you can call on Win32 API functions like WindowFromPoint on a Windows box, the .Net framework itself can run on a Linux or Unix box, which obviously has no support for WindowFromPoint.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width