Windows API函数大全
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
Windows API函数
我们知道VB可以做很多事,但是有些事情,特别是涉及对Windows操作系统的访问,还需要借助Win32 API函数(Microsoft Win32 Application Programming Interface的缩写)。
API函数是一组用C语言编写的函数,总共约有一千来个。
原本是为C语言编程人员而编写的,但也可以在VB应用程序中调用。
按功能划分,Win32 API函数大致涉及以下几个方面:窗口管理、图形设备接口、系统管理和多媒体技术。
Win32 API函数以动态链接库DLL提供给用户,可以在任何语言中调用。
DLL在程序运行时装入,随时响应程序的调用,不必在设计时就将文件存放在工程中,这就是动态链接的意思。
正因为如此,一个DLL程序可以同时为多个程序所调用。
在VB中引用API函数,需要事先通过Declare函数,声明要引用的DLL文件名称以及相应函数的参量。
然后便可像使用VB函数一样使用API函数。
我们看以下类似的声明语句:
Declare Function GetComputerName Lib "kernel32" Alias "GetComputerNameA" (ByVal lpBuffer As String, nSize As Long) As Long
GetComputerName是API函数名,kernel32是库名。
括号中的ByVal lpBuffer As String, nSize As Long就是函数的参量。
最后面的Long表示函数返回值的数据类型。
本节通过例子说明Win32 API函数的应用。
Windows在创建每个窗体时,都会赋给它一个与众不同的编号,这就是窗体的句柄。
在Windows中,窗体与控件都被看成是窗体(窗口)。
窗体的句柄保存在自己的hwnd属性中。
一.GetComputerName
二、GetCursorPos
三、GetWindowsDirectory
Windows API函数四、ClipCursor
五、GetProfileInt
六、GetProfileString
七、Polygon
Windows API函数八、SendMessage
Public Enum VBWin_Msg
WM_NULL = &H0
WM_CREATE = &H1
WM_DESTROY = &H2
WM_MOVE = &H3
WM_SIZE = &H5
WM_ACTIVATE = &H6
WM_SETFOCUS = &H7
WM_KILLFOCUS = &H8
WM_ENABLE = &HA
WM_SETREDRAW = &HB
WM_SETTEXT = &HC
WM_GETTEXTLENGTH = &HE
WM_PAINT = &HF
WM_CLOSE = &H10
WM_QUERYENDSESSION = &H11
WM_QUIT = &H12
WM_QUERYOPEN = &H13
WM_ERASEBKGND = &H14
WM_SYSCOLORCHANGE = &H15
WM_ENDSESSION = &H16
WM_SHOWWINDOW = &H18
WM_WININICHANGE = &H1A
WM_DEVMODECHANGE = &H1B
WM_ACTIVATEAPP = &H1C
WM_FONTCHANGE = &H1D
WM_TIMECHANGE = &H1E
WM_CANCELMODE = &H1F
WM_SETCURSOR = &H20
WM_MOUSEACTIVATE = &H21
WM_CHILDACTIVATE = &H22
WM_QUEUESYNC = &H23
WM_GETMINMAXINFO = &H24
'begin_r_winuser
WM_PAINTICON = &H26
WM_ICONERASEBKGND = &H27
WM_NEXTDLGCTL = &H28
WM_SPOOLERSTATUS = &H2A
WM_DRAWITEM = &H2B
WM_MEASUREITEM = &H2C
WM_DELETEITEM = &H2D
WM_VKEYTOITEM = &H2E
WM_CHARTOITEM = &H2F
WM_SETFONT = &H30
WM_GETFONT = &H31
WM_SETHOTKEY = &H32
WM_GETHOTKEY = &H33
WM_QUERYDRAGICON = &H37
WM_COMPAREITEM = &H39
WM_COMPACTING = &H41
WM_COMMNOTIFY = &H44 '/* no longer s uported */
WM_WINDOWPOSCHANGING = &H46
WM_WINDOWPOSCHANGED = &H47
WM_POWER = &H48
WM_CANCELJOURNAL = &H4B
'end_r_winuser
'lParam of WM_COPYDATA message points to...
'begin_r_winuser
' '#if(WINVER > = 0x0400)
WM_NOTIFY = &H4E
WM_INPUTLANGCHANGEREQUEST = &H50
WM_INPUTLANGCHANGE = &H51
WM_TCARD = &H52
WM_HELP = &H53
WM_USERCHANGED = &H54
WM_NOTIFYFORMAT = &H55
WM_CONTEXTMENU = &H7B
WM_STYLECHANGING = &H7C
WM_STYLECHANGED = &H7D
WM_DISPLAYCHANGE = &H7E
WM_GETICON = &H7F
WM_SETICON = &H80
' '#endif /* WINVER > = 0x0400 */
WM_NCCREATE = &H81
WM_NCDESTROY = &H82
WM_NCCALCSIZE = &H83
WM_NCHITTEST = &H84
WM_NCPAINT = &H85
WM_NCACTIVATE = &H86
WM_GETDLGCODE = &H87
WM_SYNCPAINT = &H88
WM_NCMOUSEMOVE = &HA0
WM_NCLBUTTONDOWN = &HA1
WM_NCLBUTTONUP = &HA2
WM_NCLBUTTONDBLCLK = &HA3
WM_NCRBUTTONDOWN = &HA4
WM_NCRBUTTONUP = &HA5
WM_NCRBUTTONDBLCLK = &HA6
WM_NCMBUTTONDOWN = &HA7
WM_NCMBUTTONUP = &HA8
WM_NCMBUTTONDBLCLK = &HA9
WM_KEYFIRST = &H100
WM_KEYDOWN = &H100
WM_KEYUP = &H101
WM_CHAR = &H102
WM_SYSKEYDOWN = &H104
WM_SYSKEYUP = &H105
WM_SYSCHAR = &H106
WM_SYSDEADCHAR = &H107
WM_KEYLAST = &H108
' '#if(WINVER > = 0x0400)
WM_IME_STARTCOMPOSITION = &H10D
WM_IME_ENDCOMPOSITION = &H10E
WM_IME_COMPOSITION = &H10F
WM_IME_KEYLAST = &H10F
' '#endif /* WINVER > = 0x0400 */
WM_INITDIALOG = &H110
WM_COMMAND = &H111
WM_SYSCOMMAND = &H112
WM_TIMER = &H113
WM_HSCROLL = &H114
WM_VSCROLL = &H115
WM_INITMENU = &H116
WM_INITMENUPOPUP = &H117
WM_MENUSELECT = &H11F
WM_MENUCHAR = &H120
WM_ENTERIDLE = &H121
'#if(WINVER > = 0x0500)
WM_MENURBUTTONUP = &H122
WM_MENUDRAG = &H123
WM_MENUGETOBJECT = &H124
WM_UNINITMENUPOPUP = &H125
WM_MENUCOMMAND = &H126
'#endif /* WINVER > = 0x0500 */
WM_CTLCOLORMSGBOX = &H132
WM_CTLCOLOREDIT = &H133
WM_CTLCOLORLISTBOX = &H134
WM_CTLCOLORBTN = &H135
WM_CTLCOLORDLG = &H136
WM_CTLCOLORSCROLLBAR = &H137
WM_CTLCOLORSTATIC = &H138
WM_MOUSEFIRST = &H200
WM_LBUTTONDOWN = &H201
WM_LBUTTONUP = &H202
WM_LBUTTONDBLCLK = &H203
WM_RBUTTONDOWN = &H204
WM_RBUTTONUP = &H205
WM_RBUTTONDBLCLK = &H206
WM_MBUTTONDOWN = &H207
WM_MBUTTONUP = &H208
WM_MBUTTONDBLCLK = &H209
'#if (_WIN32_WINNT > = 0x0400) || (_WIN32_WINDOWS > 0x0400)
WM_MOUSEWHEEL = &H20A
WM_MOUSELAST = &H20A
'#Else
' WM_MOUSELAST = &H209
'#endif /* if (_WIN32_WINNT < 0x0400) */
'#if(_WIN32_WINNT > = 0x0400)
'#define WHEEL_DELTA 120 /* Value for rolli ng one detent */
'#endif /* _WIN32_WINNT > = 0x0400 */
'#if(_WIN32_WINNT > = 0x0400)
'#define WHEEL_PAGESCROLL (UINT_MAX) /* Scroll one page */
'#endif /* _WIN32_WINNT > = 0x0400 */
WM_PARENTNOTIFY = &H210
WM_ENTERMENULOOP = &H211
WM_EXITMENULOOP = &H212
'#if(WINVER > = 0x0400)
WM_NEXTMENU = &H213
'// end_r_winuser
WM_DEVICECHANGE = &H219
'#endif /* WINVER > = 0x0400 */
WM_MDICREATE = &H220
WM_MDIDESTROY = &H221
WM_MDIACTIVATE = &H222
WM_MDIRESTORE = &H223
WM_MDINEXT = &H224
WM_MDIMAXIMIZE = &H225
WM_MDITILE = &H226
WM_MDICASCADE = &H227
WM_MDIICONARRANGE = &H228
WM_MDIGETACTIVE = &H229
WM_MDISETMENU = &H230
WM_ENTERSIZEMOVE = &H231
WM_EXITSIZEMOVE = &H232
WM_DROPFILES = &H233
WM_MDIREFRESHMENU = &H234
'#if(WINVER > = 0x0400)
WM_IME_SETCONTEXT = &H281
WM_IME_NOTIFY = &H282
WM_IME_CONTROL = &H283
WM_IME_COMPOSITIONFULL = &H284
WM_IME_SELECT = &H285
WM_IME_CHAR = &H286
'#endif /* WINVER > = 0x0400 */
'#if(WINVER > = 0x0500)
WM_IME_REQUEST = &H288
'#endif /* WINVER > = 0x0500 */
'#if(WINVER > = 0x0400)
WM_IME_KEYDOWN = &H290
WM_IME_KEYUP = &H291
'#endif /* WINVER > = 0x0400 */
'#if(_WIN32_WINNT > = 0x0400)
WM_MOUSEHOVER = &H2A1
WM_MOUSELEAVE = &H2A3
'#endif /* _WIN32_WINNT > = 0x0400 */
WM_CUT = &H300
WM_COPY = &H301
WM_PASTE = &H302
WM_CLEAR = &H303
WM_UNDO = &H304
WM_RENDERFORMAT = &H305
WM_RENDERALLFORMATS = &H306
WM_DESTROYCLIPBOARD = &H307
WM_DRAWCLIPBOARD = &H308
WM_PAINTCLIPBOARD = &H309
WM_VSCROLLCLIPBOARD = &H30A
WM_SIZECLIPBOARD = &H30B
WM_ASKCBFORMATNAME = &H30C
WM_CHANGECBCHAIN = &H30D
WM_HSCROLLCLIPBOARD = &H30E
WM_QUERYNEWPALETTE = &H30F
WM_PALETTEISCHANGING = &H310
WM_PALETTECHANGED = &H311
WM_HOTKEY = &H312
'#if(WINVER > = 0x0400)
WM_PRINT = &H317
WM_PRINTCLIENT = &H318
WM_HANDHELDFIRST = &H358
WM_HANDHELDLAST = &H35F
WM_AFXFIRST = &H360
WM_AFXLAST = &H37F
'#endif /* WINVER > = 0x0400 */
WM_PENWINFIRST = &H380
WM_PENWINLAST = &H38F
WM_USER = &H400
Public Enum eWM_Msg
WM_NULL = &H0
WM_CREATE = &H1
WM_DESTROY = &H2
WM_MOVE = &H3
WM_SIZE = &H5
WM_ACTIVATE = &H6
WM_SETFOCUS = &H7
WM_KILLFOCUS = &H8
WM_USER = &H400
End Enum
九、GlobalMemoryStatus
十、GetSystemMenu
十一、GetMenuItemInfo
十二、SetMenuItemInfo
十三、SetCursorPos
十四、SetWindowPos
十五、GetUserName。