'prompt.sbp #ifndef _INC_PROMPT #define _INC_PROMPT #include Dim _PromptSys_hWnd As HWND Dim _PromptSys_dwThreadID As DWord Dim _PromptSys_bInitFinish As BOOL 'text Dim _PromptSys_LogFont As LOGFONTA 'LOGFONT Dim _PromptSys_hFont As HFONT Dim _PromptSys_FontSize As SIZE Dim _PromptSys_InputStr[255] As Char Dim _PromptSys_InputLen As Long Dim _PromptSys_KeyChar As Byte Dim _PromptSys_CurPos As POINTAPI Dim _PromptSys_Buffer[100] As *Char Dim _PromptSys_TextColor[100] As *COLORREF Dim _PromptSys_BackColor[100] As *COLORREF Dim _PromptSys_NowTextColor As COLORREF Dim _PromptSys_NowBackColor As COLORREF Dim _PromptSys_SectionOfBufferAccess As CRITICAL_SECTION _PromptSys_InputLen=-1 'graphic Dim _PromptSys_hBitmap As HBITMAP Dim _PromptSys_hMemDC As HDC Dim _PromptSys_ScreenSize As SIZE Dim _PromptSys_GlobalPos As POINTAPI _PromptSys_bInitFinish=0 CreateThread( _ 0, 0, AddressOf(PromptMain) As LPTHREAD_START_ROUTINE, 0 As VoidPtr, 0, _PromptSys_dwThreadID) Do Sleep(20) Loop Until _PromptSys_bInitFinish Sub DrawPromptBuffer(hDC As HDC, StartLine As Long, EndLine As Long) Dim i As Long, i2 As Long, i3 As Long Dim sz As SIZE Dim temporary[2] As Char Dim hOldFont = SelectObject(hDC, _PromptSys_hFont) As HFONT 'Scroll Dim rc As RECT GetClientRect(_PromptSys_hWnd, rc) While (_PromptSys_CurPos.y+1)*_PromptSys_FontSize.cy>rc.bottom and _PromptSys_CurPos.y>0 _System_free(_PromptSys_Buffer[0]) _System_free(_PromptSys_TextColor[0]) _System_free(_PromptSys_BackColor[0]) For i=0 To 100-1 _PromptSys_Buffer[i] = _PromptSys_Buffer[i+1] _PromptSys_TextColor[i] = _PromptSys_TextColor[i+1] _PromptSys_BackColor[i] = _PromptSys_BackColor[i+1] Next _PromptSys_Buffer[100] = _System_calloc(SizeOf (Char) * 255) _PromptSys_TextColor[100] = _System_calloc(SizeOf(COLORREF) * 255) _PromptSys_BackColor[100] = _System_calloc(SizeOf(COLORREF) * 255) _PromptSys_CurPos.y-- 'Redraw StartLine=-1 Wend i=0 While i*_PromptSys_FontSize.cy-1 Then hIMC = ImmGetContext(hWnd) If hIMC Then With CompForm .dwStyle = CFS_POINT .ptCurrentPos.x = _PromptSys_CurPos.x*_PromptSys_FontSize.cx .ptCurrentPos.y = _PromptSys_CurPos.y*_PromptSys_FontSize.cy End With ImmSetCompositionWindow(hIMC, CompForm) ImmSetCompositionFontA(hIMC, _PromptSys_LogFont) End If ImmReleaseContext(hWnd, hIMC) CreateCaret(hWnd,NULL,9,6) SetCaretPos(_PromptSys_CurPos.x*_PromptSys_FontSize.cx, _ (_PromptSys_CurPos.y+1)*_PromptSys_FontSize.cy-7) ShowCaret(hWnd) End If Case WM_KILLFOCUS HideCaret(hWnd) DestroyCaret() Case WM_KEYDOWN If _PromptSys_InputLen=-1 Then _PromptSys_KeyChar=wParam As Byte End If Case WM_CHAR If _PromptSys_InputLen <> -1 Then If wParam = VK_BACK Then If _PromptSys_InputLen Then _PromptSys_InputLen-- _PromptSys_InputStr[_PromptSys_InputLen] = 0 _PromptSys_CurPos.x-- _PromptSys_Buffer[_PromptSys_CurPos.y][_PromptSys_CurPos.x] = 0 End If ElseIf wParam = VK_RETURN Then _PromptSys_InputStr[_PromptSys_InputLen] = 0 _PromptSys_InputLen = -1 TempStr = Ex"\r\n" ElseIf wParam = &H16 Then 'Paste Command(Use Clippboard) OpenClipboard(hWnd) Dim hGlobal = GetClipboardData(CF_TEXT) As HGLOBAL If hGlobal = 0 Then Return 0 Dim pTemp = GlobalLock(hGlobal) As PCSTR #ifdef UNICODE 'A版ウィンドウプロシージャ用 Dim tempSizeW = MultiByteToWideChar(CP_ACP, 0, pTemp, -1, 0, 0) + 1 TempStr = ZeroString(tempSizeW) MultiByteToWideChar(CP_ACP, 0, pTemp, -1, StrPtr(TempStr), tempSizeW) #else TempStr = ZeroString(lstrlen(pTemp) + 1) lstrcpy(StrPtr(TempStr), pTemp) #endif memcpy(VarPtr(_PromptSys_InputStr[_PromptSys_InputLen]), TempStr.Chars, SizeOf (Char) * TempStr.Length) _PromptSys_InputLen += TempStr.Length GlobalUnlock(hGlobal) CloseClipboard() Else _PromptSys_InputStr[_PromptSys_InputLen] = wParam As Byte _PromptSys_InputLen++ TempStr.ReSize(1) TempStr[0] = wParam As Char End If SendMessage(hWnd, WM_KILLFOCUS, 0, 0) PRINT_ToPrompt(TempStr) SendMessage(hWnd, WM_SETFOCUS, 0, 0) End If Case WM_DESTROY DeleteDC(_PromptSys_hMemDC) DeleteObject(_PromptSys_hBitmap) PostQuitMessage(0) Case Else PromptProc=DefWindowProc(hWnd,message,wParam,lParam) Exit Function End Select PromptProc=0 End Function Function PromptMain(dwData As Long) As Long Dim i As Long 'Allocate For i=0 To 100 _PromptSys_Buffer[i] = _System_calloc(SizeOf (Char) * 255) _PromptSys_TextColor[i] = _System_calloc(SizeOf(COLORREF) * 255) _PromptSys_BackColor[i] = _System_calloc(SizeOf(COLORREF) * 255) Next 'Current Colors initialize _PromptSys_NowTextColor=RGB(255,255,255) _PromptSys_NowBackColor=RGB(0,0,0) 'Setup _PromptSys_ScreenSize.cx=GetSystemMetrics(SM_CXSCREEN) _PromptSys_ScreenSize.cy=GetSystemMetrics(SM_CYSCREEN) 'LogFont initialize With _PromptSys_LogFont .lfHeight = -16 .lfWidth = 0 .lfEscapement = 0 .lfOrientation = 0 .lfWeight = 0 .lfItalic = 0 .lfUnderline = 0 .lfStrikeOut = 0 .lfCharSet = SHIFTJIS_CHARSET .lfOutPrecision = OUT_DEFAULT_PRECIS .lfClipPrecision = CLIP_DEFAULT_PRECIS .lfQuality = DEFAULT_QUALITY .lfPitchAndFamily = FIXED_PITCH lstrcpy(.lfFaceName, "MS 明朝") End With _PromptSys_hFont = CreateFontIndirect(ByVal VarPtr(_PromptSys_LogFont)) 'Critical Section InitializeCriticalSection(_PromptSys_SectionOfBufferAccess) 'Regist Prompt Class Dim wcl As WNDCLASSEX FillMemory(VarPtr(wcl),Len(wcl),0) wcl.cbSize=Len(wcl) wcl.hInstance=GetModuleHandle(0) wcl.style=CS_HREDRAW or CS_VREDRAW or CS_DBLCLKS wcl.hIcon=LoadIcon(NULL,MAKEINTRESOURCE(IDI_APPLICATION)) wcl.hIconSm=LoadIcon(NULL,MAKEINTRESOURCE(IDI_WINLOGO)) wcl.hCursor=LoadCursor(NULL,MAKEINTRESOURCE(IDC_ARROW)) wcl.lpszClassName="PROMPT" wcl.lpfnWndProc=AddressOf(PromptProc) wcl.hbrBackground=GetStockObject(BLACK_BRUSH) Dim atom = RegisterClassEx(wcl) 'Create Prompt Window _PromptSys_hWnd=CreateWindowEx(WS_EX_CLIENTEDGE,atom As ULONG_PTR As PCSTR,"BASIC PROMPT",WS_OVERLAPPEDWINDOW,CW_USEDEFAULT,CW_USEDEFAULT,CW_USEDEFAULT,CW_USEDEFAULT,0,0,GetModuleHandle(0),0) ShowWindow(_PromptSys_hWnd,SW_SHOW) UpdateWindow(_PromptSys_hWnd) Dim msg As MSG, iResult As Long Do iResult=GetMessage(msg,0,0,0) If iResult=0 or iResult=-1 Then Exit Do TranslateMessage(msg) DispatchMessage(msg) Loop '強制的に終了する ExitProcess(0) EnterCriticalSection(_PromptSys_SectionOfBufferAccess) For i=0 to 100 _System_free(_PromptSys_Buffer[i]) _System_free(_PromptSys_TextColor[i]) _System_free(_PromptSys_BackColor[i]) Next LeaveCriticalSection(_PromptSys_SectionOfBufferAccess) DeleteCriticalSection(_PromptSys_SectionOfBufferAccess) ExitProcess(0) End Function '---------------------- ' Prompt text Commands '---------------------- Macro CLS()(num As Long) Dim i As Long Dim hOldBrush As HBRUSH 'When parameter was omitted, num is set to 1 If num=0 Then num=1 If num=1 or num=3 Then 'Clear the text screen For i=0 To 100 FillMemory(_PromptSys_Buffer[i],255,0) Next _PromptSys_CurPos.x=0 _PromptSys_CurPos.y=0 End If If num=2 or num=3 Then 'Clear the graphics screen hOldBrush=SelectObject(_PromptSys_hMemDC,GetStockObject(BLACK_BRUSH)) PatBlt(_PromptSys_hMemDC,0,0,_PromptSys_ScreenSize.cx,_PromptSys_ScreenSize.cy,PATCOPY) SelectObject(_PromptSys_hMemDC,hOldBrush) End If 'Redraw InvalidateRect(_PromptSys_hWnd,ByVal 0,0) End Macro Macro COLOR(TextColorCode As Long)(BackColorCode As Long) _PromptSys_NowTextColor=GetBasicColor(TextColorCode) If BackColorCode=-1 Then _PromptSys_NowBackColor=-1 Else _PromptSys_NowBackColor=GetBasicColor(BackColorCode) End If End Macro '---------- Defined in "command.sbp" ---------- 'Dim _System_InputDataPtr[_System_MAX_PARMSNUM] As VoidPtr 'Dim _System_InputDataType[_System_MAX_PARMSNUM] As DWord '---------------------------------------------- Sub INPUT_FromPrompt(ShowStr As String) Dim i As Long ,i2 As Long, i3 As Long Dim buf As String *InputReStart PRINT_ToPrompt(ShowStr) 'Input by keyboard _PromptSys_InputLen=0 SendMessage(_PromptSys_hWnd,WM_SETFOCUS,0,0) While _PromptSys_InputLen<>-1 Sleep(10) Wend SendMessage(_PromptSys_hWnd,WM_KILLFOCUS,0,0) 'Set value to variable i = 0 i2 = 0 buf = ZeroString(lstrlen(_PromptSys_InputStr)) While 1 i3 = 0 While 1 If _PromptSys_InputStr[i2] = &h2c Then buf.Chars[i3] = 0 Exit While End If buf.Chars[i3] = _PromptSys_InputStr[i2] If _PromptSys_InputStr[i2] = 0 Then Exit While i2++ i3++ Wend _System_Input_SetArgument(_System_InputDataPtr[i], _System_InputDataType[i], buf, i3) i++ If _System_InputDataPtr[i]=0 and _PromptSys_InputStr[i2]=&h2c Then 'Asc(",") PRINT_ToPrompt(Ex"入力データの個数が多すぎます\r\n") Goto *InputReStart ElseIf _PromptSys_InputStr[i2]=0 Then If _System_InputDataPtr[i]<>0 Then PRINT_ToPrompt(Ex"入力データの個数が足りません\r\n") Goto *InputReStart Else Exit While End If End If i2++ Wend End Sub Sub PRINTUSING_ToPrompt(UsingStr As String) PRINT_ToPrompt(_System_GetUsingFormat(UsingStr)) End Sub Macro LOCATE(x As Long, y As Long) Dim i As Long, i2 As Long If x<0 Then x=0 If y<0 Then y=0 If y>100 Then y=100 _PromptSys_CurPos.x=x _PromptSys_CurPos.y=y i=0 While _PromptSys_Buffer[y][i] i++ Wend If iex Then temp=ex ex=sx sx=temp End If If sy>ey Then temp=ey ey=sy sy=temp End If End If End If Dim hDC = GetDC(_PromptSys_hWnd) Dim hPen = CreatePen(PS_SOLID, 1, GetBasicColor(ColorCode)) Dim hBrush As HBRUSH If fType=2 Then hBrush=CreateSolidBrush(GetBasicColor(BrushColor)) Else hBrush=GetStockObject(NULL_BRUSH) End If SelectObject(hDC,hPen) SelectObject(hDC,hBrush) Dim hOldPen = SelectObject(_PromptSys_hMemDC,hPen) Dim hOldBrush = SelectObject(_PromptSys_hMemDC,hBrush) Select Case fType Case 0 'line MoveToEx(_PromptSys_hMemDC,sx,sy,ByVal NULL) LineTo(_PromptSys_hMemDC,ex,ey) SetPixel(_PromptSys_hMemDC,ex,ey,GetBasicColor(ColorCode)) MoveToEx(hDC,sx,sy,ByVal NULL) LineTo(hDC,ex,ey) SetPixel(hDC,ex,ey,GetBasicColor(ColorCode)) Case Else 'Rectangle Rectangle(hDC,sx,sy,ex+1,ey+1) Rectangle(_PromptSys_hMemDC,sx,sy,ex+1,ey+1) End Select ReleaseDC(_PromptSys_hWnd,hDC) SelectObject(_PromptSys_hMemDC,hOldPen) SelectObject(_PromptSys_hMemDC,hOldBrush) DeleteObject(hPen) If fType=2 Then DeleteObject(hBrush) _PromptSys_GlobalPos.x=ex _PromptSys_GlobalPos.y=ey End Macro Macro PSET(x As Long, y As Long)(ColorCode As Long) '呼び出し方法は以下のようになります(コンパイラがパラメータの並びを最適化します) 'PSet (x,y),ColorCode Dim hDC=GetDC(_PromptSys_hWnd) SetPixel(hDC,x,y,GetBasicColor(ColorCode)) SetPixel(_PromptSys_hMemDC,x,y,GetBasicColor(ColorCode)) ReleaseDC(_PromptSys_hWnd,hDC) _PromptSys_GlobalPos.x=x _PromptSys_GlobalPos.y=y End Macro Macro PAINT(x As Long, y As Long, BrushColor As Long)(ByVal LineColor As Long) '呼び出し方法は以下のようになります(コンパイラがパラメータの並びを最適化します) 'Paint (x,y),BrushColor,LineColor Dim hDC As HDC Dim hBrush As HBRUSH, hOldBrush As VoidPtr hBrush=CreateSolidBrush(GetBasicColor(BrushColor)) hDC=GetDC(_PromptSys_hWnd) SelectObject(hDC,hBrush) hOldBrush=SelectObject(_PromptSys_hMemDC,hBrush) ExtFloodFill(hDC,x,y,GetBasicColor(LineColor),FLOODFILLBORDER) ExtFloodFill(_PromptSys_hMemDC,x,y,GetBasicColor(LineColor),FLOODFILLBORDER) ReleaseDC(_PromptSys_hWnd,hDC) SelectObject(_PromptSys_hMemDC,hOldBrush) DeleteObject(hBrush) End Macro '----------- ' Functions '----------- Function Inkey$() As String If _PromptSys_KeyChar=0 Then Inkey$="" Else Inkey$=Chr$(_PromptSys_KeyChar) End If _PromptSys_KeyChar=0 End Function Function Input$(length As Long) As String Dim i As Long If length<=0 Then Input$="" Exit Function End If i=0 While 1 If _PromptSys_KeyChar Then Input$=Input$+Chr$(_PromptSys_KeyChar) _PromptSys_KeyChar=0 i++ If i>=length Then Exit While End If End If Sleep(1) Wend End Function #endif '_INC_PROMPT