如果你想让你的程序处于前方,可以使用以下代码:
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)
计算文本框中输入文本的行数可以使用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="开始"