vb獲取相對坐標(biāo).doc_第1頁
vb獲取相對坐標(biāo).doc_第2頁
vb獲取相對坐標(biāo).doc_第3頁
vb獲取相對坐標(biāo).doc_第4頁
全文預(yù)覽已結(jié)束

下載本文檔

版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進行舉報或認領(lǐng)

文檔簡介

獲取窗口相對坐標(biāo)示例一:無論某窗口如何改變,單擊窗體某相對位置實現(xiàn):一窗體,兩按鈕,單擊按鈕一時,光標(biāo)移動到按鈕二上并單擊(并非諸如call command2_click()之類);重點在于坐標(biāo)轉(zhuǎn)換。兩CommamdButtonPrivate Declare Function GetWindowRect Lib user32 _(ByVal hwnd As Long, lpRect As RECT) As LongPrivate Declare Sub mouse_event Lib user32 (ByVal dwFlags As Long, ByVal dx As Long, ByVal dy As Long, ByVal cButtons As Long, ByVal dwExtraInfo As Long)Private Declare Function SetCursorPos Lib user32 (ByVal x As Long, ByVal y As Long) As LongPrivate Type RECTleft As Longtop As Longright As Longbottom As LongEnd TypePrivate Type POINTx As Longy As LongEnd TypeConst MOUSEEVENTF_LEFTDOWN As Integer = &H2Const MOUSEEVENTF_LEFTUP As Integer = &H4Private Sub Command1_Click() 測試鍵Dim re As RECT, pt As POINT, x As Long, y As LongGetWindowRect Me.hwnd, re 獲取窗口矩形信息x = re.left + (Command2.left + Command2.Width / 2) / Screen.TwipsPerPixelXy = re.top + (Command2.top + Me.Height - Me.ScaleHeight + Command2.Height / 2) / Screen.TwipsPerPixelYSetCursorPos x, y 移動光標(biāo)至(x,y)mouse_event MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0mouse_event MOUSEEVENTF_LEFTUP, 0, 0, 0, 0End Sub目標(biāo)按鈕Private Sub Command2_Click()MsgBox You have clicked me !End Sub示例二:坐標(biāo)三步轉(zhuǎn)換,窗體上有圖像框,圖像框上有坐標(biāo)系,顯示鼠標(biāo)在坐標(biāo)系位置注:坐標(biāo)系為數(shù)學(xué)常用坐標(biāo)系,原點在左下角實現(xiàn):獲取光標(biāo)位置,轉(zhuǎn)換成窗體位置,轉(zhuǎn)換成圖像框位置,轉(zhuǎn)換為坐標(biāo)系位置。一PictureBoxPrivate Declare Function GetCursorPos Lib user32 (lpPoint As POINTAPI) As LongPrivate Declare Function ScreenToClient Lib user32 (ByVal hwnd As Long, lpPoint As POINTAPI) As LongPrivate Type POINTAPI x As Long y As LongEnd TypeDim pt As POINTAPIPrivate Sub Form_Load() Timer1.Interval = 100End SubPrivate Sub Timer1_Timer() GetCursorPos pt 獲取鼠標(biāo)屏幕位置 ScreenToClient Me.hwnd, pt 轉(zhuǎn)換成窗口位置 If pt.x Picture1.left / Screen.TwipsPerPixelX And _ pt.x Picture1.top / Screen.TwipsPerPixelY And _ pt.y (Picture1.top + Picture1.Height) / Screen.TwipsPerPixelY Then Picture1.Cls Picture1.Print pt.x - Picture1.left / Screen.TwipsPerPixelX & , & _ (Picture1.top + Picture1

溫馨提示

  • 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
  • 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
  • 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負責(zé)。
  • 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時也不承擔(dān)用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。

評論

0/150

提交評論