VB与API学习笔记(1)热身

VB与API学习笔记(1)热身,第1张

概述一、句柄hwnd         handle of window 窗体(或控件)的把柄,它是一个长整型,用来标识一个窗体或控件,同一时刻没有两个句柄是一样的。                 Private Declare Function MessageBox Lib "user32" Alias "MessageBoxA" (ByVal hwnd As Long, ByVal lpText


一、句柄hwnd

handle of window 窗体(或控件)的把柄,它是一个长整型,用来标识一个窗体或控件,同一时刻没有两个句柄是一样的。

Private Declare Function MessageBox lib "user32" Alias "MessageBoxA" (ByVal hwnd As Long,ByVal lpText As String,ByVal lpCaption As String,ByVal wType As Long) As Long


1、lib部分:来由哪个库(dll),常见如下:

Kernel32.dll windows核心函数库

User32.dll 使用者 *** 作界面函数库

Gdi32.dll 图形外部界面函数库

Comdlg.dll 通用对话框函数库 common dialog

Shell32.dll shell界面函数库

winmm.dll 多媒体函数库 windows multimedia

AdvAPI.dll 高级API函数库Advanced windows 32 Base API DLL

Lz32.dll 压缩及解压函数库

2、Alias部分:库中名为什么。若外面名与库内名一致,此部分省略

3、参数及返回值。



二、参数

参数前未标明的是传址方式,byval是传值方式。有时类型是Any时需小心。

字符串与定长字符串的区别。

'获取计算机名'lpBuffer 字串指针'nSize    字串总长度Private Declare Function GetComputername lib "kernel32" Alias "GetComputernameA" (ByVal lpBuffer As String,nSize As Long) As LongPrivate Sub Command1_Click()    Dim s As String,lngSize As Long    lngSize = 255    s = String(lngSize,0) '格式化255个空字符    GetComputername s,lngSize    s = left$(s,lngSize)    Text1.Text = sEnd Sub

'获取鼠标位置'pointAPI中x,y分别是屏幕像素位置'返回值 Long,非零表示成功,零表示失败。Private Declare Function GetCursorPos lib "user32" (lpPoint As POINTAPI) As LongPrivate Type POINTAPI    X As Long    Y As LongEnd TypeDim p As POINTAPIPrivate Sub Form_MouseMove(button As Integer,Shift As Integer,X As Single,Y As Single)    Dim a As Long    GetCursorPos p    Text1.Text = p.X & "," & p.YEnd Sub


'取得系统目录'长度取260Private Declare Function GetSystemDirectory _                lib "kernel32" _                Alias "GetSystemDirectoryA" (ByVal lpBuffer As String,_                                             ByVal nSize As Long) As LongPrivate Const MAX_PATH = 260Private Sub Command1_Click()    Dim s As String,max As Long    s = String$(MAX_PATH,0)    max = GetSystemDirectory(s,MAX_PATH)    Text1.Text = left$(s,InStr(s,Chr(0)) - 1) '截取字串End Sub

'取得windows目录'长度取260Private Declare Function GetwindowsDirectory lib "kernel32" Alias "GetwindowsDirectoryA" (ByVal lpBuffer As String,ByVal nSize As Long) As LongPrivate Const MAX_PATH = 260Private Sub Command1_Click()    Dim s As String,0)    max = GetwindowsDirectory(s,Chr(0)) - 1) '截取字串End Sub

'取得 *** 作系统版本,判断是什么 *** 作系统'Operating system Version number'windows 8 6.2'windows 7 6.1'windows Server 2008 R2 6.1'windows Server 2008 6.0'windows Vista 6.0'windows Server 2003 R2 5.2'windows Server 2003 5.2'windows XP 5.1'windows 2000 5.0Private Declare Function GetVersionEx _                lib "kernel32" _                Alias "GetVersionExA" (lpVersioninformation As OsveRSIONINFO) As LongPrivate Type OsveRSIONINFO    DWOsversionInfoSize As Long    DWMajorVersion As Long    DWMinorVersion As Long    DWBuildNumber As Long    DWPlatformID As Long    szCSDVersion As String * 128      '  Maintenance string for PSS usageEnd TypePrivate Sub Command1_Click()    Dim ver As OsveRSIONINFO    ver.DWOsversionInfoSize = Len(ver)    GetVersionEx ver    Text1.Text = ver.DWMajorVersion & "." & ver.DWMinorVersion & "." & ver.DWBuildNumber & " " & ver.DWPlatformIDEnd Sub
总结

以上是内存溢出为你收集整理的VB与API学习笔记(1)热身全部内容,希望文章能够帮你解决VB与API学习笔记(1)热身所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/langs/1279639.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-06-09
下一篇 2022-06-09

发表评论

登录后才能评论

评论列表(0条)

保存