国产成人v爽在线免播放观看,日韩欧美色,久久99国产精品久久99软件,亚洲综合色网站,国产欧美日韩中文久久,色99在线,亚洲伦理一区二区

學習啦>學習電腦>電腦硬件知識>鍵盤鼠標>

VB怎么更改鼠標指針樣式

時間: 本達868 分享

  VB設置鼠標的指針樣式,可設置窗口中的鼠標樣式和系統(tǒng)中的鼠標指針樣式,通過操作窗口中的菜單,你就可以很方便的改變鼠標樣式,下面是學習啦小編給大家整理的一些相關解決方法步驟,希望對大家有幫助!

  VB怎么更改鼠標指針樣式

  這是窗體代碼:

  01VERSION 5.00

  02Object = "{F9043C88-F6F2-101A-A3C9-08002B2F49FB}#1.2#0"; "Comdlg32.ocx"

  03Begin VB.Form Form1

  04 Caption = "鼠標樣式設置器"

  05 ClientHeight = 3210

  06 ClientLeft = 165

  07 ClientTop = 735

  08 ClientWidth = 5490

  09 LinkTopic = "Form1"

  10 ScaleHeight = 3210

  11 ScaleWidth = 5490

  12 StartUpPosition = 3 '窗口缺省

  13 Begin MSComDlg.CommonDialog CommonDialog1

  14 Left = 2640

  15 Top = -45

  16 _ExtentX = 847

  17 _ExtentY = 847

  18 _Version = 393216

  19 End

  20 Begin VB.Menu SetMouse

  21 Caption = "設置鼠標樣式"

  22 Begin VB.Menu SetSysMouse

  23 Caption = "設置系統(tǒng)鼠標樣式"

  24 End

  25 Begin VB.Menu BackSysMouse

  26 Caption = "恢復系統(tǒng)鼠標樣式"

  27 End

  28 Begin VB.Menu SetFormMouse

  29 Caption = "設置窗體鼠標樣式"

  30 End

  31 Begin VB.Menu BackFormMouse

  32 Caption = "恢復窗體鼠標樣式"

  33 End

  34 End

  35End

  36Attribute VB_Name = "Form1"

  37Attribute VB_GlobalNameSpace = False

  38Attribute VB_Creatable = False

  39Attribute VB_PredeclaredId = True

  40Attribute VB_Exposed = False

  41Option Explicit

  42Const OCR_NORMAL = 32512

  43Const IDC_ARROW = 32512&

  44Const SPI_SETCURSORS = 87

  45Const SPIF_SENDWININICHANGE = &H2

  46Const OCR_NORAAC = 32512 '標準

  47Const GCL_HCURSOR = (-12)

  48' const OCR_APPSTARTING = 32650 '小的沙漏

  49' const OCR_HAND = 32649 '手

  50' const OCR_NO = 32648 '圓

  51' const OCR_SIZEALL = 32646 '十

  52' const OCR_WAIT = 32514 '沙漏

  53Private Declare Function LoadCursorFromFile Lib "user32" Alias "LoadCursorFromFileA" (ByVal lpFileName As String)As Long

  54Private Declare Function SetSystemCursor Lib "user32" (ByVal hcur As Long, _

  55 ByVal id As Long) As Long

  56Private Declare Function SystemParametersInfo Lib "user32" Alias "SystemParametersInfoA" (ByVal uAction As Long, _

  57 ByVal uParam As Long, _

  58 ByRef lpvParam As Any, _

  59 ByVal fuWinIni As Long _

  60 ) As Long

  61Private Declare Function SetClassLong Lib "user32" Alias "SetClassLongA" (ByVal hwnd As Long, _

  62 ByVal nIndex As Long, _

  63 ByVal dwNewLong As Long _

  64 ) As Long

  65Private Declare Function GetSystemDirectory Lib "kernel32" Alias "GetSystemDirectoryA" (ByVal lpBuffer As String, _

  66 ByVal nSize As Long _

  67 ) As Long

  68Dim hCursor As Long

  69Private Sub BackFormMouse_Click() '恢復窗體鼠標的樣式

  70 Dim sPath As String * 260 '定義路徑

  71 GetSystemDirectory sPath, Len(sPath)

  72 hCursor = LoadCursorFromFile(sPath)

  73 SetClassLong Me.hwnd, GCL_HCURSOR, hCursor

  74End Sub

  75Private Sub BackSysMouse_Click() '恢復系統(tǒng)鼠標的樣式

  76 SystemParametersInfo SPI_SETCURSORS, 0, 0, SPIF_SENDWININICHANGE

  77End Sub

  78Private Sub SetFormMouse_Click() '設置窗體的鼠標樣式

  79 CommonDialog1.Filter = "CUR文件(*.cur)|*.cur|ANI文件(*.ani)|*.ani|所有文件|(*.*)"

  80 CommonDialog1.ShowOpen

  81 CommonDialog1.CancelError = False

  82 If CommonDialog1.FileName <> "" Then

  83 hCursor = LoadCursorFromFile(CommonDialog1.FileName)

  84 SetClassLong Me.hwnd, GCL_HCURSOR, hCursor

  85 End If

  86End Sub

  87Private Sub SetSysMouse_Click() '設置系統(tǒng)鼠標樣式

  88 CommonDialog1.Filter = "CUR文件(*.cur)|*.cur|ANI文件(*.ani)|*.ani|所有文件|(*.*)"

  89 CommonDialog1.ShowOpen

  90 CommonDialog1.CancelError = False

  91 If CommonDialog1.FileName <> "" Then

  92 hCursor = LoadCursorFromFile(CommonDialog1.FileName)

  93 Call SetSystemCursor(hCursor, OCR_NORMAL)

  94 End If

  95End Sub

  程序運行截圖如下圖所示:

  相關拓展:vb如何控制鼠標

  主要是要通過兩個方面:

  (一)對鼠標的停留位置做出判斷,也就是得到鼠標在屏幕上停留的位置。

  (二)將鼠標的移動到所確定的位置上。 而實現(xiàn)這個功能則要使用到SetCursorPos這個函數(shù),此函數(shù)的功能是設定鼠標位置。

  這個函數(shù)的聲明如下:

  Public Declare Function SetCursorPos Lib "user32" (ByVal x As Long, ByVal y As Long) As Long

  而僅僅有這個函數(shù)是不夠的,還需要定義一個type格式的自定義變量。定義為:

  Public Type POINTAPI

  x As Long

  y As Long

  End Type

  它用于存放鼠標的位置(屏幕上的位置)。

  但是一個新的問題又出現(xiàn)了:鼠標到底放在哪里呢?也就是如何獲得屏幕上的位置。

  這個問題就要用到另一個函數(shù):GetCursorPos,它的功能是獲得屏幕上鼠標的坐標。

  它的聲明如下:

  Public Declare Function GetCursorPos Lib "user32" (lpPoint As POINTAPI) As Long

  這樣就可以通過GetCursorPos函數(shù)獲得鼠標的位置,存放到一個POINTAPI變量中,再通過SetCursorPos函數(shù)來設置鼠標的位置。

  這樣就可以十分順利的來控制鼠標了!

1357862