vb常用代码大全

合集下载
  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。

.

Word 资料

移动无标题栏的窗体 dim m(borderstyle=none) ouseX as integer dim mouseY as integer dim moveX as integer dim moveY as integer dim down as boolean

form_mousedown: 'mousedown 事件

down=true mouseX=x mouseY=y

form_mouseup: 'mouseup 事件 down=false form_mousemove if down=true then

moveX=me.left-mouseX+X moveY=me.top-mouseY+Y me.move moveX,moveY end if

*******************************************闪烁控件

比如要闪烁一个label (标签)

添加一个时钟控件 间隔请根据实际需要设置 enabled 属性设为true 代码为:

label1.visible=not label1.visible *******************************************

禁止使用 Alt+F4 关闭窗口

Private Declare Function DeleteM enu Lib "user32" (ByVal hMenu As L ong, ByVal nPosition As Long, ByV al wFlags As Long) As Long Private Declare Function GetMen uItemCount Lib "user32" (ByVal hM enu As Long) As Long

Private Const MF_BYPOSITION = &H 400&

Private Sub Form_Load() Dim hwndMenu As Long Dim c As Long

hwndMenu = GetSystemMenu(Me .hwnd, 0)

c = GetMenuItemCount(hwndMe nu)

VB 常用代码

DeleteMenu hwndMenu, c - 1, MF _BYPOSITION

c = GetMenuItemCount(hwndMe nu)

DeleteMenu hwndMenu, c - 1, MF _BYPOSITION

End Sub

启动控制面板大全

'打开控制面板

Call Shell("rundll32.exe shell32.dll,C ontrol_RunDLL", 9)

'辅助选项属性-键盘

Call Shell("rundll32.exe shell32.dll,C ontrol_RunDLL access.cpl,,1", 9) '辅助选项属性-声音

Call Shell("rundll32.exe shell32.dll,C ontrol_RunDLL access.cpl,,2", 9) '辅助选项属性-显示

Call Shell("rundll32.exe shell32.dll,C ontrol_RunDLL access.cpl,,3", 9) '辅助选项属性-鼠标

Call Shell("rundll32.exe shell32.dll,C ontrol_RunDLL access.cpl,,4", 9)

'辅助选项属性-常规

Call Shell("rundll32.exe shell32.dll,C ontrol_RunDLL access.cpl,,5", 9)

'添加/删除程序属性-安装/卸载

Call Shell("rundll32.exe shell32.dll,C ontrol_RunDLL Appwiz.cpl,,1", 9) '添加/删除程序属性-Windows安装程序

Call Shell("rundll32.exe shell32.dll,C ontrol_RunDLL Appwiz.cpl,,2", 9) '添加/删除程序属性-启动盘

Call Shell("rundll32.exe shell32.dll,C ontrol_RunDLL Appwiz.cpl,,3", 9) '显示属性-背景

Call Shell("rundll32.exe shell32.dll,C ontrol_RunDLL desk.cpl,,0", 9)

'显示属性-屏幕保护程序

Call Shell("rundll32.exe shell32.dll,C ontrol_RunDLL desk.cpl,,1", 9)

'显示属性-外观

Call Shell("rundll32.exe shell32.dll,C ontrol_RunDLL desk.cpl,,2", 9)

Word 资料

'显示属性-设置

Call Shell("rundll32.exe shell32.dll,C ontrol_RunDLL desk.cpl,,3", 9)

'Internet 属性-常规

Call Shell("rundll32.exe shell32.dll,C ontrol_RunDLL Inetcpl.cpl,,0", 9)

'Internet 属性-安全

Call Shell("rundll32.exe shell32.dll,C ontrol_RunDLL Inetcpl.cpl,,1", 9)

'Internet 属性-内容

Call Shell("rundll32.exe shell32.dll,C ontrol_RunDLL Inetcpl.cpl,,2", 9)

'Internet 属性-连接

Call Shell("rundll32.exe shell32.dll,C ontrol_RunDLL Inetcpl.cpl,,3", 9)

*************************************** ****

怎样关闭一个程序

你可以使用API函数FindWindow和PostMessage来寻找一个窗口并且关闭它。下面的范例演示如何关闭一个标题为"Calculator"的窗口。

Dim winHwnd As Long Dim RetVal As Long

winHwnd = FindWindow(vbNullStri ng, "Calculator")

Debug.Print winHwnd

If winHwnd <> 0 Then

RetVal = PostMessage(winHwnd, WM_CLOSE, 0&, 0&)

If RetVal = 0 Then

MsgBox "Error posting message." End If

Else

MsgBox "The Calculator is not ope n."

End If

For this code to work, you must ha ve declared the API functions in a module in your project. You must put the following in the declaratio ns section of the module. Declare Function FindWindow Lib " user32" Alias _ "FindWindowA" (ByVal lpClassNam e As String, _

Word 资料

相关文档
最新文档