urForm.Caption = "释放鼠标"
With NewRect
.Left = 0&
.Top = 0&
.Right = Screen.Width / Screen.TwipsPerPixelX
.Bottom = Screen.Height / Screen.TwipsPerPixelY
End With
erg& = ClipCursor(NewRect)
End Sub
Public Sub EnableTrap(CurForm As Form)
Dim x As Long, y As Long, erg As Long
''''声明过程变量
''''设置新坐标
Dim NewRect As RECT
''''得到TwipsperPixel
''''窗体的ScaleMode必须设为Twips!!!
x& = Screen.TwipsPerPixelX
y& = Screen.TwipsPerPixelY
CurForm.Caption = "捕捉鼠标"
''''设置光标的范围
With NewRect
.Left = CurForm.Left / x&
.Top = CurForm.Top / y&
.Right = .Left + CurForm.Width / x&
.Bottom = .Top + CurForm.Height / y&
End With
erg& = ClipCursor(NewRect)
End Sub
2、在窗体上添加两个命令按钮(Command Button)。
3、把以下代码添加如Form1。
Private Sub Command1_Click()
EnableTrap Form1
End Sub
Private Sub Command2_Click()
DisableTrap Form1
End Sub
Private Sub Form_Unload(Cancel As Integer)
''''程序结束时释放鼠标。
DisableTrap Form1
End Sub
怎样使我的程序总处于屏幕最前方?(Always on top)
如果你想让你的程序处于前方,可以使用以下代码:
Form1.ZOrder
配合计时器使用,每隔一段很小的时间间隔调用这种方法可以使窗体Form1处于屏幕前方,但是用户还是可能使别的窗体在短暂的时间里处于Form1的上方。所以这种方法并不能使窗体真正的实现Always on top,而要真正的Always on top可以使用API函数SetWindowPos,代码如下:
''''声明函数:
Declare Function SetWindowPos Lib "user32" _
(ByVal h%, ByVal hb%, ByVal x%, ByVal y%, _
ByVal cx%,ByVal cy%,ByVal f%) As Integer
Global Const SWP_NOMOVE = 2
Global Const SWP_NOSIZE = 1
Global Const FLAGS = SWP_NOMOVE Or SWP_NOSIZE
Global Const HWND_TOPMOST = -1
Global Const HWND_NOTOPMOST = -2
''''把窗体放在最前面:
res% = SetWindowPos (Form1.hWnd, HWND_TOPMOST, _
0, 0, 0, 0, FLAGS)
''''如果res%=0, 就产生错误
''''使窗体恢复普通模式:
res% = SetWindowPos (Form1.hWnd, HWND_NOTOPMOST, _
0, 0, 0, 0, FLAGS)
怎样得到文本框(TextBox)中的文本行数?
计算文本框中输入文本的行数可以使用SendMessage函数返回,当一行文字发生环绕时,它将被当作新的一行,而被非简单的计算文本中的换行符个数。
把以下API函数的声明添入模块文件的general declarations区域,如果您使用的是VB4-32或VB5,也可以把此声明添入Form1的general declarations中,并把所有的“Public”更换为“Private”。
Option Explicit
Public Declare Function SendMessageLong Lib _
"user32" Alias "SendMessageA" _
(ByVal hwnd As Long, _
ByVal wMsg As Long, _
ByVal wParam As Long, _
ByVal lParam As Long) As Long
Public Const EM_GETLINECOUNT = &HBA
Form Code
Sub Text1_Change()
Dim lineCount as Long
On Local Error Resume Next
''''得到/显示文本行数
lineCount = SendMessageLong(Text1.hwnd, EM_GETLINECOUNT, 0&, 0&)
Label1 = Format$(lineCount, "##,###")
End Sub
注释:
为了使本程序成功,请在设计阶段把文本框的Multiline属性设为True。
怎样使程序的标题条闪烁?
建立新的项目文件,添加模块文件,并填写如下代码:
Public Declare Function FlashWindow _
Lib "user32" (ByVal hwnd As Long, _
ByVal bInvert As Long) As Long
在窗体中添加两个按钮和一个计时器,并用设置以下属性:
command1.caption="开始"
command2.caption="停止"
timer1.interval=500 ''''每0.5秒闪烁一次
timer1.enabled=false
Private Sub Timer1_Timer()
a& = FlashWindow(Me.hwnd, 1)
End Sub
Private Sub Command1_Click()
Timer1.Enabled = True
End Sub
Private Sub Command2_Click()
Timer1.Enabled = False
End Sub
按F5运行程序。
上一页 [1] [2] 没有相关教程
|