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)