Visual Basic, .NET, ASP, VBScript
 

   
   
     

Форум - Общий форум

Страница: 1 |

 

  Вопрос: Работа с мышью в VB6 Добавлено: 23.10.08 18:11  

Автор вопроса:  KreAtoR
Необходимо узнать похицию мыши на экране, пожскажите как это сделать

Ответить

  Ответы Всего ответов: 3  

Номер ответа: 1
Автор ответа:
 Arseny



ICQ: 298826769 

Вопросов: 53
Ответов: 1732
 Профиль | | #1 Добавлено: 23.10.08 18:16
API GetCursorPos

Ответить

Номер ответа: 2
Автор ответа:
 KreAtoR



Вопросов: 120
Ответов: 438
 Профиль | | #2 Добавлено: 23.10.08 18:38
можешь пример привести как с этой функцией работать. плиз

Ответить

Номер ответа: 3
Автор ответа:
 Arseny



ICQ: 298826769 

Вопросов: 53
Ответов: 1732
 Профиль | | #3 Добавлено: 23.10.08 18:44
ну, по-моему, чудесная прога - API-Guide:
  1. 'This project needs
  2. 'a Form, called 'Form1'
  3. 'a Picture Box, called 'ExplButton' (50x50 pixels)
  4. 'a Picture Box with an icon in it, called 'picIcon'
  5. 'two timers (Timer1 and Timer2), both with interval 100
  6. 'Button, called 'Command1'
  7. 'In general section
  8. Private Type RECT
  9.     Left As Long
  10.     Top As Long
  11.     Right As Long
  12.     Bottom As Long
  13. End Type
  14. Private Type POINTAPI
  15.     X As Long
  16.     Y As Long
  17. End Type
  18.  
  19. 'Declare the API-Functions
  20. Private Declare Function GetCursorPos Lib "user32" (lpPoint As POINTAPI) As Long
  21. Private Declare Function SetCursorPos Lib "user32" (ByVal X As Long, ByVal Y As Long) As Long
  22. Private Declare Function GetWindowRect Lib "user32" (ByVal hwnd As Long, lpRect As RECT) As Long
  23. Sub DrawButton(Pushed As Boolean)
  24.     Dim Clr1 As Long, Clr2 As Long
  25.     If Pushed = True Then
  26.         'If Pushed=True then clr1=Dark Gray
  27.         Clr1 = &H808080
  28.         'If Pushed=True then clr1=White
  29.         Clr2 = &HFFFFFF
  30.     ElseIf Pushed = False Then
  31.         'If Pushed=True then clr1=White
  32.         Clr1 = &HFFFFFF
  33.         'If Pushed=True then clr1=Dark Gray
  34.         Clr2 = &H808080
  35.     End If
  36.  
  37.     With Form1.ExplButton
  38.         ' Draw the button
  39.         Form1.ExplButton.Line (0, 0)-(.ScaleWidth, 0), Clr1
  40.         Form1.ExplButton.Line (0, 0)-(0, .ScaleHeight), Clr1
  41.         Form1.ExplButton.Line (.ScaleWidth - 1, .ScaleHeight - 1)-(.ScaleWidth - 1, 0), Clr2
  42.         Form1.ExplButton.Line (.ScaleWidth - 1, .ScaleHeight - 1)-(0, .ScaleHeight - 1), Clr2
  43.     End With
  44. End Sub
  45. Private Sub Command1_Click()
  46.     Dim Rec As RECT
  47.     'Get Left, Right, Top and Bottom of Form1
  48.     GetWindowRect Form1.hwnd, Rec
  49.     'Set Cursor position on X
  50.     SetCursorPos Rec.Right - 15, Rec.Top + 15
  51. End Sub
  52. Private Sub ExplButton_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
  53.     DrawButton True
  54. End Sub
  55. Private Sub ExplButton_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
  56.     DrawButton False
  57. End Sub
  58. Private Sub ExplButton_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
  59.     DrawButton False
  60. End Sub
  61. Private Sub Form_Load()
  62.     'KPD-Team 1998
  63.     'URL: http://www.allapi.net/
  64.     'E-Mail: KPDTeam@Allapi.net
  65.  
  66.     Dim Stretched As Boolean
  67.     'picIcon.Visible = False
  68.     'API uses pixels
  69.     picIcon.ScaleMode = vbPixels
  70.     'No border
  71.     ExplButton.BorderStyle = 0
  72.     'API uses pixels
  73.     ExplButton.ScaleMode = vbPixels
  74.     'Set graphic mode te 'persistent graphic'
  75.     ExplButton.AutoRedraw = True
  76.     'API uses pixels
  77.     Me.ScaleMode = vbPixels
  78.     'Set the button's caption
  79.     Command1.Caption = "Set Mousecursor on X"
  80.  
  81.     ' If you set Stretched to true then stretch the icon to te Height and Width of the button
  82.     ' If Stretched=False, the icon will be centered
  83.     Stretched = False
  84.  
  85.     If Stretched = True Then
  86.         ' Stretch the Icon
  87.         ExplButton.PaintPicture picIcon.Picture, 1, 1, ExplButton.ScaleWidth - 2, ExplButton.ScaleHeight - 2
  88.     ElseIf Stretched = False Then
  89.         ' Center the picture of the icon
  90.         ExplButton.PaintPicture picIcon.Picture, (ExplButton.ScaleWidth - picIcon.ScaleWidth) / 2, (ExplButton.ScaleHeight - picIcon.ScaleHeight) / 2
  91.     End If
  92.     ' Set icon as picture
  93.     ExplButton.Picture = ExplButton.Image
  94. End Sub
  95. Private Sub Timer1_Timer()
  96.     Dim Rec As RECT, Point As POINTAPI
  97.     ' Get Left, Right, Top and Bottom of Form1
  98.     GetWindowRect Me.hwnd, Rec
  99.     ' Get the position of the cursor
  100.     GetCursorPos Point
  101.  
  102.     ' If the cursor is located above the form then
  103.     If Point.X >= Rec.Left And Point.X <= Rec.Right And Point.Y >= Rec.Top And Point.Y <= Rec.Bottom Then
  104.         Me.Caption = "MouseCursor is on form."
  105.     Else
  106.         ' The cursor is not located above the form
  107.         Me.Caption = "MouseCursor is not on form."
  108.     End If
  109. End Sub
  110. Private Sub Timer2_Timer()
  111.     Dim Rec As RECT, Point As POINTAPI
  112.     ' Get Left, Right, Top and Bottom of ExplButton
  113.     GetWindowRect ExplButton.hwnd, Rec
  114.     ' Get the position of the cursor
  115.     GetCursorPos Point
  116.     ' If the cursor isn't located above ExplButton then
  117.     If Point.X < Rec.Left Or Point.X > Rec.Right Or Point.Y < Rec.Top Or Point.Y > Rec.Bottom Then ExplButton.Cls
  118. End Sub

Ответить

Страница: 1 |

Поиск по форуму



© Copyright 2002-2011 VBNet.RU | Пишите нам