Thread View: cn.bbs.comp.program
1 messages
1 total messages
Started by ���ܵ�Сʨ
Sat, 18 Apr 1998 00:00
Visual Basic����Windows API�����Ӧ�þ���
Author: ���ܵ�Сʨ
Date: Sat, 18 Apr 1998 00:00
Date: Sat, 18 Apr 1998 00:00
152 lines
8094 bytes
8094 bytes
���Ľ���������Visual Basic(���¼��VB)���� Windows API����
�ķ���,��ͨ�������ܲ���API����Ĺ��ܡ�
����VB����API������
1.��Declare���������Ҫ���õ�API����,���ú�������ֵ,��
����ΪSub���;���з���ֵ,�������ΪFunction�������е�API��
����������� \VB\WINAPI\WIN31API.HLP��, ֻ����Copy�� Paste��
�ɷŵ���Ӧ�ĵط���
2.һ��������ijһ��API�����,�Ϳ��������VB�ĺ���һ�����
����ע��,������ݲ���,���ܻᵼ������
VB����˽�г�ʼ������Ĵ�ȡ
Windows����ij�ʼ������Ļ�ȡ�뱣����ͨ���ȡ��չ��Ϊ .I
NI���ı��ļ���ʵ�ֵ�,����������ǰ�ȴ�ָ����.INI�ļ���������
����IJ���,����ӳ����������л�����;�������˳�ʱ�ֽ���ǰ�Ļ�
������浽ָ����.INI�ļ��С�Windows�ṩ��API�����е�GetPr
ivateProfileString��WritePrivateProfileString ������Щ���ܡ�
������һ��Ҫ˵��
1.GetPrivateProfileString
����:Declare Function GetPrivateProfileString Lib "kerne
l32"Alias"GetPrivat eProfileStringA"(ByVal lpApplicationName
As String,ByVal lpKeyName As Any,ByVal lpDefault As String
, ByVal lpReturnedString As String, ByVal nSize As Long,ByV
al lpFileName As String) As Long
����:��ȡ.INI�ļ�����ָ���ؼ��ֶ�Ӧ�IJ���(�ַ�) ������
�����lpReturne dString��
��1
2.WritePrivateProfileString
����:Declare Function WritePrivateProfileString Lib "ker
nel32" Alias"WriteP rivateProfileStringA" (ByVal lpApplicati
onName As String, ByVal lpKeyName AsAny , ByVal lpString As
Any, ByVal lpFileName As String) As Long
����:�ڳ�ʼ���ļ���ָ���ؼ����������ò���(�ַ�)��
����ֵ:������óɹ�,����TRUE;����FALSE��
VB��ǰϵͳ��Ϣ
�����API������GetWindowsDirectory,GetWinFlags,GetVersio
n,GetSystemDirector y��,�����ʹ�÷���������˵������:
1.������Ŀ�ļ�DEMO.PRJ;����ģ���ļ�DEMO.BAS.������������
���뵽DEMO.BAS �С�
Declare Function GetWindowsDirectory Lib "kernel32" Alia
s "GetWindowsDirect oryA" (ByVal lpBuffer As String, ByVal n
Size As Long) As Long
Declare Function GetPrivateProfileString Lib "kernel32"
Alias "GetPrivatePr ofileStringA" (ByVal lpApplicationName A
s String, ByVal lpKeyName As Any, ByVal lpDefault As String,
ByVal lpReturnedString As String, ByVal nSize As Long, ByV
al lpFileName As String) As Long
Declare Function WritePrivateProfileString Lib "kernel32
" Alias "WritePriva teProfileStringA" (ByVal lpApplicationNa
me As String, ByVal lpKeyName As Any,By Val lpString As Any,
ByVal lpFileName As String) As Long
Declare Function GetKeyboardType Lib "user32" (ByVal nTy
peFlag As Long) AsL ongDeclare Function GetSystemDirectory L
ib "kernel32" Alias "GetSystemDirectory A" (ByVal lpBuffer A
s String, ByVal nSize As Long) As Long
Declare Function GetVersion Lib "kernel32" () As Long
Declare Function GetWinflags Lib "kernel32" () As Long
��Ҫ˵������:
(1). GetWindowsDirectory:�ú����ȡWindowsĿ¼��·����
(2).GetSystemDirectory:�ú����ȡWindowsϵͳ��Ŀ¼��·��
��
(3). GetVersion:�ú���ص�ǰWindows�汾�ź�DOS�汾�š�
����ֵ�ĵ�λ�ֽ�˵��Windows���汾��,����ֵ�ĵ�λ�ֵĸ�λ�ֽ�
˵��Windows���汾��,��λ�ֵĵ�λ�ֽ�˵��DOS���汾��,��λ�ֵ�
��λ�ֽ�˵��DOS���汾�š�
(4).GetWinflags:�ú����Windows����ϵͳ�ϵ��ڴ����á�
��2
(5).GetKeyboardType():�ú���õ�ϵͳ��������,nTypeFlag=0
ʱ���ؼ������͡���3
(6).Ϊ�˵�����ЩAPI�����ӷ���,���Ա�дһЩ������
Щ�û��Զ��庯��Ĺ���Ҳ��Ҫ��ģ���С�����ƪ������,����ֻ��
����������,����ֻ�к�����:
Function SysDir()
Function WinDir() As String
Function KeyType()
KbType = GetKeyboardType(0)
Select Case KbType
Case 1
KeyType="IBM PC\XT,or compatible(83key)"
Case 2
KeyType="Olivetti ��ICO'(102key)"
Case 3
KeyType="IBM AT,or similar(84key)"
Case 4
KeyType = "IBM Enhance (101 or 102 keys)"
Case 5
KeyType = "Nokia 1050 or similar"
Case 6
KeyType = "Nokia 1050 or similar"
Case 6
KeyType = "Nokia 9140 or similar"
Case 7
KeyType = "Japan Keyboard"
End Select
End Function
Function Initial()
Function SaveInfor()
x = WritePrivateProfileString("Form", "left", Str
$(Form1.Left), "c:\windows\demo.ini")
x = WritePrivateProfileString("Form", "top", Str
$(Form1.Top), "c:\windows\demo.ini")
x = WritePrivateProfileString("Form", "windowstate", Str
$(Form1.WindowState), "c:\windows\demo.ini")
End Function
Function StringFormINI(SectionName As String, KeyNam
e As String, Defaul t AsString, FileName As String) As Strin
g
Function WinVer()
Function DosVer()
Function CPU()
Function Mode()
2.���������ļ�Form1.frm
Form1.Caption="System Information"
Sub Form_Paint()
Cls
Print
Print , "System Information"
Print
Print , "WindowsDir: ", WinDir()
Print , "SystemDir: ", SysDir()
Print , "WindowsVersion: ", WinVer()
Print , "DosVersion: ", DosVer()
Print , "KeyboardType: ", KeyType()
End Sub
Sub Form_Load()
x = Initial()
End Sub
Sub Form_Unload(Cancel As Integer)
x = SaveInfor()
End Sub
3.���б�����(��������486���ݻ�Windows3.1��ͨ��)��������
�ܹ���ǰ����ϵͳ��Ϣ,���˳�ʱ�ܽ����ڵ�����λ�ü�����
״̬��¼��DEMO.INI�ļ���,���´�����ʱ,�����ܱ����ϴ��˳�ʱ��
λ�ú�״̬��
ע��:��Ҫ���ı��༭���༭DEMO.INI
[Form��
Left=100
Top=100
Windowstate=0
�����ڵ�ǰϵͳWindowsĿ¼�¡�
���Ľ����ǽ�����һ��API�����ʹ�÷���,������ש����֮�á�
�����Ӧ��API����,����Ҫ���꾡�����ϺͶ��߸���Ŭ����
--
[m[1;32m�� ��Դ:���ϴ�С�ٺ���Ϣ����վ bbs.nju.edu.cn��[FROM: hsia.nju.edu.cn][m
Thread Navigation
This is a paginated view of messages in the thread with full content displayed inline.
Messages are displayed in chronological order, with the original post highlighted in green.
Use pagination controls to navigate through all messages in large threads.
Back to All Threads