VB常用代码总结.doc

上传人:sk****8 文档编号:3543770 上传时间:2019-06-03 格式:DOC 页数:26 大小:93.50KB
下载 相关 举报
VB常用代码总结.doc_第1页
第1页 / 共26页
VB常用代码总结.doc_第2页
第2页 / 共26页
VB常用代码总结.doc_第3页
第3页 / 共26页
VB常用代码总结.doc_第4页
第4页 / 共26页
VB常用代码总结.doc_第5页
第5页 / 共26页
点击查看更多>>
资源描述

1、VB 常用代码总结原文出自木蚂蚁社区 ,本贴地址:http:/ mouseX 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 thenmoveX=me.left-mouseX+XmoveY=me.top-mouseY+Yme.move mo

2、veX,moveYend if*闪烁控件比如要闪烁一个 label(标签)添加一个时钟控件 间隔请根据实际需要设置 enabled 属性设为 true代码为:label1.visible=not label1.visible*禁止使用 Alt+F4 关闭窗口 Private Declare Function DeleteMenu Lib “user32“ (ByVal hMenu As Long, ByVal nPosition As Long, ByVal wFlags As Long) As LongPrivate Declare Function GetMenuItemCount Lib

3、 “user32“ (ByVal hMenu As Long) As LongPrivate Const MF_BYPOSITION = “)CommonDialog1.InitDir = App.PathCommonDialog1.ShowOpenIf CommonDialog1.filename “ ThenMMControl1.Command = “play“Play = TrueEnd IfElseCall Option3_ClickEnd IfEnd SubPrivate Sub Command3_Click()Play = FalseMMControl1.Command = “st

4、op“End SubPrivate Sub Command4_Click()MMControl1.Command = “pause“End SubPrivate Sub MMControl1_Done(NotifyCode As Integer)If Play And Check1.Value = vbChecked ThenPlay = FalseMMControl1.Command = “stop“MMControl1.Command = “prev“MMControl1.Command = “play“Play = TrueEnd IfEnd SubPrivate Sub MMContr

5、ol1_StatusUpdate()Label2.Caption = MMControl1.PositionEnd SubPrivate Sub Option1_Click()Check1.Enabled = TrueCheck2.Enabled = FalseMMControl1.hWndDisplay = 0End SubPrivate Sub Option2_Click()Check1.Enabled = TrueCheck2.Enabled = TrueMMControl1.hWndDisplay = Picture1.hWndEnd SubPrivate Sub Option3_Cl

6、ick()注意这里Dim R&, AA$Check1.Enabled = FalseCheck2.Enabled = FalseMMControl1.Command = “stop“Play = FalseAA = 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.Valu

7、e = vbChecked And MMControl1.filename 0 ThenMsgBox (“Fehler“)ElsePicture1.Width = (Par.rc.Right - Par.rc.Left) * 15 + 4 * 15Picture1.Height = (Par.rc.Bottom - Par.rc.Top) * 15 + 4 * 15End IfEnd Sub*通用对话框专辑(全)使用 API 调用 Winodws 各种通用对话框(Common Diaglog)的方法(一)1.文件属性对话框Type SHELLEXECUTEINFOcbSize As Longf

8、Mask As Longhwnd As LonglpVerb As StringlpFile As StringlpParameters As StringlpDirectory As StringnShow As LonghInstApp As LonglpIDList As Long 可选参数lpClass As String 可选参数hkeyClass As Long 可选参数dwHotKey As Long 可选参数hIcon As Long 可选参数hProcess As Long 可选参数End TypeConst SEE_MASK_INVOKEIDLIST = &HCConst

9、SEE_MASK_NOCLOSEPROCESS = &H40Const SEE_MASK_FLAG_NO_UI = &H400Declare Function ShellExecuteEX Lib “shell32.dll“ Alias “ShellExecuteEx“ _(SEI As SHELLEXECUTEINFO) As LongPublic Function ShowProperties(filename As String, OwnerhWnd As Long) As Long打开指定文件的属性对话框,如果返回值=32 则出错Dim SEI As SHELLEXECUTEINFOD

10、im r As LongWith SEI.cbSize = Len(SEI).fMask = SEE_MASK_NOCLOSEPROCESS Or SEE_MASK_INVOKEIDLIST Or SEE_MASK_FLAG_NO_UI.hwnd = OwnerhWnd.lpVerb = “properties“.lpFile = filename.lpParameters = vbNullChar.lpDirectory = vbNullChar.nShow = 0.hInstApp = 0.lpIDList = 0End Withr = ShellExecuteEX(SEI)ShowPro

11、perties = SEI.hInstAppEnd Function新建一个工程,添加一个按钮和名为 Text1 的文本框把以下代码置入 CommandbButton_Click 中Dim r As LongDim fname As String从 Text1 中获取文件名及路径fname = (Text1)r = ShowProperties(fname, Me.hwnd)If r = 32 Then MsgBox “Error“2.使用 Win95 的关于对话框Private Declare Function ShellAbout Lib “shell32.dll“ _Alias “She

12、llAboutA“ (ByVal hwnd As Long, ByVal szApp As String, _ByVal szOtherStuff As String, ByVal hIcon As Long) As Long示例:Dim x As Longx = shellabout (Form1.hwnd, “Visual Basic 6.0“, _“Alp Studio MouseTracker Ver 1.0“, Form1.icon)2.调用“捕获打印机端口“对话框Private Declare Function WNetConnectionDialog Lib “mpr.dll“

13、_(ByVal hwnd As Long, ByVal dwType As Long) As Long示例:Dim x As Longx = WNetConnectionDialog(Me.hwnd, 2)3.调用颜色对话框Private Type ChooseColorlStructSize As LonghwndOwner As LonghInstance As LongrgbResult As LonglpCustColors As Stringflags As LonglCustData As LonglpfnHook As LonglpTemplateName As StringEn

14、d TypePrivate Declare Function ChooseColor Lib “comdlg32.dll“ Alias “ChooseColorA“ (pChoosecolor As ChooseColor) As Long将以下代码置入某一事件中:Dim cc As ChooseColorDim CustColor(16) As Longcc.lStructSize = Len(cc)cc.hwndOwner = Form1.hWndcc.hInstance = App.hInstancecc.flags = 0cc.lpCustColors = String$(16 * 4, 0)Dim aDim xDim c1Dim c2Dim c3Dim c4a = ChooseColor(cc)ClsIf (a) ThenMsgBox “Color chosen:“ & Str$(cc.rgbResult)For x = 1 To Len(cc.lpCustColors) Step 4c1 = Asc(Mid$(cc.lpCustColors, x, 1)

展开阅读全文
相关资源
相关搜索
资源标签

当前位置:首页 > 教育教学资料库 > 精品笔记

Copyright © 2018-2021 Wenke99.com All rights reserved

工信部备案号浙ICP备20026746号-2  

公安局备案号:浙公网安备33038302330469号

本站为C2C交文档易平台,即用户上传的文档直接卖给下载用户,本站只是网络服务中间平台,所有原创文档下载所得归上传人所有,若您发现上传作品侵犯了您的权利,请立刻联系网站客服并提供证据,平台将在3个工作日内予以改正。