| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1271 人关注过本帖
标题:API getwindowrect 的使用问题
只看楼主 加入收藏
dafeixia88
Rank: 2
等 级:论坛游民
帖 子:14
专家分:42
注 册:2010-2-23
收藏
 问题点数:0 回复次数:2 
API getwindowrect 的使用问题
我做了一个小程序,但不能正确使用getwindowrect函数,我是新手,万望各位高手们指教,谢谢
主程序:
Public Class Form1
    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

    End Sub

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim aaa As New task
        Dim bbb As taskbar
        Dim ccc As Collection
        ccc = aaa.gainedlist
        ListBox1.Items.Clear()
        For Each bbb In ccc
            ListBox1.Items.Add(bbb.hwn.ToString & "-" & bbb.name)
        Next
    End Sub

    Private Sub ListBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ListBox1.SelectedIndexChanged
        Label1.Text = ListBox1.SelectedItem.ToString.Split("-")(0)
    End Sub

    Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
        If ListBox1.SelectedIndex = -1 Then Exit Sub
        Dim aaa As New chuangkou
        aaa.hwn = ListBox1.SelectedItem.ToString.Split("-")(0)
        aaa.huoqu()
        Label1.Text = aaa.chuzhuo.Bottom
        aaa = Nothing
    End Sub
End Class
类型 chuangkou
Public Class chuangkou
    '用于对窗口进行操作的类型
    Public hwn As IntPtr
    Public chuzhuo As Rectangle
    Private Declare Function GetWindowRect Lib "user32" (ByRef hwnd As IntPtr, ByRef lpRect As Rectangle) As Long
    Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
    Private Function gainzhuo() As Boolean

        If GetWindowRect(hwn, chuzhuo) <> 0 Then '此处出现问题,获取的坐座总是0,不论是left/top/bottom or right ,请各位指教!!!!

            MsgBox("窗口信息获取完毕")
        Else
            MsgBox("获取窗口座标失败!!!")
        End If
        Return True
    End Function
    Public Function huoqu() As Boolean
        gainzhuo()
        Return True
    End Function
End Class
类型TASK
Public Class task
    Private Declare Function GetWindowLongPtr Lib "user32" Alias "GetWindowLongA" (ByVal hwnd As IntPtr, ByVal nIndex As Int32) As IntPtr
    Private Declare Function GetParent Lib "user32" (ByVal hwnd As IntPtr) As IntPtr
    Private Declare Function GetWindow Lib "user32" (ByVal hwnd As IntPtr, ByVal wCmd As Int32) As IntPtr
    Private Declare Function IsWindowVisible Lib "user32" (ByVal hwnd As IntPtr) As IntPtr
    Private Declare Function GetDesktopWindow Lib "user32" () As IntPtr
    Private Declare Function GetWindowText Lib "user32" Alias "GetWindowTextA" (ByVal hwnd As IntPtr, ByVal lpString As String, ByVal cch As Integer) As Int16
    Private Declare Function GetWindowTextLength Lib "user32" Alias "GetWindowTextLengthA" (ByVal hwnd As IntPtr) As Int32

    Public Const GW_OWNER = 4
    Public Const GWL_EXSTYLE = (-20)
    Public Const GW_CHILD = 5
    Public Const WS_EX_TOOLWINDOW = &H80
    Public Const WS_EX_APPWINDOW = &H40000
    Public Const GW_HWNDFIRST = 0
    Public Const GW_HWNDNEXT = 2
    Private taskli As Collection
    Public Function gainedlist() As Collection
        Return taskli
    End Function
    Public Sub New()
        '类初始化
        Dim aaa As IntPtr
        Dim bbb As IntPtr
        Dim ccc As taskbar
        Dim eee As Long
        Dim ddd As String
        Dim fff As Integer
        fff = 0
        taskli = New Collection
        aaa = GetDesktopWindow
        bbb = GetWindow(aaa, GW_CHILD)
        bbb = GetWindow(bbb, GW_HWNDFIRST)
        Do
            If bbb = 0 Then Exit Do
            If IsTaskbarApp(bbb) Then
                fff = fff + 1
                eee = GetWindowTextLength(bbb)
                ddd = Space$(eee + 1)
                eee = GetWindowText(bbb, ddd, eee + 1)
                ccc = New taskbar
                ccc.hwn = bbb
                ccc.name = ddd
                taskli.Add(ccc, ccc.name & ccc.hwn.ToString)
            End If
            bbb = GetWindow(bbb, GW_HWNDNEXT)
        Loop
    End Sub
    '判断窗口是否为任务应用函数,参数为窗口句柄
    Public Function IsTaskbarApp(ByVal hwnd As IntPtr) As Boolean
        Dim ExtendStyle As Long
        Dim hParent As IntPtr
        Dim BoolIsTaskBarApp As Boolean
        ExtendStyle = GetWindowLongPtr(hwnd, GWL_EXSTYLE)
        hParent = GetParent(hwnd)
        BoolIsTaskBarApp = CBool((IsWindowVisible(hwnd) <> 0) And _
                          (GetWindow(hwnd, GW_OWNER) = 0) And _
                          (hParent = 0 Or hParent = GetDesktopWindow()))
        If (ExtendStyle And WS_EX_TOOLWINDOW) Then BoolIsTaskBarApp = False
        If (ExtendStyle And WS_EX_APPWINDOW) Then BoolIsTaskBarApp = True
        IsTaskbarApp = BoolIsTaskBarApp
    End Function
End Class
搜索更多相关主题的帖子: API 
2010-02-23 17:57
dafeixia88
Rank: 2
等 级:论坛游民
帖 子:14
专家分:42
注 册:2010-2-23
收藏
得分:0 
问题已解决,谢谢大家!!!!!
2010-02-23 22:07
好学
Rank: 16Rank: 16Rank: 16Rank: 16
等 级:版主
帖 子:622
专家分:318
注 册:2004-5-4
收藏
得分:0 
一直觉得VB语法是最美的语法,宁愿打End Function也不愿意打那个花括号
2010-02-23 22:13
快速回复:API getwindowrect 的使用问题
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.033438 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved