当打开一个窗体时,希望窗体根据鼠标的位置出现在相应地方.

解决方案 »

  1.   

    Private Type POINTAPI
        x As Long
        y As Long
    End Type
    Private Declare Function GetCursorPos Lib "user32" (lpPoint As POINTAPI) As Long
    Private Declare Function MoveWindow Lib "user32" (ByVal hwnd As Long, ByVal x As Long, ByVal y As Long, ByVal nWidth As Long, ByVal nHeight As Long, ByVal bRepaint As Long) As Long
    Private Sub Command1_Click()
    Dim t As POINTAPI
    GetCursorPos t
    MoveWindow Me.hwnd, t.x, t.y, Me.Width / Screen.TwipsPerPixelX, Me.Height / Screen.TwipsPerPixelY, 1
    End Sub本例中窗体的ScaleMode属性为1。
      

  2.   

    Private Type POINTAPI
        x As Long
        y As Long
    End Type
    Private Declare Function GetCursorPos Lib "user32" (lpPoint As POINTAPI) As LongDim t As POINTAPI
    GetCursorPos t
    Debug.? t.x
    Debug.? t.y
      

  3.   

    GetCursorPos VB声明 
    Declare Function GetCursorPos Lib "user32" Alias "GetCursorPos" (lpPoint As POINTAPI) As Long 
    说明 
    获取鼠标指针的当前位置 
    返回值 
    Long,非零表示成功,零表示失败。会设置GetLastError 
    参数表 
    参数 类型及说明 
    lpPoint POINTAPI,随同指针在屏幕像素坐标中的位置载入的一个结构 
      

  4.   

    Private Type POINTAPI
        X As Long
        Y As Long
    End Type
    Private Declare Function GetCursorPos Lib "user32" (lpPoint As POINTAPI) As LongPrivate Sub Form_Load()
    Dim p As POINTAPI
    GetCursorPos p
    Me.Move p.X * Screen.TwipsPerPixelX, p.Y * Screen.TwipsPerPixelY
    End Sub
      

  5.   


    Private Type POINTAPI
        X As Long
        Y As Long
    End Type【VB声明】
      Private Declare Function GetCursorPos Lib "user32" Alias "GetCursorPos" (lpPoint As POINTAPI) As Long【说明】
      获取鼠标指针的当前位置 【返回值】
      Long,非零表示成功,零表示失败。会设置GetLastError 【参数表】
      lpPoint --------  POINTAPI,随同指针在屏幕像素坐标中的位置载入的一个结构