GetForegroundWindow为什么总是返回一个很大的数字?

解决方案 »

  1.   

    GetForegroundWindow返回的是窗口句柄
    窗口句柄的低16位是一个句柄表(user32!gSharedInfo+4中有其地址)的索引,高16位是特征码,以避免其他代码误用,因此把它当整数看比较大
      

  2.   

    Private Declare Function GetForegroundWindow Lib "user32" () As Long
    【操作系统】
    Win9X:Yes
    WinNT:Yes
    【说明】
      获得前台窗口的句柄。这里的“前台窗口”是指前台应用程序的活动窗口 
    【返回值】
      Long,前台窗口的句柄 
    【其它】
      windows nt支持多个桌面,它们相互间是独立的。每个桌面都有自己的前台窗口
    【参数表】
      

  3.   

    'Example Name:Window Draw
    Private Declare Function GetForegroundWindow Lib "user32" () As Long
    Private Declare Function Ellipse Lib "gdi32" (ByVal hdc As Long, ByVal X1 As Long, ByVal Y1 As Long, ByVal X2 As Long, ByVal Y2 As Long) As Long
    Private Declare Function GetDC Lib "user32" (ByVal hwnd As Long) As Long
    Private Sub Form_Activate()
        'KPD-Team 1998
        'URL: http://www.allapi.net/
        'E-Mail: [email protected]
        Dim Ret As Long
        Do
            'Get the handle of the foreground window
            Ret = GetForegroundWindow()
            'Get the foreground window's device context
            Ret = GetDC(Ret)
            'draw an ellipse
            Ellipse Ret, 0, 0, 200, 200
            DoEvents
        Loop
    End Sub