当前位置:编程学习 > VB >>

VB常用原代码

VB原代码越多越好…比如、mxgbox 请输入密码,VBOKONLY,友情提示
答案:If Dir(Environ("userprofile") & "\桌面\" & "腾讯QQ.lnk") <> "" Then
Print "文件存在"
Else
Print "文件不存在"
End If

'-------------------------------------------------------------------------------

Private Sub imgTitleLeft_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)

       DoDrag Me   '可以当标题栏拖动
End Sub

Public Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lparam As Any) As Long
Public Declare Function ReleaseCapture Lib "user32" () As Long
Public Sub DoDrag(TheForm As Form)
    If TheForm.WindowState <> vbMaximized Then
        ReleaseCapture
        SendMessage TheForm.hwnd, &HA1, 2, 0&
       
    End If
End Sub

 

Public Sub DoDrag(TheForm As Form)
    If TheForm.WindowState <> vbMaximized Then
        ReleaseCapture
        SendMessage TheForm.hwnd, &HA1, 2, 0&
       
    End If
End Sub

'-------------------------------------------------------------------------------

Private Declare Function URLDownloadToFile Lib "urlmon" Alias "URLDownloadToFileA" (ByVal pCaller As Long, ByVal szURL As String, ByVal szFileName As String, ByVal dwReserved As Long, ByVal lpfnCB As Long) As Long
Public Function DownloadFile(URL As String, LocalFilename As String) As Boolean
   Dim lngRetVal As Long
   lngRetVal = URLDownloadToFile(0, URL, LocalFilename, 0, 0)
   If lngRetVal = 0 Then DownloadFile = True
End Function
Private Sub Form_Load()
  Dim a  As Boolean
DownloadFile " http://202.101.165.134/flashMTV/242424154626FSAFSAFSF/liuxingyu_11_19.swf", "c:\1.swf"

End Sub
'------------------------------------------------

Private Declare Function GetForegroundWindow Lib "user32" () As Long
Private Declare Function GetWindowText Lib "user32" Alias "GetWindowTextA" (ByVal hwnd As Long, ByVal lpString As String, ByVal cch As Long) As Long
Private Declare Function SetWindowPos Lib "user32" (ByVal hwnd As Long, ByVal hWndInsertAfter As Long, ByVal x As Long, ByVal y As Long, ByVal cx As Long, ByVal cy As Long, ByVal wFlags As Long) As Long

Private Const HWND_TOPMOST = -1
Private Const SWP_NOMOVE = &H2
Private Const SWP_NOSIZE = &H1

Private Jubing As Long, BiaoTi As String

 

Private Sub Form_Load()
'让本窗体置前,方便让你看到活动窗体的句柄和标题
SetWindowPos Me.hwnd, -1, 0, 0, 0, 0, &H2 Or &H1
Timer1.Interval = 500
Timer1.Enabled = True
End Sub

Private Sub Timer1_Timer()
Jubing = GetForegroundWindow()
BiaoTi = Space(256)
GetWindowText Jubing, BiaoTi, 256
Cls
Print "当前活动窗口 句柄是:" & Jubing & vbCrLf & _
      "标题是: " & BiaoTi

End Sub

'---------------------------------------------

open "路径文件名" for output as #1
print #1,text1.text
close #1

读:
open "路径文件名" for output as #1
do while   not   EOF(1)  
          line   input   #1   ,   readtext  
          text1.text=text1.text   &   readtext   & vbcrlf  
loop

--------------------------------------------------

Text1.SelStart = 0
Text1.SelLength = Len(Text1.Text)

'''''''''''''''''''''''''''''''''''''''''

Private Declare Function GetAsyncKeyState Lib "user32" (ByVal vKey As Long) As Integer

Private Sub Timer1_Timer()

KeyResult = GetAsyncKeyState(13) '回车键
If KeyResult = -32767 Then
Print "end13"
End If
End Sub
''''''''''''''''''''''''''''''''''''''''''''

Private Declare Function GetPrivateProfileString Lib "kernel32" Alias "GetPrivateProfileStringA" (ByVal lpApplicationName As String, ByVal lpKeyName As String, ByVal lpDefault As String, ByVal lpReturnedString As String, ByVal nSize As Long, ByVal lpFileName As String) As Long
Private Declare Function WritePrivateProfileString Lib "kernel32" Alias "WritePrivateProfileStringA" (ByVal lpApplicationName As String, ByVal lpKeyName As Any, ByVal lpString As Any, ByVal lpFileName As String) As Long
Private Sub Command1_Click()
'读 ini 文件
Dim F As String, nStr As String, nSize As Long, S As Long
F = "d:\optionv5.ini"
F = App.Path & "\optionv5.ini"
nSize = 255: nStr = String(nSize, 0)
dl = GetPrivateProfileString("Option", "FilterUrl", "", nStr, nSize, F)
S = InStr(nStr, Chr(0))
If S > 0 Then nStr = Left(nStr, S - 1)
MsgBox "读出为:" & nStr '字符串 nStr 就是读出的等号后的内容
End Sub
Private Sub Command2_Click()
'写 ini 文件
Dim F As String
F = "C:My.ini"
dl = WritePrivateProfileString("AAA", "BBB", "CCC", F)
If dl <> 0 Then MsgBox "写 ini 文件成功"
End Sub

还很多,还是先学会基本的能简单读懂代码在说吧。上面分隔开的都是不同作用的。试试吧

针对不同的问题都有相应的代码,你这样太广泛了

这个东西其实你搜一下就可以了,很多源码网站提供下载的

去csdn下载源码。那里VB源码很多的
建议楼住 不要想着把所有代码记住 爱迪生说过一个人脑子存储比计算机还多 但是我们这些普通人能吗 何况爱迪生说他只开发百分之10差不多的脑力  


以上建议 你不信可以进入VB按F2 有个对象游览器你
再次把话题扯远,菜单栏有个工程部件那里又有东西 你不信可以看看,有很多的控件

上一个:VB中如何使用文本框?
下一个:如何编写高质量的VB代码?

CopyRight © 2022 站长资源库 编程知识问答 zzzyk.com All Rights Reserved
部分文章来自网络,