'prompt.sbp #ifndef _INC_PROMPT #define _INC_PROMPT #include Dim _PromptSys_hWnd As HWND Dim _PromptSys_dwThreadID As DWord Dim _PromptSys_bInitFinish As Long 'text Dim _PromptSys_LogFont As LOGFONT Dim _PromptSys_hFont As HFONT Dim _PromptSys_FontSize As SIZE Dim _PromptSys_InputStr[255] As Byte Dim _PromptSys_InputLen As Long Dim _PromptSys_KeyChar As Byte Dim _PromptSys_CurPos As POINTAPI Dim _PromptSys_Buffer[100] As BytePtr Dim _PromptSys_TextColor[100] As DWordPtr Dim _PromptSys_BackColor[100] As DWordPtr Dim _PromptSys_NowTextColor As DWord Dim _PromptSys_NowBackColor As DWord 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 hOldFont As HFONT Dim sz As SIZE Dim temporary[2] As Byte hOldFont=SelectObject(hDC,_PromptSys_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 HeapFree(_System_hProcessHeap,0,_PromptSys_Buffer[0]) HeapFree(_System_hProcessHeap,0,_PromptSys_TextColor[0]) HeapFree(_System_hProcessHeap,0,_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]=HeapAlloc(_System_hProcessHeap,HEAP_ZERO_MEMORY,255) _PromptSys_TextColor[100]=HeapAlloc(_System_hProcessHeap,HEAP_ZERO_MEMORY,255*SizeOf(LONG_PTR)) _PromptSys_BackColor[100]=HeapAlloc(_System_hProcessHeap,HEAP_ZERO_MEMORY,255*SizeOf(LONG_PTR)) _PromptSys_CurPos.y=_PromptSys_CurPos.y-1 'Redraw StartLine=-1 Wend i=0 While i*_PromptSys_FontSize.cy-1 Then hIMC=ImmGetContext(hWnd) If hIMC Then CompForm.dwStyle=CFS_POINT CompForm.ptCurrentPos.x=_PromptSys_CurPos.x*_PromptSys_FontSize.cx CompForm.ptCurrentPos.y=_PromptSys_CurPos.y*_PromptSys_FontSize.cy ImmSetCompositionWindow(hIMC,CompForm) ImmSetCompositionFont(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_InputLen-1 _PromptSys_InputStr[_PromptSys_InputLen]=0 _PromptSys_CurPos.x=_PromptSys_CurPos.x-1 _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) hGlobal=GetClipboardData(CF_TEXT) If hGlobal=0 Then PromptProc=0:Exit Function pTemp=GlobalLock(hGlobal) As *Byte TempStr=ZeroString(lstrlen(pTemp)+1) lstrcpy(StrPtr(TempStr),pTemp) lstrcpy((VarPtr(_PromptSys_InputStr[0])+_PromptSys_InputLen) As *Byte,pTemp) _PromptSys_InputLen=_PromptSys_InputLen+lstrlen(pTemp) GlobalUnlock(hGlobal) CloseClipboard() Else _PromptSys_InputStr[_PromptSys_InputLen]=wParam As Byte _PromptSys_InputLen=_PromptSys_InputLen+1 temporary[0]=wParam As Byte temporary[1]=0 TempStr=temporary 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]=HeapAlloc(_System_hProcessHeap,HEAP_ZERO_MEMORY,255) _PromptSys_TextColor[i]=HeapAlloc(_System_hProcessHeap,HEAP_ZERO_MEMORY,255*SizeOf(LONG_PTR)) _PromptSys_BackColor[i]=HeapAlloc(_System_hProcessHeap,HEAP_ZERO_MEMORY,255*SizeOf(LONG_PTR)) 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 _PromptSys_LogFont.lfHeight=-16 _PromptSys_LogFont.lfWidth=0 _PromptSys_LogFont.lfEscapement=0 _PromptSys_LogFont.lfOrientation=0 _PromptSys_LogFont.lfWeight=0 _PromptSys_LogFont.lfItalic=0 _PromptSys_LogFont.lfUnderline=0 _PromptSys_LogFont.lfStrikeOut=0 _PromptSys_LogFont.lfCharSet=SHIFTJIS_CHARSET _PromptSys_LogFont.lfOutPrecision=OUT_DEFAULT_PRECIS _PromptSys_LogFont.lfClipPrecision=CLIP_DEFAULT_PRECIS _PromptSys_LogFont.lfQuality=DEFAULT_QUALITY _PromptSys_LogFont.lfPitchAndFamily=FIXED_PITCH lstrcpy(_PromptSys_LogFont.lfFaceName,"MS 明朝") _PromptSys_hFont=CreateFontIndirect(_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) RegisterClassEx(wcl) 'Create Prompt Window _PromptSys_hWnd=CreateWindowEx(WS_EX_CLIENTEDGE,"PROMPT","BASIC PROMPT",WS_OVERLAPPEDWINDOW,CW_USEDEFAULT,CW_USEDEFAULT,CW_USEDEFAULT,CW_USEDEFAULT,0,0,GetModuleHandle(0),0) ShowWindow(_PromptSys_hWnd,SW_SHOW) 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 EnterCriticalSection(_PromptSys_SectionOfBufferAccess) For i=0 to 100 HeapFree(_System_hProcessHeap,0,_PromptSys_Buffer[i]) HeapFree(_System_hProcessHeap,0,_PromptSys_TextColor[i]) HeapFree(_System_hProcessHeap,0,_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]=Asc(",") Then buf.Chars[i3]=0 Exit While End If buf.Chars[i3]=_PromptSys_InputStr[i2] If _PromptSys_InputStr[i2]=0 Then Exit While i2=i2+1 i3=i3+1 Wend Select Case _System_InputDataType[i] Case _System_Type_Double SetDouble(_System_InputDataPtr[i],Val(buf)) Case _System_Type_Single SetSingle(_System_InputDataPtr[i],Val(buf)) Case _System_Type_Int64,_System_Type_QWord SetQWord(_System_InputDataPtr[i],Val(buf)) Case _System_Type_Long,_System_Type_DWord SetDWord(_System_InputDataPtr[i],Val(buf)) Case _System_Type_Integer,_System_Type_Word SetWord(_System_InputDataPtr[i],Val(buf)) Case _System_Type_Char,_System_Type_Byte SetByte(_System_InputDataPtr[i],Val(buf)) Case _System_Type_String Dim pTempStr As *String pTempStr=_System_InputDataPtr[i] As *String pTempStr->Length=i3 pTempStr->Chars=_System_realloc(pTempStr->Chars,pTempStr->Length+1) memcpy(pTempStr->Chars,buf.Chars,pTempStr->Length) pTempStr->Chars[pTempStr->Length]=0 End Select i=i+1 If _System_InputDataPtr[i]=0 and _PromptSys_InputStr[i2]=Asc(",") Then 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=i2+1 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=i+1 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 As Long Dim hPen As Long, hOldPen As Long Dim hBrush As Long, hOldBrush As Long hDC=GetDC(_PromptSys_hWnd) hPen=CreatePen(PS_SOLID,1,GetBasicColor(ColorCode)) If fType=2 Then hBrush=CreateSolidBrush(GetBasicColor(BrushColor)) Else hBrush=GetStockObject(NULL_BRUSH) End If SelectObject(hDC,hPen) SelectObject(hDC,hBrush) hOldPen=SelectObject(_PromptSys_hMemDC,hPen) 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 As Long 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 Long Dim hBrush As Long, hOldBrush As Long 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=i+1 If i>=length Then Exit While End If End If Sleep(1) Wend End Function #endif '_INC_PROMPT