Ignore:
Timestamp:
May 21, 2007, 1:03:21 AM (17 years ago)
Author:
イグトランス (egtra)
Message:

Prompt.sbp内を名前空間に入れた。EnvironmentのMachineName, UserName, GetFolderPathを実装。

File:
1 edited

Legend:

Unmodified
Added
Removed
  • Include/basic/prompt.sbp

    r208 r258  
    55#define _INC_PROMPT
    66
    7 
    87#require <api_imm.sbp>
    98#require <Classes/System/Math.ab>
    10 
     9#require <Classes/System/Environment.ab>
     10
     11Namespace ActiveBasic
     12Namespace Prompt
     13Namespace Detail
     14   
    1115Function _PromptSys_GetTextExtentPoint32(hdc As HDC, psz As PCSTR, cb As Long, ByRef Size As SIZE) As Long
    1216    _PromptSys_GetTextExtentPoint32 = GetTextExtentPoint32A(hdc, psz, cb, Size)
     
    5054End Type
    5155
    52 Dim _PromptSys_LogFont As LOGFONT
    5356Dim _PromptSys_hFont As HFONT
    5457Dim _PromptSys_FontSize As SIZE
    5558Dim _PromptSys_InputStr[255] As StrChar
    56 Dim _PromptSys_InputLen As Long
     59Dim _PromptSys_InputLen = -1 As Long
    5760Dim _PromptSys_KeyChar As Byte
    5861Dim _PromptSys_CurPos As POINTAPI
     
    6467Dim _System_OSVersionInfo As OSVERSIONINFO
    6568
    66 _PromptSys_InputLen = -1
    6769
    6870'graphic
     
    7274Dim _PromptSys_GlobalPos As POINTAPI
    7375
     76Sub _PromptSys_Initialize()
    7477_PromptSys_hInitFinish = CreateEvent(0, FALSE, FALSE, 0)
    75 Dim _PromptSys_hThread As HANDLE
    76 _PromptSys_hThread = CreateThread(0, 0, AddressOf(PromptMain) As LPTHREAD_START_ROUTINE, 0, 0, _PromptSys_dwThreadID)
     78Dim _PromptSys_hThread = CreateThread(0, 0, AddressOf(PromptMain), 0, 0, _PromptSys_dwThreadID)
    7779If _PromptSys_hThread = 0 Then
    7880    Debug
     
    8082End If
    8183WaitForSingleObject(_PromptSys_hInitFinish, INFINITE)
     84End Sub
    8285
    8386Sub DrawPromptBuffer(hDC As HDC, StartLine As Long, EndLine As Long)
     
    267270    Dim ps As PAINTSTRUCT
    268271    Dim hdc = BeginPaint(hwnd, ps)
    269 '   With _PromptSys_ScreenSize
    270 '       BitBlt(hdc, 0, 0, .cx, .cy, _PromptSys_hMemDC, 0, 0, SRCCOPY)
    271     With ps.rcPaint
    272         BitBlt(hdc, .left, .top, .right - .left, .bottom - .top, _PromptSys_hMemDC, .left, .top, SRCCOPY)
     272    With _PromptSys_ScreenSize
     273        BitBlt(hdc, 0, 0, .cx, .cy, _PromptSys_hMemDC, 0, 0, SRCCOPY)
     274'   With ps.rcPaint
     275'       BitBlt(hdc, .left, .top, .right - .left, .bottom - .top, _PromptSys_hMemDC, .left, .top, SRCCOPY)
    273276    End With
    274277    DrawPromptBuffer(hdc, -1, 0)
     
    287290            End With
    288291            ImmSetCompositionWindow(himc, CompForm)
    289             ImmSetCompositionFont(himc, _PromptSys_LogFont)
     292
     293            Dim lf As LOGFONT
     294            GetObject(_PromptSys_hFont, Len(lf), lf)
     295            ImmSetCompositionFont(himc, lf)
    290296        End If
    291297        ImmReleaseContext(hwnd, himc)
     
    365371
    366372        SendMessage(hwnd, WM_KILLFOCUS, 0, 0)
    367         PRINT_ToPrompt(TempStr)
     373        ActiveBasic.Prompt.Detail.PRINT_ToPrompt(TempStr)
    368374        SendMessage(hwnd, WM_SETFOCUS, 0, 0)
    369375    End If
     
    372378Function _PromptWnd_GetCompositionStringW(himc As HIMC, ByRef rpsz As PWSTR) As Long
    373379    Dim size = ImmGetCompositionStringW(himc, GCS_RESULTSTR, 0, 0) 'sizeはバイト単位
    374     rpsz = _System_malloc(size) As PTSTR
     380    rpsz = _System_malloc(size) As PWSTR
    375381    If rpsz = 0 Then
    376382        'Debug
     
    382388Function _PromptWnd_GetCompositionStringA(himc As HIMC, ByRef rpsz As PSTR) As Long
    383389    Dim size = ImmGetCompositionStringA(himc, GCS_RESULTSTR, 0, 0) 'sizeはバイト単位
    384     rpsz = _System_malloc(size) As PTSTR
     390    rpsz = _System_malloc(size) As PSTR
    385391    If rpsz = 0 Then
    386392        'Debug
     
    403409        tempStr.Assign(str, size)
    404410#else
    405         With _System_OSVersionInfo
     411        Dim osver = System.Environment.OSVersion
     412        With osver
    406413            ' GetCompositionStringW is not implimented in Windows 95
    407             If .dwMajorVersion = 4 And .dwMinorVersion = 0 And .dwPlatformId = VER_PLATFORM_WIN32_WINDOWS Then
     414            If .Version.Major = 4 And .Version.Minor = 0 And .Platform = System.PlatformID.Win32Windows Then
    408415                Dim strA As PCSTR
    409416                Dim sizeA = _PromptWnd_GetCompositionStringA(himc, strA)
     
    421428        _PromptSys_InputLen += tempStr.Length
    422429
    423         SendMessage(hwnd, WM_KILLFOCUS, 0, 0) : Debug
    424         PRINT_ToPrompt(tempStr)
     430        SendMessage(hwnd, WM_KILLFOCUS, 0, 0)
     431        ActiveBasic.Prompt.Detail.PRINT_ToPrompt(tempStr)
    425432        SendMessage(hwnd, WM_SETFOCUS, 0, 0)
    426433
     
    454461    End With
    455462
    456     'LogFont initialize
    457     With _PromptSys_LogFont
     463    '_PromptSys_hFont initialize
     464    Dim lf As LOGFONT
     465    With lf
    458466        .lfHeight = -16
    459467        .lfWidth = 0
     
    469477        .lfQuality = DEFAULT_QUALITY
    470478        .lfPitchAndFamily = FIXED_PITCH
    471         lstrcpy(.lfFaceName, "MS 明朝")
    472     End With
    473 
    474     _PromptSys_hFont = CreateFontIndirect(_PromptSys_LogFont)
     479        lstrcpy(.lfFaceName, ToTCStr("MS 明朝"))
     480    End With
     481
     482    _PromptSys_hFont = CreateFontIndirect(lf)
    475483
    476484    'Critical Section
     
    487495        .hIconSm = LoadImage(0, MAKEINTRESOURCE(IDI_WINLOGO), IMAGE_ICON, 0, 0, LR_DEFAULTSIZE Or LR_SHARED) As HICON
    488496        .hCursor = LoadImage(0, MAKEINTRESOURCE(IDC_ARROW), IMAGE_CURSOR, 0, 0, LR_DEFAULTSIZE Or LR_SHARED) As HCURSOR
    489         .lpszClassName = "PROMPT"
     497        .lpszClassName = ToTCStr("PROMPT")
    490498        .lpfnWndProc = AddressOf(PromptProc)
    491499        .hbrBackground = GetStockObject(BLACK_BRUSH)
     
    494502
    495503    'Create Prompt Window
    496     _PromptSys_hWnd = CreateWindowEx(WS_EX_CLIENTEDGE, atom As ULONG_PTR As LPCTSTR, "BASIC PROMPT", _
     504    _PromptSys_hWnd = CreateWindowEx(WS_EX_CLIENTEDGE, atom As ULONG_PTR As LPCTSTR, ToTCStr("BASIC PROMPT"), _
    497505        WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, _
    498506        0, 0, wcl.hInstance, 0)
     
    503511    Do
    504512        Dim iResult = GetMessage(msg, 0, 0, 0)
    505         If iResult = 0 Or iResult = -1 Then Exit Do
     513        If iResult = 0 Then
     514            System.Environment.ExitCode = msg.wParam As Long
     515            Exit Do
     516        ElseIf iResult = -1 Then
     517            Exit Do
     518        End If
    506519        TranslateMessage(msg)
    507520        DispatchMessage(msg)
     
    509522
    510523    '強制的に終了する
    511     End 'ExitProcess(0)
     524    End
    512525
    513526    EnterCriticalSection(_PromptSys_SectionOfBufferAccess)
     
    522535    DeleteCriticalSection(_PromptSys_SectionOfBufferAccess)
    523536
    524     End 'ExitProcess(0)
    525 End Function
    526 
    527 
    528 '----------------------
    529 ' Prompt text Commands
    530 '----------------------
    531 
    532 Macro CLS()(num As Long)
     537    End
     538End Function
     539
     540'Prompt text command functoins
     541
     542Sub Cls(n As Long)
    533543    Dim i As Long
    534544
    535545    'When parameter was omitted, num is set to 1
    536     If num = 0 Then num = 1
    537 
    538     If num = 1 Or num = 3 Then
     546    If n = 0 Then n = 1
     547
     548    If n = 1 Or n = 3 Then
    539549        'Clear the text screen
    540550        For i = 0 To 100
     
    550560    End If
    551561
    552     If num = 2 Or num = 3 Then
     562    If n = 2 Or n = 3 Then
    553563        'Clear the graphics screen
    554564        Dim hOldBrush = SelectObject(_PromptSys_hMemDC, GetStockObject(BLACK_BRUSH))
     
    561571    'Redraw
    562572    InvalidateRect(_PromptSys_hWnd, ByVal 0, 0)
    563 End Macro
    564 
    565 Macro COLOR(TextColorCode As Long)(BackColorCode As Long)
    566     _PromptSys_NowTextColor = GetBasicColor(TextColorCode)
    567     If BackColorCode = -1 Then
     573End Sub
     574
     575Sub Color(textColorCode As Long, backColorCode As Long)
     576    _PromptSys_NowTextColor = GetBasicColor(textColorCode)
     577    If backColorCode = -1 Then
    568578        _PromptSys_NowBackColor = -1
    569579    Else
    570         _PromptSys_NowBackColor = GetBasicColor(BackColorCode)
    571     End If
    572 End Macro
    573 
    574 '---------- Defined in "command.sbp" ----------
    575 'Dim _System_InputDataPtr[_System_MAX_PARMSNUM] As VoidPtr
    576 'Dim _System_InputDataType[_System_MAX_PARMSNUM] As DWord
    577 '----------------------------------------------
    578 Sub INPUT_FromPrompt(ShowStr As String)
     580        _PromptSys_NowBackColor = GetBasicColor(backColorCode)
     581    End If
     582End Sub
     583
     584Sub INPUT_FromPrompt(showStr As String)
    579585    Dim i As Long, i2 As Long, i3 As Long
    580586    Dim buf As String
     
    582588*InputReStart
    583589
    584     PRINT_ToPrompt(ShowStr)
     590    ActiveBasic.Prompt.Detail.PRINT_ToPrompt(showStr)
    585591
    586592    'Input by keyboard
     
    616622        i++
    617623        If _System_InputDataPtr[i] = 0 and _PromptSys_InputStr[i2] = &h2c Then 'Asc(",")
    618             PRINT_ToPrompt(Ex"入力データの個数が多すぎます\r\n")
     624            ActiveBasic.Prompt.Detail.PRINT_ToPrompt(Ex"入力データの個数が多すぎます\r\n")
    619625            Goto *InputReStart
    620626        ElseIf _PromptSys_InputStr[i2] = 0 Then
    621627            If _System_InputDataPtr[i]<>0 Then
    622                 PRINT_ToPrompt(Ex"入力データの個数が足りません\r\n")
     628                ActiveBasic.Prompt.Detail.PRINT_ToPrompt(Ex"入力データの個数が足りません\r\n")
    623629                Goto *InputReStart
    624630            Else
     
    631637End Sub
    632638
    633 Sub PRINTUSING_ToPrompt(UsingStr As String)
    634     PRINT_ToPrompt(_System_GetUsingFormat(UsingStr))
    635 End Sub
    636 
    637 Macro LOCATE(x As Long, y As Long)
     639Sub Locate(x As Long, y As Long)
    638640    If x < 0 Then x = 0
    639641    If y < 0 Then y = 0
     
    653655        _PromptSys_TextLine[y].Length = x
    654656    End If
    655 End Macro
    656 
    657 
    658 '-------------------
    659 ' Graphics Commands
    660 '-------------------
    661 
    662 Macro CIRCLE(x As Long , y As Long, radius As Long)(ColorCode As Long, StartPos As Double, EndPos As Double, Aspect As Double, bFill As Long, BrushColor As Long)
    663     '呼び出し方法は以下のようになります(コンパイラがパラメータの並びを最適化します)
    664     'Circle (x, y), radius [, color] [, start] [, end] [, aspect] [, f] [, color2]
    665 
     657End Sub
     658
     659'Prompt graphic command functions
     660
     661Sub Circle(x As Long , y As Long, radius As Long, ColorCode As Long, StartPos As Double, EndPos As Double, Aspect As Double, bFill As Long, BrushColor As Long)
    666662    Dim i1 As Long, i2 As Long, i3 As Long, i4 As Long
    667663
     
    763759    DeleteObject(hPen)
    764760    If bFill Then DeleteObject(hBrush)
    765 End Macro
    766 
    767 Macro LINE(sx As Long, sy As Long, bStep As Long, ex As Long, ey As Long)(ColorCode As Long, fType As Long, BrushColor As Long)
    768     '呼び出し方法は以下のようになります(コンパイラがパラメータの並びを最適化します)
    769     'Line (sx,sy)-[STEP](ex,ey),[ColorCode],[B/Bf],[BrushColor]
     761End Sub
     762
     763Sub Line(sx As Long, sy As Long, bStep As Long, ex As Long, ey As Long, ColorCode As Long, fType As Long, BrushColor As Long)
    770764    Dim temp As Long
    771765
     
    796790    End If
    797791
    798     Dim hDC = GetDC(_PromptSys_hWnd)
     792    Dim hdc = GetDC(_PromptSys_hWnd)
    799793    Dim hPen = CreatePen(PS_SOLID, 1, GetBasicColor(ColorCode))
    800794    Dim hBrush As HBRUSH
     
    805799    End If
    806800
    807     SelectObject(hDC, hPen)
    808     SelectObject(hDC, hBrush)
     801    SelectObject(hdc, hPen)
     802    SelectObject(hdc, hBrush)
    809803    Dim hOldPen = SelectObject(_PromptSys_hMemDC, hPen)
    810804    Dim hOldBrush = SelectObject(_PromptSys_hMemDC, hBrush)
     
    816810            LineTo(_PromptSys_hMemDC,ex,ey)
    817811            SetPixel(_PromptSys_hMemDC,ex,ey,GetBasicColor(ColorCode))
    818             MoveToEx(hDC,sx,sy,ByVal NULL)
    819             LineTo(hDC,ex,ey)
    820             SetPixel(hDC,ex,ey,GetBasicColor(ColorCode))
     812            MoveToEx(hdc,sx,sy,ByVal NULL)
     813            LineTo(hdc,ex,ey)
     814            SetPixel(hdc,ex,ey,GetBasicColor(ColorCode))
    821815        Case Else
    822816            'Rectangle
    823             Rectangle(hDC,sx,sy,ex+1,ey+1)
     817            Rectangle(hdc,sx,sy,ex+1,ey+1)
    824818            Rectangle(_PromptSys_hMemDC,sx,sy,ex+1,ey+1)
    825819    End Select
    826820
    827     ReleaseDC(_PromptSys_hWnd,hDC)
     821    ReleaseDC(_PromptSys_hWnd,hdc)
    828822    SelectObject(_PromptSys_hMemDC,hOldPen)
    829823    SelectObject(_PromptSys_hMemDC,hOldBrush)
     
    834828        .y = ey
    835829    End With
    836 End Macro
    837 
    838 Macro PSET(x As Long, y As Long)(ColorCode As Long)
    839     '呼び出し方法は以下のようになります(コンパイラがパラメータの並びを最適化します)
    840     'PSet (x,y),ColorCode
    841 
    842     Dim hDC = GetDC(_PromptSys_hWnd)
    843     SetPixel(hDC, x, y, GetBasicColor(ColorCode))
     830End Sub
     831
     832Sub PSet(x As Long, y As Long, ColorCode As Long)
     833    Dim hdc = GetDC(_PromptSys_hWnd)
     834    SetPixel(hdc, x, y, GetBasicColor(ColorCode))
    844835    SetPixel(_PromptSys_hMemDC, x, y, GetBasicColor(ColorCode))
    845     ReleaseDC(_PromptSys_hWnd, hDC)
     836    ReleaseDC(_PromptSys_hWnd, hdc)
    846837    With _PromptSys_GlobalPos
    847838        .x = x
    848839        .y = y
    849840    End With
    850 End Macro
    851 
    852 Macro PAINT(x As Long, y As Long, BrushColor As Long)(ByVal LineColor As Long)
    853     '呼び出し方法は以下のようになります(コンパイラがパラメータの並びを最適化します)
    854     'Paint (x,y),BrushColor,LineColor
    855 
    856     Dim hBrush = CreateSolidBrush(GetBasicColor(BrushColor))
    857 
    858     Dim hDC = GetDC(_PromptSys_hWnd)
    859     Dim hOldBrush = SelectObject(_PromptSys_hMemDC, hBrush)
    860     Dim hOldBrushWndDC = SelectObject(hDC, hBrush)
    861 
    862     ExtFloodFill(hDC, x, y, GetBasicColor(LineColor), FLOODFILLBORDER)
     841End Sub
     842
     843Sub Paint(x As Long, y As Long, BrushColor As Long, LineColor As Long)
     844    Dim hbr = CreateSolidBrush(GetBasicColor(BrushColor))
     845
     846    Dim hdc = GetDC(_PromptSys_hWnd)
     847    Dim hbrOld = SelectObject(_PromptSys_hMemDC, hbr)
     848    Dim hbrOldWndDC = SelectObject(hdc, hbr)
     849
     850    ExtFloodFill(hdc, x, y, GetBasicColor(LineColor), FLOODFILLBORDER)
    863851    ExtFloodFill(_PromptSys_hMemDC, x, y, GetBasicColor(LineColor), FLOODFILLBORDER)
    864852
    865     ReleaseDC(_PromptSys_hWnd, hDC)
    866     SelectObject(_PromptSys_hMemDC, hOldBrush)
    867     SelectObject(hDC, hOldBrushWndDC)
    868     DeleteObject(hBrush)
    869 End Macro
    870 
    871 
    872 '-----------
    873 ' Functions
    874 '-----------
     853    ReleaseDC(_PromptSys_hWnd, hdc)
     854    SelectObject(_PromptSys_hMemDC, hbrOld)
     855    SelectObject(hdc, hbrOldWndDC)
     856    DeleteObject(hbr)
     857End Sub
    875858
    876859Function Inkey$() As String
     
    884867
    885868Function Input$(length As Long) As String
    886     Dim i As Long
     869    Dim i = 0 As Long
    887870
    888871    If length<=0 Then
     
    891874    End If
    892875
    893     i=0
    894876    While 1
    895877        If _PromptSys_KeyChar Then
     
    905887End Function
    906888
     889End Namespace 'Detail
     890
     891Function OwnerWnd() As HWND
     892    Return Detail._PromptSys_hWnd
     893End Function
     894
     895End Namespace 'Prompt
     896End Namespace 'ActiveBasic
     897
     898'----------------------
     899' Prompt text Commands
     900'----------------------
     901
     902Sub PRINT_ToPrompt(s As String)
     903    ActiveBasic.Prompt.Detail.PRINT_ToPrompt(s)
     904End Sub
     905
     906Macro CLS()(num As Long)
     907    ActiveBasic.Prompt.Detail.Cls(num)
     908End Macro
     909
     910Macro COLOR(TextColorCode As Long)(BackColorCode As Long)
     911    ActiveBasic.Prompt.Detail.Color(TextColorCode, BackColorCode)
     912End Macro
     913
     914'---------- Defined in "command.sbp" ----------
     915'Dim _System_InputDataPtr[_System_MAX_PARMSNUM] As VoidPtr
     916'Dim _System_InputDataType[_System_MAX_PARMSNUM] As DWord
     917'----------------------------------------------
     918Sub INPUT_FromPrompt(ShowStr As String)
     919    ActiveBasic.Prompt.Detail.INPUT_FromPrompt(ShowStr)
     920End Sub
     921
     922Sub PRINTUSING_ToPrompt(UsingStr As String)
     923    ActiveBasic.Prompt.Detail.PRINT_ToPrompt(_System_GetUsingFormat(UsingStr))
     924End Sub
     925
     926Macro LOCATE(x As Long, y As Long)
     927    ActiveBasic.Prompt.Detail.Locate(x, y)
     928End Macro
     929
     930
     931'-------------------
     932' Graphics Commands
     933'-------------------
     934
     935Macro CIRCLE(x As Long , y As Long, radius As Long)(ColorCode As Long, StartPos As Double, EndPos As Double, Aspect As Double, bFill As Long, BrushColor As Long)
     936    '呼び出し方法は以下のようになります(コンパイラがパラメータの並びを最適化します)
     937    'Circle (x, y), radius [, color] [, start] [, end] [, aspect] [, f] [, color2]
     938    ActiveBasic.Prompt.Detail.Circle(x, y, radius, ColorCode, StartPos, EndPos, Aspect, bFill, BrushColor)
     939End Macro
     940
     941Macro LINE(sx As Long, sy As Long, bStep As Long, ex As Long, ey As Long)(ColorCode As Long, fType As Long, BrushColor As Long)
     942    '呼び出し方法は以下のようになります(コンパイラがパラメータの並びを最適化します)
     943    'Line (sx,sy)-[STEP](ex,ey),[ColorCode],[B/Bf],[BrushColor]
     944    ActiveBasic.Prompt.Detail.Line(sx, sy, bStep, ex, ey, ColorCode, fType, BrushColor)
     945End Macro
     946
     947Macro PSET(x As Long, y As Long)(ColorCode As Long)
     948    '呼び出し方法は以下のようになります(コンパイラがパラメータの並びを最適化します)
     949    'PSet (x,y),ColorCode
     950    ActiveBasic.Prompt.Detail.PSet(x, y, ColorCode)
     951End Macro
     952
     953Macro PAINT(x As Long, y As Long, BrushColor As Long)(ByVal LineColor As Long)
     954    '呼び出し方法は以下のようになります(コンパイラがパラメータの並びを最適化します)
     955    'Paint (x,y),BrushColor,LineColor
     956    ActiveBasic.Prompt.Detail.Paint(x, y, BrushColor, LineColor)
     957End Macro
     958
     959
     960'-----------
     961' Functions
     962'-----------
     963
     964Function Inkey$() As String
     965    Return ActiveBasic.Prompt.Detail.Inkey$()
     966End Function
     967
     968Function Input$(length As Long) As String
     969    Return ActiveBasic.Prompt.Detail.Input$(length)
     970End Function
     971
     972ActiveBasic.Prompt.Detail._PromptSys_Initialize()
    907973
    908974#endif '_INC_PROMPT
Note: See TracChangeset for help on using the changeset viewer.