API 函数集锦
时 间:2007-10-18 13:22:27
作 者:竹笛 ID:8 城市:上海 QQ:2851379730
摘 要:API 函数集锦
正 文:
1、如何让窗体总在最前面?
*API函数声明
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 SWP_NOSIZE = &H1
Private Const SWP_NOMOVE = &H2
Private Const HWND_TOPMOST = -1
Private Const HWND_NOTOPMOST = -2
注释: 在某个form里写:
SetWindowPos me.hWnd,WND_TOPMOST,0,0,0,0, SWP_NOMOVE 注释:或下面
SetWindowPos me.hWnd,WND_TOPMOST,0,0,0,0, SWP_NOSIZE
2、使用API函数sendmessage,获得光标所在行和列。
Sub getcaretpos(byval TextHwnd&,LineNo&,ColNo&)
注释:TextHwnd为TextBox的hWnd属性值, LineNo为所在行数,ColNo为列数
dim I&,j&,k& 注释:获取起始位置到光标所在位置字节数 I=SendMessage(TextHwnd,&HB0&,0,0) j=I/2^16 注释:确定所在行 LineNo=SendMessage(TextHwnd,&HC9&,j,0)+1
注释:确定所在列
k=SendMessage(TextHwnd,&HBB&,-1,0)
ColNo=j-k+1
End sub
3、如何以某种颜色填充某区域?
*API函数声明
Private Declare Sub FloodFill Lib "gdi32" _ (ByVal Hdc As Long, ByVal X As Long, ByVal Y As _ Long, ByVal crColor As Long
注释:设(fillx,filly)为此区域内任一点
注释:Color为某种颜色
FloodFill Picture1.Hdc, fillx, filly,Color
4、如何关闭计算机?
*API函数声明
Declare Function ExitWindows Lib "User" (ByVal dwReturnCode As Long, ByVal wReserved As Integer) As Integer
注释:执行
Dim DUMMY
DUMMY=ExitWindows(0,0)
5、如何获取Windows目录和System目录?
注释:复制以下代码到一模块中
Public Declare Function GetWindowsDirectory Lib "kernel32" Alias "GetWindowsDirectoryA" (ByVal lpBuffer As String, ByVal nSize As Long) As Long
Public Declare Function GetSystemDirectory Lib "kernel32" Alias "GetSystemDirectoryA" (ByVal lpBuffer As String, ByVal nSize As Long) As Long
注释:在程序中调用
Dim WindowsDirectory As String, SystemDirectory As String, x As Long
WindowsDirectory = Space(255)
SystemDirectory = Space(255)
x = GetWindowsDirectory(WindowsDirectory, 255)
x = GetSystemDirectory(SystemDirectory, 255)
MsgBox "Windows的安装目录是:" + WindowsDirectory+",系统目录是:" + SystemDirectory
6、如何建立简单的超级连接?
*API函数声明
Private Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecute A" (ByVal hWnd As Long, ByVal lpOperation As String, ByVal lpFile As String, ByVal lpParameters As String, ByVal lpDirectory As String, ByVal nShowCmd A s Long) As Long
注释:打开某个网址
ShellExecute 0, "open", "http://tyvb.126.com", vbNullString, vbNullString, 3
注释:给某个信箱发电子邮件
ShellExecute hwnd, "open", "mailto:sst95@21cn.com", vbNullString, vbNullString, 0
7、如何得知TextBox中文字所有的行数?
*API函数声明
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 Const EM_GETLINECOUNT = &HBA
注释:在程序中调用
LineCnt = SendMessage(ctl.hwnd, EM_GETLINECOUNT, 0, 0)
注释:LineCnt即为此TextBox的行数。
8、如何设置ListBox的水平卷动轴的宽度?
*API函数声明
Const LB_SETHORIZONTALEXTENT = &H194
Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" _ (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, _ lParam As Any) As Long
注释:调用
Call SendMessage(List1.hwnd, LB_SETHORIZONTALEXTENT, 400, ByVal 0&)
注释:注意400是以象素为单位,你可以根据情况自行设定。
9、如何交换鼠标按键?
*API函数声明
Declare Function SwapMouseButton& Lib "user32" _ (ByVal bSwap as lo
Access软件网QQ交流群 (群号:54525238) Access源码网店
常见问答:
技术分类:
源码示例
- 【源码QQ群号19834647...(12.17)
- Access对子窗体数据进行批...(10.30)
- 最精简的组合框行来源数据快速输...(10.25)
- Access仿平台的多值选择器...(10.24)
- 【Access日期区间段查询】...(10.22)
- 【Access源码示例】VBA...(10.12)
- Access累乘示例,Acce...(10.09)
- 数值8.88,把整数8去掉,转...(10.08)
- 【Access自定义函数】一个...(09.30)
- 【Access选项卡示例】Ac...(09.09)
学习心得
最新文章
- Access快速开发平台企业版--...(11.18)
- 不会用多表联合查询,多表查询没结果...(11.16)
- 【案例分享】主键字段值含有不间断空...(11.16)
- Access快速开发平台--后台D...(11.14)
- 微软Access邀测新Monaco...(11.12)
- Access列表框左右互选、列表框...(11.11)
- 高效率在导入数据前删除记录(11.10)
- Access报价单转订单示例代码(11.08)
- Access系统自带的日期选择器不...(11.08)
- 分享一下Access工程中的acw...(11.07)