🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: cn.bbs.comp.program
Article #576

vb�е���api����Ӧ��ʵ��

#576
From: ���δ�
Date: Mon, 22 Jun 1998 00:00
420 lines
14919 bytes
Visual Basic �� �� Windows API �� �� �� Ӧ �� �� �� 

        �� ժ Ҫ�� 
        �� �� �� �� �� �� ��Visual Basic �� �� Windows API �� �� �� �� ���� �� ͨ �� �� �� ��
 �� �� �� 

        API �� �� �� �� �� �� �� �磺VB �� �� ˽ �� �� ʼ �� �� �� �� �� ȡ�� �� �� ǰ ϵ ͳ
 �� Ϣ �� �� �⡣ 

        �� �� �� �֡� 
        Windows Microsoft( ΢ ��) �� ˾ �� �� �� ϵ ͳ�� 
        Visual Basic(VB) Microsoft( ΢ ��) �� ˾ �� �� �� �� �� �� �� �ߡ� 
        API(Application Program Interface) Ӧ �� �� �� �� �ڡ� 
        �� ʼ �� �� ���� �� �磺DEMO.INI�� 

        �� �� �� �� 

 һ�� �� ��VB �� ��API �� �� �� �� ���� 

        (1) ��Declare �� �� �� �� �� Ҫ �� �� ��API �� �� �� �� �� �� �� �� �� ֵ�� �� ��
 �� ΪSub �� �̣� �� �� �� �� ֵ�� �� �� �� �� ΪFunction �� �� 

        ע�� �� �� ��API �� �� �� �� �� �� �� .\VB\WINAPI\WIN31API.HLP �У� ֻ ��
 ��Copy �� Paste �� �� �� �� �� �� �� �� Ӧ �� �� ���� 

        (2) һ �� �� �� �� ij һ ��API �� �� �� �� �� �� �� �� ��VB �� �� �� һ �� �� ��
 ע �⣬ �� �� �� �� �� �� �� �ԣ� �� �� �� �� �� �� �� 

 ���� VB �� �� ˽ �� �� ʼ �� �� �� �� �� ȡ�� 

        Windows �� �� �� �� ʼ �� �� �� �� �� ȡ �� �� �� �� ͨ �� �� ȡ �� չ �� Ϊ .INI ��
 �� �� �� �� �� ʵ �� �ģ� �� �� �� �� �� ǰ �� �� ָ �� ��INI �� �� �� �� �� �� �� �� ��
 �� �� �� �� ӳ �� �� �� �� �� �� �� �� �У� �� �� �� �� �� ʱ �� �� �� ǰ �� �� �� �� ��
 �� �� �� ָ �� ��INI �� �� �С�Windows �� �� ��API �� �� �� ��GetPrivateProfileString
 ��WritePrivateProfileString �� �� �� Щ �� �ܡ� 

        ˵ ���� 
        ��1�� GetPrivateProfileString �� ����Declare Function GetPrivateProfileString Lib "kernel32"
 Alias "GetPrivateProfileStringA" (ByVal lpApplicationName As String,ByVal lpKeyName As Any,
 ByVal lpDefault As String, ByVal lpReturnedString As String, ByVal nSize As Long, ByVal
 lpFileName As String) As Long 

        �� �ܣ� �� ȡINI �� �� �� �� ָ �� �� �� �� �� Ӧ �� �� �� �� �� �� �ԣ� �� �� ��
 �� �� �� �� ��lpReturnedString �� 

        �� �� 
        �� �� 
        ˵ �� 
        lpApplicationName 
        String 
        �� Ѱ �� �� �� �� �� �� �� �� �� 
        lpKeyName 
        String 
        �� �� �� �� �� Ӧ �� �� �� �� �� 
        lpDefault 
        String 
        ָ �� �� �� �� �� �� �� �� ʱ �� �� �� ȱ ʡ ֵ 
        lpReturnedString 
        String 
        Ԥ �� �� �� �� �� �� �� �� �� ΪnSize �� �� �� �� �� �� �� �� �� 
        nSized 
        Integer 
        �� Ҫ װ ��lpReturnedString �� �� �� �� �� �� �� �� �� 
        lpFileName 
        String 
        �� ʼ �� �� �� �� �� �� 
        �� �� ֵ 
        Integer 
        �� �� ��lpReturnedString �� �� �� �� �� �� �� 

        ��2��WritePrivateProfileString 
        �� ����Declare Function WritePrivateProfileString Lib "kernel32" Alias
 "WritePrivateProfileStringA" (ByVal lpApplicationName As String, ByVal lpKeyName As Any,
 ByVal lpString As Any, ByVal lpFileName As String) As Long 

        �� �ܣ� �� �� ʼ �� �� �� �� ָ �� �� �� �� �� �� �� �� �� �� �� �� ������ 
        �� �� ֵ�� �� �� �� �� �� ���� �� ��TRUE�� �� �� �� ��FALSE�� 

 �� VB �� �� �� ǰ ϵ ͳ �� Ϣ 

        �� �� ��API �� ��
 ��GetWindowsDirectory��GetWinFlags,GetVersion��GetSystemDirectory, �ȣ� �� �� �� ʹ ��
 �� �� �� �� �� �� 

 �ġ� �� �� 

        DEMO.PRJ 

        �� һ�� �� �� �� Ŀ �� ��DEMO.PRJ�� �� �� ģ �� �� ��DEMO.BAS. �� �� �� �� ��
 �� �� �� ��DEMO.BAS �� 

        Declare Function GetWindowsDirectory Lib "kernel32" Alias "GetWindowsDirectoryA" (ByVal
 lpBuffer As String, ByVal nSize As Long) As Long 

        Declare Function GetPrivateProfileString Lib "kernel32" Alias "GetPrivateProfileStringA" (ByVal
 lpApplicationName As String, ByVal lpKeyName As Any, ByVal lpDefault As String, ByVal
 lpReturnedString As String, ByVal nSize As Long, ByVal lpFileName As String) As Long 

        Declare Function WritePrivateProfileString Lib "kernel32" Alias "WritePrivateProfileStringA"
 (ByVal lpApplicationName As String, ByVal lpKeyName As Any, ByVal lpString As Any, ByVal
 lpFileName As String) As Long 
        Declare Function GetKeyboardType Lib "user32" (ByVal nTypeFlag As Long) As Long 
        Declare Function GetSystemDirectory Lib "kernel32" Alias "GetSystemDirectoryA" (ByVal
 lpBuffer As 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 �� �� ϵ ͳ �� �� �� �� �� �á� 

        �� �� �� ־ ֵ 
        �� �� 
        WF_80X87 
        Intel �� �� Э �� �� �� 
        WF_CPU386 
        80386 CPU 
        WF_CPU486 
        80486 CPU 
        WF_ENHANCED 
        Windows ϵ ͳ �� �� ��386 �� ǿ ģ ʽ 
        WF_PMODE 
        Windows ϵ ͳ �� �� �� �� �� ģ ʽ 
        WF_STANDARD 
        Windows ϵ ͳ �� �� �� �� ׼ ģ ʽ 
        WF_WLO 
        �� �� ��OS/2 �� 

        5��GetKeyboardType(): �� �� �� �� �� ϵ ͳ �� �� �� �ͣ�nTypeFlag=0 ʱ �� �� �� ��
 �� �͡� 
        �� �� ֵ 
        �� �� 
        1 
        IBM PC/XT �� �� �� �� �� 
        2 
        Olivetti "ICO" �� �̣�102 �� �� 
        3 
        IBM �� �� �� �� �̣�84 �� �� 
        4 
        IBM �� ǿ �� �� �� �� �� �̣�101 ��102 �� �� 
        5 
        Nokia 1050 �� �� �� �� �� 
        6 
        Nokia 9140 �� �� �� �� �� 
        7 
        �� �� �� �� 

        6�� Ϊ �� �� �� �� ЩAPI �� �� �� �� �� �㣬 �� �� �� д һ Щ �� �� �� �� �� Щ
 �� �� �� �� �� �� �� �� �� �� Ҳ �� Ҫ �� ģ �� �С� 



 Function SysDir()

 Temp = Space$(255)

 StringLen = GetSystemDirectory(Temp, 255)

 SysDir = Left$(Temp, StringLen)

 End Function

 ___________________________________________________________________________

 Function WinDir() As String

 Temp = Space$(255)

 StringLen = GetWindowsDirectory(Temp, 255)

 WinDir = Left$(Temp, StringLen)

 End Function

 ___________________________________________________________________________

 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()

 Form1.Left = Val(StringFormINI("Form", "left", "0 ", "c:\windows\demo.ini"))

 Form1.Top = Val(StringFormINI("Form", "top", "0 ","c:\windows\demo.ini" ))

 Form1.WindowState = Val(StringFormINI("Form", "windowstate", "0 ","

 c:\windows\demo.ini"))

 End Function

 _______________________________________________________________________

 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, KeyName As String, 

 Default As String, FileName As String) As String

 MaxStringLen% = 255

 returnedstr$ = Space$(MaxStringLen%)

 Result% = GetPrivateProfileString(SectionName, KeyName, 

 Default, returnedstr$, MaxStringLen%, FileName)

 returnedstr$ = LTrim$(RTrim$(returnedstr$))

 returnedstr$ = Left$(returnedstr$, Len(returnedstr$) - 1)

 StringFormINI = returnedstr$

 End Function

 __________________________________________________________________________

 Function WinVer()

 ver& = GetVersion()

 winhigh = ver& Mod 256

 winlow = Int(ver& / 256) Mod 256

 WinVer = ((winhigh * 100) + winlow) / 100

 End Function

 ___________________________________________________________________________



 Function DosVer()

 ver& = GetVersion()

 Temp = ver& / 65536

 doshigh = Int(Temp / 256) Mod 256

 doslow = Temp Mod 256

 DosVer = ((doshigh * 100) + doslow) / 100

 End Function

 ___________________________________________________________________________

 Function CPU()

 Flags&=GetWinFlags()

 Match=1

 Select Case Match 

        Case (Flags& And &H8)\&H8

             CPU=486

        Case (Flags& And &H4)\&H4

             CPU=386

 End Select 

 End Function 

 ___________________________________________________________________________

 Function Mode()

 Flags&=GetWinFlags()

 If flags& And &H20 Then 

    Mode="Enhanced"

 Else

    Mode="Standard"

 End If 

 End Function



 �� ���� �� �� �� �� �� ��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


        �� �� �� �� �� �� �򡣣� �� �� �� ��486 �� �� ��Windows3.1 �� ͨ �� 
        �� �� �� �� �� �� �� �� ǰ �� �� ϵ ͳ �� Ϣ�� �� �� �� ʱ �� �� �� �� �� �� �� λ
 �� �� �� �� ״ ̬ �� ¼ ��DEMO.INI �� �� �У� �� �� �� �� �� ʱ�� �� �� �� �� �� �� ��
 �� �� ʱ �� λ �� �� ״ ̬�� 
        ע�� �� Ҫ �� �� �� �� �� �� �� ��DEMO.INI 



     [Form]

     Left=100

     Top=100

     Windowstate=0


        �� �� �� �� ǰ ϵ ͳWindows Ŀ ¼ �¡� 
        �� �� �� �� �� �� �� �� һ ��API �� �� �� ʹ �� �� ���� �� �� �� ש �� �� ֮ �á� ��
 �� �� Ӧ ��API �� �� �� �� Ҫ �� �� �� �� �� �� �� �� �� �� �� �� Ŭ ���� 
        �� �� �� �� Ŀ�� 
        ��Windows3.1 API �� �� �� �� �� �� �� �� Ϣ �� �⡷ 

--
�� ��Դ:��Yat-sen Channel argo.zsu.edu.cn��[FROM: 202.116.78.75]
Technical Details
Message-ID: <3PCWBD$u90@argo.zsu.edu.cn>
Path: arc1-ca.pugleaf.net!unknown!not-for-mail

Show Full Headers
Complete Article Headers
X-Google-Language: Chinese,GB
X-Google-Thread: fc86e,8a44b5002219bf83,start
X-Google-Attributes: gidfc86e,public
From: ox.bbs@argo.zsu.edu.cn (���δ�)
Subject: vb�е���api����Ӧ��ʵ��
Date: 1998/06/22
Message-ID: <3PCWBD$u90@argo.zsu.edu.cn>
X-Deja-AN: 365073805
X-Filename: Programming/M.898523677.A
Organization: Yat-sen Channel BBS
Newsgroups: cn.bbs.comp.program