精华区 [关闭][返回]

当前位置:网易精华区>>讨论区精华>>编程开发>>● VB和Basic>>〓〓..API 函数使用..〓〓>>窗体和显示相关>>在vb 中得到 windows 任务栏的高度的方法

主题:在vb 中得到 windows 任务栏的高度的方法
发信人: e_jie()
整理人: winsy(2003-03-05 15:56:15), 站内信件

 Private Declare Function GetWindowRect& Lib "user32" ( _
        ByVal hwnd As Long, _
              lpRect As RECT)

Private Type RECT
       Left                As Long
       Top                 As Long
       Right               As Long
       Bottom              As Long
End Type

Private Declare Function FindWindow& Lib "user32" Alias "FindWindowA" ( _
        ByVal lpClassName As String, _
        ByVal lpWindowName As String)

 
Dim hwnd5 As Long
Dim winrect As RECT

Private Sub Command1_Click()
hwnd5 = FindWindow("shell_traywnd", "")
GetWindowRect hwnd5, winrect
'左 右 上 下 坐标
Debug.Print winrect.Left, winrect.Right, winrect.Top, winrect.Bottom
'宽和高
Debug.Print winrect.Right - winrect.Left, winrect.Bottom - winrect.Top
End Sub

要注意的是
vb 中缺省单位为twips(缇) ,你得到的数字单位为pixel(像素)  
转换方法:
twips-->pixel    缇\screen.TwipsPerPixelX
pixel---->twips  screen.TwipsPerPixelX*像素 

此外在windows中坐标点为负数是正常的,它代表可视区域之外的坐标,你试着移动任务栏,
不同的位置会有不同的-2值



----
 网络任我飞

[关闭][返回]