暂无图片
暂无图片
暂无图片
暂无图片
暂无图片

64位Office API声明语句第94讲

VBA语言専攻 2022-08-21
162
【分享成果,随喜正能量】不要去要求别人理解你、共情你、尊重你。这是弱者的思维。强者不会这样做。 所谓强者,就是能承受更多压力,能接受更多不公,能忍受更多委屈。不怕被利用,就怕你没用。 。
跟我学VBA,我这里专注VBA, 授人以渔。我98年开始,从源码接触VBA已经20余年了,随着年龄的增长,越来越觉得有必要把这项技能传递给需要这项技术的职场人员。希望职场和数据打交道的朋友,都来学习VBA,利用VBA,起码可以提高自己的工作效率,可以有时间多陪陪父母,多陪陪家人,何乐而不为呢?
这讲我们继续学习64位Office API声明语句第94讲,这些内容是MS的权威资料,看似枯燥,但对于想学习API函数的朋友是非常有用的。
当学员学习到高级阶段,如果引用API,这个资料可以直接查到64位写法。大多数情况下我们是将低版本的程序文件升级到高版本,这时您就不必为如下的错误提示所困扰了:




'  timer error return values
Const TIMERR_NOERROR = (0)  '  no error
Const TIMERR_NOCANDO = (TIMERR_BASE + 1) '  request not completed
Const TIMERR_STRUCT = (TIMERR_BASE + 33) '  time struct size

'  flags for wFlags parameter of timeSetEvent() function
Const TIME_ONESHOT = 0  '  program timer for single event
Const TIME_PERIODIC = 1  '  program for continuous periodic event

Type TIMECAPS
        wPeriodMin As Long
        wPeriodMax As Long
End Type

Declare PtrSafe Function timeGetSystemTime Lib "winmm.dll" Alias "timeGetSystemTime" (lpTime As MMTIME, ByVal uSize As Long) As Long
Declare PtrSafe Function timeGetTime Lib "winmm.dll" Alias "timeGetTime" () As Long
Declare PtrSafe Function timeSetEvent Lib "winmm.dll" Alias "timeSetEvent" (ByVal uDelay As Long, ByVal uResolution As Long, ByVal lpFunction As LongPtr, ByVal dwUser As LongPtr, ByVal uFlags As Long) As Long
Declare PtrSafe Function timeKillEvent Lib "winmm.dll" Alias "timeKillEvent" (ByVal uID As Long) As Long
Declare PtrSafe Function timeGetDevCaps Lib "winmm.dll" Alias "timeGetDevCaps" (lpTimeCaps As TIMECAPS, ByVal uSize As Long) As Long
Declare PtrSafe Function timeBeginPeriod Lib "winmm.dll" Alias "timeBeginPeriod" (ByVal uPeriod As Long) As Long
Declare PtrSafe Function timeEndPeriod Lib "winmm.dll" Alias "timeEndPeriod" (ByVal uPeriod As Long) As Long

'  joystick error return values
Const JOYERR_NOERROR = (0)  '  no error
Const JOYERR_PARMS = (JOYERR_BASE + 5) '  bad parameters
Const JOYERR_NOCANDO = (JOYERR_BASE + 6) '  request not completed
Const JOYERR_UNPLUGGED = (JOYERR_BASE + 7) '  joystick is unplugged

'  constants used with JOYINFO structure and MM_JOY messages
Const JOY_BUTTON1 = &H1
Const JOY_BUTTON2 = &H2
Const JOY_BUTTON3 = &H4
Const JOY_BUTTON4 = &H8
Const JOY_BUTTON1CHG = &H100
Const JOY_BUTTON2CHG = &H200
Const JOY_BUTTON3CHG = &H400
Const JOY_BUTTON4CHG = &H800

'  joystick ID constants
Const JOYSTICKID1 = 0
Const JOYSTICKID2 = 1

Type JOYCAPS
        wMid As Integer
        wPid As Integer
        szPname(0 To MAXPNAMELEN - 1) As Byte
        wXmin As Long
        wXmax As Long
        wYmin As Long
        wYmax As Long
        wZmin As Long
        wZmax As Long
        wNumButtons As Long
        wPeriodMin As Long
        wPeriodMax As Long
'#if (WINVER >= 0x0400)
        wRmin As Long
        wRmax As Long
        wUmin As Long
        wUmax As Long
        wVmin As Long
        wVmax As Long
        wCaps As Long
        wMaxAxes As Long
        wNumAxes As Long
        wMaxButtons As Long
        szRegKey(0 To MAXPNAMELEN - 1) As Byte
        szOEMVxD(0 To MAX_JOYSTICKOEMVXDNAME - 1) As Byte
'#endif
End Type

Declare PtrSafe Function joyGetDevCaps Lib "winmm.dll" Alias "joyGetDevCapsA" (ByVal id As LongPtr, lpCaps As JOYCAPS, ByVal uSize As Long) As Long

Declare PtrSafe Function joyGetNumDevs Lib "winmm.dll" Alias "joyGetNumDev" () As Long
Declare PtrSafe Function joyGetThreshold Lib "winmm.dll" Alias "joyGetThreshold" (ByVal id As Long, lpuThreshold As Long) As Long
Declare PtrSafe Function joyReleaseCapture Lib "winmm.dll" Alias "joyReleaseCapture" (ByVal id As Long) As Long
Declare PtrSafe Function joySetCapture Lib "winmm.dll" Alias "joySetCapture" (ByVal hwnd As LongPtr, ByVal uID As Long, ByVal uPeriod As Long, ByVal bChanged As Long) As Long
Declare PtrSafe Function joySetThreshold Lib "winmm.dll" Alias "joySetThreshold" (ByVal id As Long, ByVal uThreshold As Long) As Long

'  MMIO error return values
Const MMIOERR_BASE = 256
Const MMIOERR_FILENOTFOUND = (MMIOERR_BASE + 1)  '  file not found
Const MMIOERR_OUTOFMEMORY = (MMIOERR_BASE + 2)  '  out of memory
Const MMIOERR_CANNOTOPEN = (MMIOERR_BASE + 3)  '  cannot open
Const MMIOERR_CANNOTCLOSE = (MMIOERR_BASE + 4)  '  cannot close
Const MMIOERR_CANNOTREAD = (MMIOERR_BASE + 5)  '  cannot read
Const MMIOERR_CANNOTWRITE = (MMIOERR_BASE + 6) '  cannot write
Const MMIOERR_CANNOTSEEK = (MMIOERR_BASE + 7)  '  cannot seek
Const MMIOERR_CANNOTEXPAND = (MMIOERR_BASE + 8)  '  cannot expand file
Const MMIOERR_CHUNKNOTFOUND = (MMIOERR_BASE + 9)  '  chunk not found
Const MMIOERR_UNBUFFERED = (MMIOERR_BASE + 10) '  file is unbuffered

'  MMIO constants
Const CFSEPCHAR = "+"  '  compound file name separator char.

Type MMIOINFO
        dwFlags As Long
        fccIOProc As Long
        pIOProc As LongPtr
        wErrorRet As Long
        htask As LongPtr
        cchBuffer As Long
        pchBuffer As String
        pchNext As String
        pchEndRead As String
        pchEndWrite As String
        lBufOffset As Long
        lDiskOffset As Long
        adwInfo(0 To 2) As Long
        dwReserved1 As Long
        dwReserved2 As Long
        hmmio As LongPtr
End Type

Const MMIO_RWMODE = &H3         '  mask to get bits used for opening
                                        '  file for reading/writing/both
Const MMIO_SHAREMODE = &H70        '  file sharing mode number

'  constants for dwFlags field of MMIOINFO
Const MMIO_CREATE = &H1000      '  create new file (or truncate file)
Const MMIO_PARSE = &H100       '  parse new file returning path
Const MMIO_DELETE = &H200       '  create new file (or truncate file)
Const MMIO_EXIST = &H4000      '  checks for existence of file
Const MMIO_ALLOCBUF = &H10000     '  mmioOpen() should allocate a buffer
Const MMIO_GETTEMP = &H20000     '  mmioOpen() should retrieve temp name

Const MMIO_DIRTY = &H10000000  '  I/O buffer is dirty
'  MMIO_DIRTY is also used in thefield of MMCKINFO structure

Const MMIO_OPEN_VALID = &H3FFFF     '  valid flags for mmioOpen ;Internal

'  read/write mode numbers (bit field MMIO_RWMODE)
Const MMIO_READ = &H0         '  open file for reading only
Const MMIO_WRITE = &H1         '  open file for writing only
Const MMIO_READWRITE = &H2         '  open file for reading and writing

'  share mode numbers (bit field MMIO_SHAREMODE)
Const MMIO_COMPAT = &H0         '  compatibility mode
Const MMIO_EXCLUSIVE = &H10        '  exclusive-access mode
Const MMIO_DENYWRITE = &H20        '  deny writing to other processes
Const MMIO_DENYREAD = &H30        '  deny reading to other processes
Const MMIO_DENYNONE = &H40        '  deny nothing to other processes

'  flags for other functions
Const MMIO_FHOPEN = &H10    '  mmioClose(): keep file handle open
Const MMIO_EMPTYBUF = &H10    '  mmioFlush(): empty the I/O buffer
Const MMIO_TOUPPER = &H10    '  mmioStringToFOURCC(): cvt. to u-case
Const MMIO_INSTALLPROC = &H10000     '  mmioInstallIOProc(): install MMIOProc
Const MMIO_PUBLICPROC = &H10000000  '  mmioInstallIOProc: install Globally
Const MMIO_UNICODEPROC = &H1000000   '  mmioInstallIOProc(): Unicode MMIOProc
Const MMIO_REMOVEPROC = &H20000     '  mmioInstallIOProc(): remove MMIOProc
Const MMIO_FINDPROC = &H40000     '  mmioInstallIOProc(): find an MMIOProc
Const MMIO_FINDCHUNK = &H10    '  mmioDescend(): find a chunk by ID
Const MMIO_FINDRIFF = &H20    '  mmioDescend(): find a LIST chunk
Const MMIO_FINDLIST = &H40    '  mmioDescend(): find a RIFF chunk
Const MMIO_CREATERIFF = &H20    '  mmioCreateChunk(): make a LIST chunk
Const MMIO_CREATELIST = &H40    '  mmioCreateChunk(): make a RIFF chunk

Const MMIO_VALIDPROC = &H11070000  '  valid for mmioInstallIOProc ;Internal

'  message numbers for MMIOPROC I/O procedure functions
Const MMIOM_READ = MMIO_READ  '  read (must equal MMIO_READ!)
Const MMIOM_WRITE = MMIO_WRITE  '  write (must equal MMIO_WRITE!)
Const MMIOM_SEEK = 2  '  seek to a new position in file
Const MMIOM_OPEN = 3  '  open file
Const MMIOM_CLOSE = 4  '  close file
Const MMIOM_WRITEFLUSH = 5  '  write and flush
Const MMIOM_RENAME = 6  '  rename specified file
Const MMIOM_USER = &H8000&  '  beginning of user-defined messages

'  flags for mmioSeek()
Const SEEK_SET = 0  '  seek to an absolute position
Const SEEK_CUR = 1  '  seek relative to current position
Const SEEK_END = 2  '  seek relative to end of file

'  other constants
Const MMIO_DEFAULTBUFFER = 8192  '  default buffer size

Type MMCKINFO
    ckid As Long
    ckSize As Long
    fccType As Long
    dwDataOffset As Long
    dwFlags As Long
End Type

Declare PtrSafe Function mmioStringToFOURCC Lib "winmm.dll" Alias "mmioStringToFOURCCA" (ByVal sz As String, ByVal uFlags As Long) As Long

Declare PtrSafe Function mmioOpen Lib "winmm.dll" Alias "mmioOpenA" (ByVal szFileName As String, lpmmioinfo As MMIOINFO, ByVal dwOpenFlags As Long) As LongPtr

Declare PtrSafe Function mmioRename Lib "winmm.dll" Alias "mmioRenameA" (ByVal szFileName As String, ByVal SzNewFileName As String, lpmmioinfo As MMIOINFO, ByVal dwRenameFlags As Long) As Long

Declare PtrSafe Function mmioClose Lib "winmm.dll" Alias "mmioClose" (ByVal hmmio As LongPtr, ByVal uFlags As Long) As Long
Declare PtrSafe Function mmioRead Lib "winmm.dll" Alias "mmioRead" (ByVal hmmio As LongPtr, ByVal pch As String, ByVal cch As Long) As Long
Declare PtrSafe Function mmioWrite Lib "winmm.dll" Alias "mmioWrite" (ByVal hmmio As LongPtr, ByVal pch As String, ByVal cch As Long) As Long
Declare PtrSafe Function mmioSeek Lib "winmm.dll" Alias "mmioSeek" (ByVal hmmio As LongPtr, ByVal lOffset As Long, ByVal iOrigin As Long) As Long




我20多年的VBA实践经验,全部浓缩在下面的各个教程中:

【分享成果,随喜正能量】非黑即白,非左即右,非朋友即敌人,非圣人即恶棍,是很幼稚而危险的思维,一定要警惕。 这个时代的最大好处是,你可以跟志趣相投的人聚集,远离三观迥异的人。你一定要跟后者纠缠,是你的问题。保持情绪稳定。坚持做正确的事,然后交给时间。 。
文章转载自VBA语言専攻,如果涉嫌侵权,请发送邮件至:contact@modb.pro进行举报,并提供相关证据,一经查实,墨天轮将立刻删除相关内容。

评论