msdn里面关于GetWindowRect的说明如下:
GetWindowRect
The GetWindowRect function retrieves the dimensions of the bounding rectangle of the specified window. The dimensions are given in screen coordinates that are relative to the upper-left corner of the screen. BOOL GetWindowRect(
HWND hWnd, // handle to window
LPRECT lpRect // address of structure for window coordinates
);
Parameters:
hWnd
Handle to the window.
lpRect
Pointer to aRECT structure that receives the screen coordinates of the upper-left and lower-right corners of the window.
Return Values
If the function succeeds, the return value is nonzero.If the function fails, the return value is zero. To get extended error information, callGetLastError. 我这里想请问的是,我想得到lpRect这个地址里面的RECT这个数据类型的四个Left、Top、Right、Bottom值,我怎么定义一个类似指针的变量来取出这几个参数!各位高手能否指点一下,本人由于初次用VB,很不熟,谢谢!最好写一下必要的代码
注:RECT的数据类型在API里面有,只要声明一下就行了
GetWindowRect
The GetWindowRect function retrieves the dimensions of the bounding rectangle of the specified window. The dimensions are given in screen coordinates that are relative to the upper-left corner of the screen. BOOL GetWindowRect(
HWND hWnd, // handle to window
LPRECT lpRect // address of structure for window coordinates
);
Parameters:
hWnd
Handle to the window.
lpRect
Pointer to aRECT structure that receives the screen coordinates of the upper-left and lower-right corners of the window.
Return Values
If the function succeeds, the return value is nonzero.If the function fails, the return value is zero. To get extended error information, callGetLastError. 我这里想请问的是,我想得到lpRect这个地址里面的RECT这个数据类型的四个Left、Top、Right、Bottom值,我怎么定义一个类似指针的变量来取出这几个参数!各位高手能否指点一下,本人由于初次用VB,很不熟,谢谢!最好写一下必要的代码
注:RECT的数据类型在API里面有,只要声明一下就行了
解决方案 »
- 请问如何实现最小化到托盘的动画?
- 求各位高手帮忙提供控件
- 远程发送数据问题?VB+SQL server 2000
- ODBC中如何保存SQL SERVER的密碼
- 我在用wininet api中的FtpFindFirstFile(hConnection, "/*.*", pData, 0, 0)取得某目录下的某文件或目录的属性的问题
- 怎样解除win2k的锁定
- 大家帮忙解释一下,这是怎么回事。
- 一个让我伤透心的问题,请各位大哥大姐多多赐教~
- 稍有难度的题目哟,请问怎么把vb中的mdi窗体的标题栏去掉呀,急用,能解决吗?马上给分了.
- 他们发分太小气,我来大的,每人50分,前6名有效
- 一個QQ網友的說明文字,有意思:)
- winsock问题及API
'a Form, called 'Form1'
'a Picture Box, called 'ExplButton' (50x50 pixels)
'a Picture Box with an icon in it, called 'picIcon'
'two timers (Timer1 and Timer2), both with interval 100
'Button, called 'Command1'
'In general section
Private Type RECT
Left As Long
Top As Long
Right As Long
Bottom As Long
End Type
Private Type POINTAPI
X As Long
Y As Long
End Type'Declare the API-Functions
Private Declare Function GetCursorPos Lib "user32" (lpPoint As POINTAPI) As Long
Private Declare Function SetCursorPos Lib "user32" (ByVal X As Long, ByVal Y As Long) As Long
Private Declare Function GetWindowRect Lib "user32" (ByVal hwnd As Long, lpRect As RECT) As Long
Sub DrawButton(Pushed As Boolean)
Dim Clr1 As Long, Clr2 As Long
If Pushed = True Then
'If Pushed=True then clr1=Dark Gray
Clr1 = &H808080
'If Pushed=True then clr1=White
Clr2 = &HFFFFFF
ElseIf Pushed = False Then
'If Pushed=True then clr1=White
Clr1 = &HFFFFFF
'If Pushed=True then clr1=Dark Gray
Clr2 = &H808080
End If With Form1.ExplButton
' Draw the button
Form1.ExplButton.Line (0, 0)-(.ScaleWidth, 0), Clr1
Form1.ExplButton.Line (0, 0)-(0, .ScaleHeight), Clr1
Form1.ExplButton.Line (.ScaleWidth - 1, .ScaleHeight - 1)-(.ScaleWidth - 1, 0), Clr2
Form1.ExplButton.Line (.ScaleWidth - 1, .ScaleHeight - 1)-(0, .ScaleHeight - 1), Clr2
End With
End Sub
Private Sub Command1_Click()
Dim Rec As RECT
'Get Left, Right, Top and Bottom of Form1
GetWindowRect Form1.hwnd, Rec
'Set Cursor position on X
SetCursorPos Rec.Right - 15, Rec.Top + 15
End Sub
Private Sub ExplButton_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
DrawButton True
End Sub
Private Sub ExplButton_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
DrawButton False
End Sub
Private Sub ExplButton_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
DrawButton False
End Sub
Private Sub Form_Load()
'KPD-Team 1998
'URL: http://www.allapi.net/
'E-Mail: [email protected] Dim Stretched As Boolean
'picIcon.Visible = False
'API uses pixels
picIcon.ScaleMode = vbPixels
'No border
ExplButton.BorderStyle = 0
'API uses pixels
ExplButton.ScaleMode = vbPixels
'Set graphic mode te 'persistent graphic'
ExplButton.AutoRedraw = True
'API uses pixels
Me.ScaleMode = vbPixels
'Set the button's caption
Command1.Caption = "Set Mousecursor on X" ' If you set Stretched to true then stretch the icon to te Height and Width of the button
' If Stretched=False, the icon will be centered
Stretched = False If Stretched = True Then
' Stretch the Icon
ExplButton.PaintPicture picIcon.Picture, 1, 1, ExplButton.ScaleWidth - 2, ExplButton.ScaleHeight - 2
ElseIf Stretched = False Then
' Center the picture of the icon
ExplButton.PaintPicture picIcon.Picture, (ExplButton.ScaleWidth - picIcon.ScaleWidth) / 2, (ExplButton.ScaleHeight - picIcon.ScaleHeight) / 2
End If
' Set icon as picture
ExplButton.Picture = ExplButton.Image
End Sub
Private Sub Timer1_Timer()
Dim Rec As RECT, Point As POINTAPI
' Get Left, Right, Top and Bottom of Form1
GetWindowRect Me.hwnd, Rec
' Get the position of the cursor
GetCursorPos Point ' If the cursor is located above the form then
If Point.X >= Rec.Left And Point.X <= Rec.Right And Point.Y >= Rec.Top And Point.Y <= Rec.Bottom Then
Me.Caption = "MouseCursor is on form."
Else
' The cursor is not located above the form
Me.Caption = "MouseCursor is not on form."
End If
End Sub
Private Sub Timer2_Timer()
Dim Rec As RECT, Point As POINTAPI
' Get Left, Right, Top and Bottom of ExplButton
GetWindowRect ExplButton.hwnd, Rec
' Get the position of the cursor
GetCursorPos Point
' If the cursor isn't located above ExplButton then
If Point.X < Rec.Left Or Point.X > Rec.Right Or Point.Y < Rec.Top Or Point.Y > Rec.Bottom Then ExplButton.Cls
End Sub
注:我的总的目标是打开一个摄像头画面,捕捉任意时刻的图像,然后对图像中心区域提取颜色并将不同的颜色对应不同的声音,现在主要的困难就在怎样捕捉摄像头的画面图像。我用的方法是获得窗口句柄,然后根据坐标抓图。其实也可以在VB窗口中播放摄像头画面,但是我不会,我是因为刚用VB,一点都不会。
Left As Long
Top As Long
Right As Long
Bottom As Long
End TypePrivate Declare Function GetWindowRect Lib "user32" (ByVal hwnd As Long, lpRect As RECT) As Long
Private Declare Function GetClientRect Lib "user32" (ByVal hwnd As Long, lpRect As RECT) As Long
Private Sub Command1_Click()
Dim ret As RECT
GetWindowRect Me.hwnd, ret
Print ret.Left
Print ret.Right
Print ret.Top
Print ret.Bottom
End Sub
sxycgxj() :这种方法我知道,我试了就是不对
Private Sub Command1_Click()
Dim Rec As RECT
'Get Left, Right, Top and Bottom of Form1
GetWindowRect Form1.hwnd, Rec
'Set Cursor position on X
SetCursorPos Rec.Right - 15, Rec.Top + 15
End Sub
能行
为什么
laviewpbt(人一定要靠自己:我试了,你这样不行
sxycgxj() :这种方法我知道,我试了就是不对
你觉的他们想给你的答案有区别吗?我想他们说的应该行.