vb常用代码大全.pdf
《vb常用代码大全.pdf》由会员分享,可在线阅读,更多相关《vb常用代码大全.pdf(16页珍藏版)》请在淘文阁 - 分享文档赚钱的网站上搜索。
1、VBVB 常用代码常用代码移动无标题栏的窗体移动无标题栏的窗体dim m(borderstyle=none)ouseX as integerdim mouseY as integerdim moveX as integerdim moveY as integerdim down as booleanform_mousedown:mousedown 事件down=truemouseX=xmouseY=yform_mouseup:mouseup 事件down=falseform_mousemoveif down=true then moveX=me。leftmouseX+X moveY=me.to
2、p-mouseY+Y me.move moveX,moveYend if*闪烁控件比如要闪烁一个 label(标签)添加一个时钟控件 间隔请根据实际需要设置 enabled 属性设为 true代码为:label1.visible=not label1.visible*禁止使用 Alt+F4 关闭窗口Private Declare Function DeleteMenu Lib”user32(ByVal hMenu As Long,ByValnPosition As Long,ByVal wFlags As Long)As LongPrivate Declare Function GetMenu
3、ItemCount Lib”user32”(ByVal hMenu As Long)As LongPrivate Const MF_BYPOSITION=H400&Private Sub Form_Load()Dim hwndMenu As LongDim c As LonghwndMenu=GetSystemMenu(Me。hwnd,0)c=GetMenuItemCount(hwndMenu)-1-DeleteMenu hwndMenu,c-1,MF_BYPOSITIONc=GetMenuItemCount(hwndMenu)DeleteMenu hwndMenu,c-1,MF_BYPOSI
4、TIONEnd Sub启动控制面板大全启动控制面板大全打开控制面板Call Shell(”rundll32.exe shell32。dll,Control_RunDLL,9)辅助选项 属性-键盘Call Shell(”rundll32。exe shell32.dll,Control_RunDLL access.cpl,1,9)辅助选项 属性声音Call Shell(rundll32.exe shell32。dll,Control_RunDLL access。cpl,2”,9)辅助选项 属性显示Call Shell(rundll32.exe shell32.dll,Control_RunDLL
5、access。cpl,3,9)辅助选项 属性鼠标Call Shell(”rundll32。exe shell32.dll,Control_RunDLL access.cpl,,4,9)辅助选项 属性常规Call Shell(rundll32.exe shell32.dll,Control_RunDLL access.cpl,5,9)添加/删除程序 属性安装/卸载Call Shell(rundll32。exe shell32.dll,Control_RunDLL Appwiz。cpl,,1,9)添加/删除程序 属性-Windows 安装程序Call Shell(rundll32.exe shel
6、l32。dll,Control_RunDLL Appwiz。cpl,2”,9)添加/删除程序 属性启动盘Call Shell(”rundll32.exe shell32.dll,Control_RunDLL Appwiz。cpl,3,9)显示 属性-背景Call Shell(”rundll32.exe shell32.dll,Control_RunDLL desk.cpl,,0,9)显示 属性-屏幕保护程序Call Shell(rundll32。exe shell32.dll,Control_RunDLL desk.cpl,,1,9)显示 属性-外观Call Shell(”rundll32.e
7、xe shell32.dll,Control_RunDLL desk.cpl,,2,9)显示 属性设置Call Shell(”rundll32。exe shell32.dll,Control_RunDLL desk.cpl,3,9)Internet 属性-常规Call Shell(”rundll32。exe shell32。dll,Control_RunDLL Inetcpl.cpl,0”,9)Internet 属性安全Call Shell(rundll32.exe shell32。dll,Control_RunDLL Inetcpl。cpl,1”,9)Internet 属性内容Call Sh
8、ell(rundll32。exe shell32.dll,Control_RunDLL Inetcpl.cpl,,2”,9)Internet 属性连接Call Shell(rundll32.exe shell32。dll,Control_RunDLL Inetcpl。cpl,,3,9)*怎样关闭一个程序你可以使用 API 函数 FindWindow 和PostMessage 来寻找一个窗口并且关闭它。下面的范例演示如何关闭一个标题为”Calculator的窗口。Dim winHwnd As LongDim RetVal As LongwinHwnd=FindWindow(vbNullStrin
9、g,”Calculator”)Debug.Print winHwndIf winHwnd 0 ThenRetVal=PostMessage(winHwnd,WM_CLOSE,0&,0&)If RetVal=0 ThenMsgBox”Error posting message。End IfElseMsgBox”The Calculator is not open。End IfFor this code to work,you must have declared the API functions in a module in your project.You must put the foll
10、owing in the declarations section of the module。-2-Declare Function FindWindow Lib”user32 Alias _”FindWindowA”(ByVal lpClassName As String,_ByVal lpWindowName As String)As LongDeclare Function PostMessage Lib”user32 Alias _PostMessageA”(ByVal hwnd As Long,ByVal wMsg As Long,_ByVal wParam As Long,lPa
11、ram As Any)As LongPublic Const WM_CLOSE=&H10*如何使 Form 的背景图随 Form 大小改变单纯显示图形用 Image 即可,而且用Image 也正好可解决你的问题设定 Image 的 Stretch=true在加入以下的 codePrivate Sub Form_Resize()Image1.Move 0,0,ScaleWidth,ScaleHeightEnd Sub或者使用以下的方式来做也可以Private Sub Form_Paint()Me。PaintPicture Me。Picture,0,0,ScaleWidth,ScaleHeight
12、End Sub*软件的注册可用注册表简单地保存已用的天数或次数次数限制(如次)如下:Private Sub Form_Load()Dim RemainDay As LongRemainDay=GetSetting(MyApp,set,times,0)If RemainDay=30 Then MsgBox”试用次数已满,请注册 Unload MeEnd IfMsgBox 现在剩下:&30-RemainDay&”试用次数,好好珍惜!RemainDay=RemainDay+1SaveSetting”MyApp,set”,”times,RemainDayEnd Sub时间限制的(如天)Private
13、Sub Form_Load()Dim RemainDay As LongRemainDay=GetSetting(”MyApp,set”,”day”,0)If RemainDay=30 Then MsgBox 试用期已过,请注册”Unload MeEnd IfMsgBox”现在剩下:”&30-RemainDay&”试用天数,好好珍惜!if day(now)remainday0 then RemainDay=RemainDay+1SaveSettingMyApp”,set”,times”,RemainDayEnd Sub*MMControl 控件全屏播放Option ExplicitPrivat
14、e Declare Function mciSendString Lib”winmm。dll”_ Alias mciSendStringA”(ByVal lpstrCommand As _ String,ByVal lpstrReturnString As Any,ByVal _ uReturnLength As Long,ByVal hwndCallback As _ Long)As LongPrivate Declare Function mciSendCommand Lib winmm。dll”_ Alias mciSendCommandA”(ByVal wDeviceID As Lon
15、g,_ ByVal uMessage As Long,ByVal dwParam1 As Long,_ dwParam2 As MCI_OVLY_RECT_PAR-3-MS)As LongPrivate Declare Function GetShortPathName Lib”kernel32”_ Alias GetShortPathNameA(ByVal lpszLongPath As _ String,ByVal lpszShortPath As String,ByVal _ cchBuffer As Long)As LongPrivate Type RECT Left As Long
16、Top As Long Right As Long Bottom As LongEnd TypePrivate Type MCI_OVLY_RECT_PARMS dwCallback As Long rc As RECTEnd TypeConst MCI_OVLY_WHERE_SOURCE=H20000Const MCI_OVLY_WHERE_DESTINATION=&H40000Const MCI_WHERE=H843Dim Play As BooleanPrivate Sub Form_Load()MMControl1。Wait=True MMControl1.UpdateInterval
17、=50 MMControl1.hWndDisplay=Picture1。hWnd Picture1.ScaleMode=3 Timer1。Interval=50End SubPrivate Sub Form_Unload(Cancel As Integer)MMControl1。Command=”stop”MMControl1.Command=closeEnd SubPrivate Sub Command1_Click()MMControl1。Command=”stop MMControl1。Command=”close”Play=False CommonDialog1。Filter=(”VB
18、-Dateien(*.avi)|*.avi;”)CommonDialog1。InitDir=App.Path CommonDialog1.ShowOpen If CommonDialog1.filename ”Then MMControl1.DeviceType=”avivideo MMControl1.filename=CommonDialog1.filename MMControl1.Command=open”MMControl1。Notify=True Label4。Caption=MMControl1.Length If Check2。Value=vbChecked And Optio
19、n2 Then Call AdaptPicture End If If Option3.Value Then Call Option3_Click Me.Caption=CommonDialog1.filename End IfEnd SubPrivate Sub Command2_Click()If Not Option3。Value Then If Play=False And MMControl1.filename Then MMControl1。Command=play”Play=True End If Else Call Option3_Click End IfEnd SubPriv
20、ate Sub Command3_Click()Play=False MMControl1.Command=”stop”End SubPrivate Sub Command4_Click()-4-MMControl1。Command=pause”End SubPrivate Sub MMControl1_Done(NotifyCode As Integer)If Play And Check1。Value=vbChecked Then Play=False MMControl1。Command=”stop MMControl1。Command=”prev”MMControl1.Command=
21、play Play=True End IfEnd SubPrivate Sub MMControl1_StatusUpdate()Label2.Caption=MMControl1.PositionEnd SubPrivate Sub Option1_Click()Check1.Enabled=True Check2。Enabled=False MMControl1。hWndDisplay=0End SubPrivate Sub Option2_Click()Check1。Enabled=True Check2。Enabled=True MMControl1。hWndDisplay=Pictu
22、re1。hWndEnd SubPrivate Sub Option3_Click()注意这里 Dim R,AA$Check1。Enabled=False Check2.Enabled=False MMControl1.Command=stop Play=False AA=Space$(255)R=GetShortPathName(CommonDialog1.filename,AA,Len(AA))AA=Mid$(AA,1,R)R=mciSendString(play&AA ”fullscreen,0,0,0&)End SubPrivate Sub Check2_Click()If Check2
23、。Value=vbChecked And MMControl1。filename ”Then Call AdaptPicture End IfEnd SubPrivate Sub Timer1_Timer()Dim x%,AA$x=MMControl1。Mode Select Case x Case 524:AA=NotOpen”Case 525:AA=Stop”Case 526:AA=Play Case 527:AA=”Record Case 528:AA=Seek Case 529:AA=Pause Case 530:AA=Ready End Select Label6.Caption=A
24、AEnd SubPrivate Sub AdaptPicture()Dim Result,Par As MCI_OVLY_RECT_PARMS Par。dwCallback=MMControl1.hWnd Result=mciSendCommand(MMControl1。DeviceID,_ MCI_WHERE,MCI_OVLY_WHERE_SOURCE,Par)If Result 0 Then MsgBox(”Fehler)Else Picture1。Width=(Par.rc.Right-Par。rc.Left)*15+4*15 Picture1.Height=(Par。rc.Bottom
25、-Par.rc。Top)*15+4*15 End If-5-End Sub*通用对话框专辑(全)使用API调用Winodws各种通用对话框(Common Diaglog)的方法(一)1。文件属性对话框Type SHELLEXECUTEINFOcbSize As LongfMask As Longhwnd As LonglpVerb As StringlpFile As StringlpParameters As StringlpDirectory As StringnShow As LonghInstApp As LonglpIDList As Long 可选参数lpClass As Stri
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- vb 常用 代码 大全
限制150内