1 | 'prompt.sbp
|
---|
2 |
|
---|
3 |
|
---|
4 | #ifndef _INC_PROMPT
|
---|
5 | #define _INC_PROMPT
|
---|
6 |
|
---|
7 |
|
---|
8 | #include <api_imm.sbp>
|
---|
9 |
|
---|
10 | Dim _PromptSys_hWnd As HWND
|
---|
11 | Dim _PromptSys_dwThreadID As DWord
|
---|
12 | Dim _PromptSys_bInitFinish As BOOL
|
---|
13 |
|
---|
14 | 'text
|
---|
15 |
|
---|
16 | Dim _PromptSys_LogFont As LOGFONTA 'LOGFONT
|
---|
17 | Dim _PromptSys_hFont As HFONT
|
---|
18 | Dim _PromptSys_FontSize As SIZE
|
---|
19 | Dim _PromptSys_InputStr[255] As Char
|
---|
20 | Dim _PromptSys_InputLen As Long
|
---|
21 | Dim _PromptSys_KeyChar As Byte
|
---|
22 | Dim _PromptSys_CurPos As POINTAPI
|
---|
23 | Dim _PromptSys_Buffer[100] As *Char
|
---|
24 | Dim _PromptSys_TextColor[100] As *COLORREF
|
---|
25 | Dim _PromptSys_BackColor[100] As *COLORREF
|
---|
26 | Dim _PromptSys_TextWidth[100] As Long
|
---|
27 | Dim _PromptSys_NowTextColor As COLORREF
|
---|
28 | Dim _PromptSys_NowBackColor As COLORREF
|
---|
29 | Dim _PromptSys_SectionOfBufferAccess As CRITICAL_SECTION
|
---|
30 |
|
---|
31 |
|
---|
32 | _PromptSys_InputLen=-1
|
---|
33 |
|
---|
34 | 'graphic
|
---|
35 | Dim _PromptSys_hBitmap As HBITMAP
|
---|
36 | Dim _PromptSys_hMemDC As HDC
|
---|
37 | Dim _PromptSys_ScreenSize As SIZE
|
---|
38 | Dim _PromptSys_GlobalPos As POINTAPI
|
---|
39 |
|
---|
40 |
|
---|
41 | _PromptSys_bInitFinish=0
|
---|
42 | CreateThread(0, 0, AddressOf(PromptMain) As LPTHREAD_START_ROUTINE, 0, 0, _PromptSys_dwThreadID)
|
---|
43 | Do
|
---|
44 | Sleep(20)
|
---|
45 | Loop Until _PromptSys_bInitFinish
|
---|
46 |
|
---|
47 | Sub DrawPromptBuffer(hDC As HDC, StartLine As Long, EndLine As Long)
|
---|
48 | Dim i As Long, i2 As Long, i3 As Long
|
---|
49 |
|
---|
50 | Dim hOldFont = SelectObject(hDC, _PromptSys_hFont) As HFONT
|
---|
51 |
|
---|
52 | 'Scroll
|
---|
53 | Dim rc As RECT
|
---|
54 | GetClientRect(_PromptSys_hWnd, rc)
|
---|
55 | While (_PromptSys_CurPos.y+1) * _PromptSys_FontSize.cy > rc.bottom and _PromptSys_CurPos.y > 0
|
---|
56 | _System_free(_PromptSys_Buffer[0])
|
---|
57 | _System_free(_PromptSys_TextColor[0])
|
---|
58 | _System_free(_PromptSys_BackColor[0])
|
---|
59 | For i = 0 To 100 - 1
|
---|
60 | _PromptSys_Buffer[i] = _PromptSys_Buffer[i+1]
|
---|
61 | _PromptSys_TextColor[i] = _PromptSys_TextColor[i+1]
|
---|
62 | _PromptSys_BackColor[i] = _PromptSys_BackColor[i+1]
|
---|
63 | _PromptSys_TextWidth[i] = _PromptSys_TextWidth[i+1]
|
---|
64 | Next
|
---|
65 | _PromptSys_Buffer[100] = _System_calloc(SizeOf (Char) * 255)
|
---|
66 | _PromptSys_TextColor[100] = _System_calloc(SizeOf(COLORREF) * 255)
|
---|
67 | _PromptSys_BackColor[100] = _System_calloc(SizeOf(COLORREF) * 255)
|
---|
68 | _PromptSys_TextWidth[100] = 0
|
---|
69 |
|
---|
70 | _PromptSys_CurPos.y--
|
---|
71 |
|
---|
72 | 'Redraw
|
---|
73 | StartLine = -1
|
---|
74 | Wend
|
---|
75 |
|
---|
76 | i = 0
|
---|
77 | While i * _PromptSys_FontSize.cy < rc.bottom and i <= 100
|
---|
78 | If StartLine=-1 or (StartLine<=i and i<=EndLine) Then
|
---|
79 | Dim sz As SIZE
|
---|
80 | i3 = lstrlen(_PromptSys_Buffer[i])
|
---|
81 | GetTextExtentPoint32(hDC, _PromptSys_Buffer[i], i3, sz)
|
---|
82 |
|
---|
83 | BitBlt(hDC,_
|
---|
84 | sz.cx, i * _PromptSys_FontSize.cy, _
|
---|
85 | rc.right, _PromptSys_FontSize.cy, _
|
---|
86 | _PromptSys_hMemDC, sz.cx, i * _PromptSys_FontSize.cy, SRCCOPY)
|
---|
87 |
|
---|
88 | Dim width = 0 As Long
|
---|
89 | For i2 = 0 To i3-1
|
---|
90 | SetTextColor(hDC, _PromptSys_TextColor[i][i2])
|
---|
91 | If _PromptSys_BackColor[i][i2] = -1 Then
|
---|
92 | SetBkMode(hDC, TRANSPARENT)
|
---|
93 | Else
|
---|
94 | SetBkMode(hDC, OPAQUE)
|
---|
95 | SetBkColor(hDC, _PromptSys_BackColor[i][i2])
|
---|
96 | End If
|
---|
97 |
|
---|
98 | Dim temporary[2] As Char
|
---|
99 | Dim tempLen As Long
|
---|
100 | temporary[0] = _PromptSys_Buffer[i][i2]
|
---|
101 | #ifdef UNICODE
|
---|
102 | If _System_IsSurrogatePair(_PromptSys_Buffer[i][i2], _PromptSys_Buffer[i][i2+1]) Then
|
---|
103 | #else
|
---|
104 | If IsDBCSLeadByte(temporary[0]) Then
|
---|
105 | #endif
|
---|
106 | temporary[1] = _PromptSys_Buffer[i][i2+1]
|
---|
107 | temporary[2] = 0
|
---|
108 | i2++
|
---|
109 | tempLen = 2
|
---|
110 | Else
|
---|
111 | temporary[1] = 0
|
---|
112 | tempLen = 1
|
---|
113 | End If
|
---|
114 | With _PromptSys_FontSize
|
---|
115 | TextOut(hDC, width, i * .cy, temporary, tempLen)
|
---|
116 | End With
|
---|
117 | GetTextExtentPoint32(hDC, temporary, i3, sz)
|
---|
118 | width += sz.cx
|
---|
119 | Next
|
---|
120 | End If
|
---|
121 |
|
---|
122 | i++
|
---|
123 | Wend
|
---|
124 |
|
---|
125 | SelectObject(hDC, hOldFont)
|
---|
126 | End Sub
|
---|
127 |
|
---|
128 | Sub PRINT_ToPrompt(buf As String)
|
---|
129 | EnterCriticalSection(_PromptSys_SectionOfBufferAccess)
|
---|
130 | With _PromptSys_CurPos
|
---|
131 | Dim StartLine As Long
|
---|
132 | StartLine = .y
|
---|
133 | 'Addition
|
---|
134 | Dim i2 = 0 As Long, i3 As Long
|
---|
135 | Do
|
---|
136 | If buf[i2] = 9 Then 'tab
|
---|
137 | i3 = 8 - (.x And 7) '(.x mod 8)
|
---|
138 | _System_FillChar(VarPtr(_PromptSys_Buffer[.y][.x]), i3, &h20) 'Asc(" ")
|
---|
139 | i2++
|
---|
140 | .x += i3
|
---|
141 | Continue
|
---|
142 | End If
|
---|
143 |
|
---|
144 | If buf[i2] = 13 and buf[i2+1] = 10 Then '\r\n
|
---|
145 | i2 += 2
|
---|
146 | .y++
|
---|
147 | .x = 0
|
---|
148 | Continue
|
---|
149 | End If
|
---|
150 |
|
---|
151 | If buf[i2] = 0 Then Exit Do
|
---|
152 | _PromptSys_Buffer[.y][.x] = buf[i2]
|
---|
153 | _PromptSys_TextColor[.y][.x] = _PromptSys_NowTextColor
|
---|
154 | _PromptSys_BackColor[.y][.x] = _PromptSys_NowBackColor
|
---|
155 |
|
---|
156 | i2++
|
---|
157 | .x++
|
---|
158 | Loop
|
---|
159 |
|
---|
160 | 'Draw the text buffer added
|
---|
161 | Dim hDC = GetDC(_PromptSys_hWnd)
|
---|
162 | DrawPromptBuffer(hDC, StartLine, .y)
|
---|
163 | ReleaseDC(_PromptSys_hWnd, hDC)
|
---|
164 | End With
|
---|
165 | LeaveCriticalSection(_PromptSys_SectionOfBufferAccess)
|
---|
166 | End Sub
|
---|
167 |
|
---|
168 | Function PromptProc(hWnd As HWND, message As DWord, wParam As WPARAM, lParam As LPARAM) As LRESULT
|
---|
169 | Dim hIMC As HIMC
|
---|
170 | Dim hDC As HDC
|
---|
171 | Dim ps As PAINTSTRUCT
|
---|
172 | Dim TempStr As String
|
---|
173 | Dim CompForm As COMPOSITIONFORM
|
---|
174 |
|
---|
175 | Select Case message
|
---|
176 | Case WM_CREATE
|
---|
177 | hDC = GetDC(hWnd)
|
---|
178 | With _PromptSys_ScreenSize
|
---|
179 | _PromptSys_hBitmap = CreateCompatibleBitmap(hDC, .cx, .cy)
|
---|
180 | End With
|
---|
181 | _PromptSys_hMemDC = CreateCompatibleDC(hDC)
|
---|
182 | SelectObject(_PromptSys_hMemDC, _PromptSys_hBitmap)
|
---|
183 |
|
---|
184 | 'Initialize for Win9x
|
---|
185 | Dim hOldBrush = SelectObject(_PromptSys_hMemDC, GetStockObject(BLACK_BRUSH)) As HBRUSH
|
---|
186 | With _PromptSys_ScreenSize
|
---|
187 | PatBlt(_PromptSys_hMemDC, 0, 0, .cx, .cy, PATCOPY)
|
---|
188 | End With
|
---|
189 | SelectObject(_PromptSys_hMemDC, hOldBrush)
|
---|
190 |
|
---|
191 | Dim tm As TEXTMETRIC
|
---|
192 | Dim hOldFont = SelectObject(_PromptSys_hMemDC, _PromptSys_hFont) As HFONT
|
---|
193 | GetTextExtentPoint32(_PromptSys_hMemDC, " " As PCTSTR, 1, _PromptSys_FontSize)
|
---|
194 | GetTextMetrics(_PromptSys_hMemDC, tm)
|
---|
195 | SelectObject(_PromptSys_hMemDC, hOldFont)
|
---|
196 | _PromptSys_FontSize.cy = tm.tmHeight
|
---|
197 |
|
---|
198 | ReleaseDC(hWnd,hDC)
|
---|
199 | Case WM_PAINT
|
---|
200 | hDC = BeginPaint(hWnd, ps)
|
---|
201 | /*
|
---|
202 | With _PromptSys_ScreenSize
|
---|
203 | BitBlt(hDC, 0, 0, .cx, .cy, _PromptSys_hMemDC, 0, 0, SRCCOPY)
|
---|
204 | */
|
---|
205 | With ps.rcPaint
|
---|
206 | BitBlt(hDC, .left, .top, .right - .left, .bottom - .top, _PromptSys_hMemDC, .left, .top, SRCCOPY)
|
---|
207 | End With
|
---|
208 | DrawPromptBuffer(hDC, -1, 0)
|
---|
209 | EndPaint(hWnd, ps)
|
---|
210 |
|
---|
211 | _PromptSys_bInitFinish = TRUE
|
---|
212 | Case WM_SETFOCUS
|
---|
213 | If _PromptSys_InputLen<>-1 Then
|
---|
214 | hIMC = ImmGetContext(hWnd)
|
---|
215 | If hIMC Then
|
---|
216 | With CompForm
|
---|
217 | .dwStyle = CFS_POINT
|
---|
218 | .ptCurrentPos.x = _PromptSys_CurPos.x * _PromptSys_FontSize.cx
|
---|
219 | .ptCurrentPos.y = _PromptSys_CurPos.y * _PromptSys_FontSize.cy
|
---|
220 | End With
|
---|
221 | ImmSetCompositionWindow(hIMC, CompForm)
|
---|
222 | ImmSetCompositionFontA(hIMC, _PromptSys_LogFont)
|
---|
223 | End If
|
---|
224 | ImmReleaseContext(hWnd, hIMC)
|
---|
225 |
|
---|
226 | CreateCaret(hWnd, NULL, 9, 6)
|
---|
227 | SetCaretPos(_PromptSys_CurPos.x*_PromptSys_FontSize.cx, _
|
---|
228 | (_PromptSys_CurPos.y+1)*_PromptSys_FontSize.cy-7)
|
---|
229 | ShowCaret(hWnd)
|
---|
230 | End If
|
---|
231 | Case WM_KILLFOCUS
|
---|
232 | HideCaret(hWnd)
|
---|
233 | DestroyCaret()
|
---|
234 | Case WM_KEYDOWN
|
---|
235 | If _PromptSys_InputLen=-1 Then
|
---|
236 | _PromptSys_KeyChar=wParam As Byte
|
---|
237 | End If
|
---|
238 | Case WM_CHAR
|
---|
239 | If _PromptSys_InputLen <> -1 Then
|
---|
240 | If wParam = VK_BACK Then
|
---|
241 | If _PromptSys_InputLen Then
|
---|
242 | _PromptSys_InputLen--
|
---|
243 | _PromptSys_InputStr[_PromptSys_InputLen] = 0
|
---|
244 |
|
---|
245 | _PromptSys_CurPos.x--
|
---|
246 | _PromptSys_Buffer[_PromptSys_CurPos.y][_PromptSys_CurPos.x] = 0
|
---|
247 | End If
|
---|
248 | ElseIf wParam = VK_RETURN Then
|
---|
249 | _PromptSys_InputStr[_PromptSys_InputLen] = 0
|
---|
250 | _PromptSys_InputLen = -1
|
---|
251 | TempStr = Ex"\r\n"
|
---|
252 | ElseIf wParam = &H16 Then
|
---|
253 | 'Paste Command(Use Clippboard)
|
---|
254 | OpenClipboard(hWnd)
|
---|
255 | Dim hGlobal = GetClipboardData(CF_TEXT) As HGLOBAL
|
---|
256 | If hGlobal = 0 Then Return 0
|
---|
257 | Dim pTemp = GlobalLock(hGlobal) As PCSTR
|
---|
258 | #ifdef UNICODE 'A版ウィンドウプロシージャ用
|
---|
259 | Dim tempSizeA = lstrlenA(pTemp)
|
---|
260 | Dim tempSizeW = MultiByteToWideChar(CP_ACP, 0, pTemp, tempSizeA, 0, 0) + 1
|
---|
261 | TempStr = ZeroString(tempSizeW)
|
---|
262 | MultiByteToWideChar(CP_ACP, 0, pTemp, tempSizeA, StrPtr(TempStr), tempSizeW)
|
---|
263 | #else
|
---|
264 | TempStr = ZeroString(lstrlen(pTemp) + 1)
|
---|
265 | lstrcpy(StrPtr(TempStr), pTemp)
|
---|
266 | #endif
|
---|
267 | memcpy(VarPtr(_PromptSys_InputStr[_PromptSys_InputLen]), TempStr.Chars, SizeOf (Char) * TempStr.Length)
|
---|
268 | _PromptSys_InputLen += TempStr.Length
|
---|
269 |
|
---|
270 | GlobalUnlock(hGlobal)
|
---|
271 | CloseClipboard()
|
---|
272 | Else
|
---|
273 | _PromptSys_InputStr[_PromptSys_InputLen] = wParam As Byte
|
---|
274 | _PromptSys_InputLen++
|
---|
275 |
|
---|
276 | TempStr.ReSize(1)
|
---|
277 | TempStr[0] = wParam As Char
|
---|
278 | End If
|
---|
279 |
|
---|
280 | SendMessage(hWnd, WM_KILLFOCUS, 0, 0)
|
---|
281 | PRINT_ToPrompt(TempStr)
|
---|
282 | SendMessage(hWnd, WM_SETFOCUS, 0, 0)
|
---|
283 | End If
|
---|
284 | Case WM_IME_COMPOSITION
|
---|
285 | Return _PromptSys_OnImeCompostion(hWnd, wParam, lParam)
|
---|
286 | Case WM_DESTROY
|
---|
287 | DeleteDC(_PromptSys_hMemDC)
|
---|
288 | DeleteObject(_PromptSys_hBitmap)
|
---|
289 |
|
---|
290 | PostQuitMessage(0)
|
---|
291 | Case Else
|
---|
292 | PromptProc=DefWindowProc(hWnd,message,wParam,lParam)
|
---|
293 | Exit Function
|
---|
294 | End Select
|
---|
295 | PromptProc=0
|
---|
296 | End Function
|
---|
297 |
|
---|
298 | Function _PromptSys_OnImeCompostion(hwnd As HWND, wp As WPARAM, lp As LPARAM) As LRESULT
|
---|
299 | If (lp And GCS_RESULTSTR) <> 0 Then
|
---|
300 | Dim himc = ImmGetContext(hwnd)
|
---|
301 | If himc = 0 Then
|
---|
302 | 'Debug
|
---|
303 | Return 0
|
---|
304 | End If
|
---|
305 | Dim size = ImmGetCompositionString(himc, GCS_RESULTSTR, 0, 0) 'sizeはバイト単位
|
---|
306 | Dim str = _System_malloc(size) As PTSTR
|
---|
307 | If str = 0 Then
|
---|
308 | 'Debug
|
---|
309 | Return 0
|
---|
310 | End If
|
---|
311 | ImmGetCompositionString(himc, GCS_RESULTSTR, str, size)
|
---|
312 | ImmReleaseContext(hwnd, himc)
|
---|
313 |
|
---|
314 | memcpy(VarPtr(_PromptSys_InputStr[_PromptSys_InputLen]), str, size)
|
---|
315 | _PromptSys_InputLen += size
|
---|
316 |
|
---|
317 | Dim tempStr As String(str, size \ SizeOf (Char))
|
---|
318 | _System_free(str)
|
---|
319 |
|
---|
320 | SendMessage(hwnd, WM_KILLFOCUS, 0, 0)
|
---|
321 | PRINT_ToPrompt(tempStr)
|
---|
322 | SendMessage(hwnd, WM_SETFOCUS, 0, 0)
|
---|
323 |
|
---|
324 | Return 0
|
---|
325 | Else
|
---|
326 | Return DefWindowProc(hwnd, WM_IME_COMPOSITION, wp, lp)
|
---|
327 | End If
|
---|
328 | End Function
|
---|
329 |
|
---|
330 | Function PromptMain(dwData As Long) As Long
|
---|
331 | Dim i As Long
|
---|
332 |
|
---|
333 | 'Allocate
|
---|
334 | For i=0 To 100
|
---|
335 | _PromptSys_Buffer[i] = _System_calloc(SizeOf (Char) * 255)
|
---|
336 | _PromptSys_TextColor[i] = _System_calloc(SizeOf(COLORREF) * 255)
|
---|
337 | _PromptSys_BackColor[i] = _System_calloc(SizeOf(COLORREF) * 255)
|
---|
338 | Next
|
---|
339 |
|
---|
340 | 'Current Colors initialize
|
---|
341 | _PromptSys_NowTextColor=RGB(255,255,255)
|
---|
342 | _PromptSys_NowBackColor=RGB(0,0,0)
|
---|
343 |
|
---|
344 | 'Setup
|
---|
345 | With _PromptSys_ScreenSize
|
---|
346 | .cx = GetSystemMetrics(SM_CXSCREEN)
|
---|
347 | .cy = GetSystemMetrics(SM_CYSCREEN)
|
---|
348 | End With
|
---|
349 |
|
---|
350 | 'LogFont initialize
|
---|
351 | With _PromptSys_LogFont
|
---|
352 | .lfHeight = -16
|
---|
353 | .lfWidth = 0
|
---|
354 | .lfEscapement = 0
|
---|
355 | .lfOrientation = 0
|
---|
356 | .lfWeight = 0
|
---|
357 | .lfItalic = 0
|
---|
358 | .lfUnderline = 0
|
---|
359 | .lfStrikeOut = 0
|
---|
360 | .lfCharSet = SHIFTJIS_CHARSET
|
---|
361 | .lfOutPrecision = OUT_DEFAULT_PRECIS
|
---|
362 | .lfClipPrecision = CLIP_DEFAULT_PRECIS
|
---|
363 | .lfQuality = DEFAULT_QUALITY
|
---|
364 | .lfPitchAndFamily = FIXED_PITCH
|
---|
365 | #ifdef UNICODE
|
---|
366 | WideCharToMultiByte(CP_ACP, 0, "MS 明朝", 5, .lfFaceName, LF_FACESIZE, 0, 0)
|
---|
367 | #else
|
---|
368 | lstrcpy(.lfFaceName, "MS 明朝")
|
---|
369 | #endif
|
---|
370 | End With
|
---|
371 |
|
---|
372 | _PromptSys_hFont = CreateFontIndirectA(ByVal VarPtr(_PromptSys_LogFont))
|
---|
373 |
|
---|
374 | 'Critical Section
|
---|
375 | InitializeCriticalSection(_PromptSys_SectionOfBufferAccess)
|
---|
376 |
|
---|
377 | 'Regist Prompt Class
|
---|
378 | Dim wcl As WNDCLASSEX
|
---|
379 | ZeroMemory(VarPtr(wcl), Len(wcl))
|
---|
380 | With wcl
|
---|
381 | .cbSize = Len(wcl)
|
---|
382 | .hInstance = GetModuleHandle(0)
|
---|
383 | .style = CS_HREDRAW or CS_VREDRAW' or CS_DBLCLKS
|
---|
384 | .hIcon = LoadIcon(NULL, MAKEINTRESOURCE(IDI_APPLICATION))
|
---|
385 | .hIconSm = LoadIcon(NULL, MAKEINTRESOURCE(IDI_WINLOGO))
|
---|
386 | .hCursor = LoadCursor(NULL, MAKEINTRESOURCE(IDC_ARROW))
|
---|
387 | .lpszClassName = "PROMPT"
|
---|
388 | .lpfnWndProc = AddressOf(PromptProc)
|
---|
389 | .hbrBackground = GetStockObject(BLACK_BRUSH)
|
---|
390 | End With
|
---|
391 | Dim atom = RegisterClassEx(wcl)
|
---|
392 |
|
---|
393 | 'Create Prompt Window
|
---|
394 | _PromptSys_hWnd = CreateWindowEx(WS_EX_CLIENTEDGE, atom As ULONG_PTR As PCSTR, "BASIC PROMPT",
|
---|
395 | WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT,
|
---|
396 | 0, 0, wcl.hInstance, 0)
|
---|
397 | ShowWindow(_PromptSys_hWnd, SW_SHOW)
|
---|
398 | UpdateWindow(_PromptSys_hWnd)
|
---|
399 |
|
---|
400 | Dim msg As MSG
|
---|
401 | Do
|
---|
402 | Dim iResult = GetMessage(msg, 0, 0, 0)
|
---|
403 | If iResult = 0 or iResult = -1 Then Exit Do
|
---|
404 | TranslateMessage(msg)
|
---|
405 | DispatchMessage(msg)
|
---|
406 | Loop
|
---|
407 |
|
---|
408 | '強制的に終了する
|
---|
409 | ExitProcess(0)
|
---|
410 |
|
---|
411 | EnterCriticalSection(_PromptSys_SectionOfBufferAccess)
|
---|
412 |
|
---|
413 | For i=0 to 100
|
---|
414 | _System_free(_PromptSys_Buffer[i])
|
---|
415 | _System_free(_PromptSys_TextColor[i])
|
---|
416 | _System_free(_PromptSys_BackColor[i])
|
---|
417 | Next
|
---|
418 |
|
---|
419 | LeaveCriticalSection(_PromptSys_SectionOfBufferAccess)
|
---|
420 |
|
---|
421 | DeleteCriticalSection(_PromptSys_SectionOfBufferAccess)
|
---|
422 |
|
---|
423 | ExitProcess(0)
|
---|
424 | End Function
|
---|
425 |
|
---|
426 |
|
---|
427 | '----------------------
|
---|
428 | ' Prompt text Commands
|
---|
429 | '----------------------
|
---|
430 |
|
---|
431 | Macro CLS()(num As Long)
|
---|
432 | Dim i As Long
|
---|
433 | Dim hOldBrush As HBRUSH
|
---|
434 |
|
---|
435 | 'When parameter was omitted, num is set to 1
|
---|
436 | If num=0 Then num=1
|
---|
437 |
|
---|
438 | If num=1 or num=3 Then
|
---|
439 | 'Clear the text screen
|
---|
440 | For i = 0 To 100
|
---|
441 | _System_FillChar(_PromptSys_Buffer[i],255,0)
|
---|
442 | Next
|
---|
443 | With _PromptSys_CurPos
|
---|
444 | .x = 0
|
---|
445 | .y = 0
|
---|
446 | End With
|
---|
447 | End If
|
---|
448 |
|
---|
449 | If num=2 or num=3 Then
|
---|
450 | 'Clear the graphics screen
|
---|
451 | hOldBrush=SelectObject(_PromptSys_hMemDC,GetStockObject(BLACK_BRUSH))
|
---|
452 | PatBlt(_PromptSys_hMemDC,0,0,_PromptSys_ScreenSize.cx,_PromptSys_ScreenSize.cy,PATCOPY)
|
---|
453 | SelectObject(_PromptSys_hMemDC,hOldBrush)
|
---|
454 | End If
|
---|
455 |
|
---|
456 | 'Redraw
|
---|
457 | InvalidateRect(_PromptSys_hWnd,ByVal 0,0)
|
---|
458 | End Macro
|
---|
459 |
|
---|
460 | Macro COLOR(TextColorCode As Long)(BackColorCode As Long)
|
---|
461 | _PromptSys_NowTextColor=GetBasicColor(TextColorCode)
|
---|
462 | If BackColorCode=-1 Then
|
---|
463 | _PromptSys_NowBackColor=-1
|
---|
464 | Else
|
---|
465 | _PromptSys_NowBackColor=GetBasicColor(BackColorCode)
|
---|
466 | End If
|
---|
467 | End Macro
|
---|
468 |
|
---|
469 | '---------- Defined in "command.sbp" ----------
|
---|
470 | 'Dim _System_InputDataPtr[_System_MAX_PARMSNUM] As VoidPtr
|
---|
471 | 'Dim _System_InputDataType[_System_MAX_PARMSNUM] As DWord
|
---|
472 | '----------------------------------------------
|
---|
473 | Sub INPUT_FromPrompt(ShowStr As String)
|
---|
474 | Dim i As Long ,i2 As Long, i3 As Long
|
---|
475 | Dim buf As String
|
---|
476 |
|
---|
477 | *InputReStart
|
---|
478 |
|
---|
479 | PRINT_ToPrompt(ShowStr)
|
---|
480 |
|
---|
481 | 'Input by keyboard
|
---|
482 | _PromptSys_InputLen=0
|
---|
483 | SendMessage(_PromptSys_hWnd,WM_SETFOCUS,0,0)
|
---|
484 | While _PromptSys_InputLen<>-1
|
---|
485 | Sleep(10)
|
---|
486 | Wend
|
---|
487 | SendMessage(_PromptSys_hWnd,WM_KILLFOCUS,0,0)
|
---|
488 |
|
---|
489 | 'Set value to variable
|
---|
490 | i = 0
|
---|
491 | i2 = 0
|
---|
492 | buf = ZeroString(lstrlen(_PromptSys_InputStr))
|
---|
493 | While 1
|
---|
494 | i3 = 0
|
---|
495 | While 1
|
---|
496 | If _PromptSys_InputStr[i2] = &h2c Then
|
---|
497 | buf.Chars[i3] = 0
|
---|
498 | Exit While
|
---|
499 | End If
|
---|
500 |
|
---|
501 | buf.Chars[i3] = _PromptSys_InputStr[i2]
|
---|
502 |
|
---|
503 | If _PromptSys_InputStr[i2] = 0 Then Exit While
|
---|
504 |
|
---|
505 | i2++
|
---|
506 | i3++
|
---|
507 | Wend
|
---|
508 |
|
---|
509 | _System_Input_SetArgument(_System_InputDataPtr[i], _System_InputDataType[i], buf, i3)
|
---|
510 |
|
---|
511 | i++
|
---|
512 | If _System_InputDataPtr[i]=0 and _PromptSys_InputStr[i2]=&h2c Then 'Asc(",")
|
---|
513 | PRINT_ToPrompt(Ex"入力データの個数が多すぎます\r\n")
|
---|
514 | Goto *InputReStart
|
---|
515 | ElseIf _PromptSys_InputStr[i2]=0 Then
|
---|
516 | If _System_InputDataPtr[i]<>0 Then
|
---|
517 | PRINT_ToPrompt(Ex"入力データの個数が足りません\r\n")
|
---|
518 | Goto *InputReStart
|
---|
519 | Else
|
---|
520 | Exit While
|
---|
521 | End If
|
---|
522 | End If
|
---|
523 |
|
---|
524 | i2++
|
---|
525 | Wend
|
---|
526 | End Sub
|
---|
527 |
|
---|
528 | Sub PRINTUSING_ToPrompt(UsingStr As String)
|
---|
529 | PRINT_ToPrompt(_System_GetUsingFormat(UsingStr))
|
---|
530 | End Sub
|
---|
531 |
|
---|
532 | Macro LOCATE(x As Long, y As Long)
|
---|
533 | Dim i As Long, i2 As Long
|
---|
534 |
|
---|
535 | If x<0 Then x=0
|
---|
536 | If y<0 Then y=0
|
---|
537 | If y>100 Then y=100
|
---|
538 | With _PromptSys_CurPos
|
---|
539 | .x = x
|
---|
540 | .y = y
|
---|
541 | End With
|
---|
542 | i=0
|
---|
543 | While _PromptSys_Buffer[y][i]
|
---|
544 | i++
|
---|
545 | Wend
|
---|
546 |
|
---|
547 | If i < x Then
|
---|
548 | _System_FillChar(VarPtr(_PromptSys_Buffer[y][i]), x - i, &h20) 'Asc(" ")
|
---|
549 | For i2 = i To x - 1
|
---|
550 | _PromptSys_BackColor[y][i2] = -1
|
---|
551 | Next
|
---|
552 | End If
|
---|
553 | End Macro
|
---|
554 |
|
---|
555 |
|
---|
556 | '-------------------
|
---|
557 | ' Graphics Commands
|
---|
558 | '-------------------
|
---|
559 |
|
---|
560 | 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)
|
---|
561 | '呼び出し方法は以下のようになります(コンパイラがパラメータの並びを最適化します)
|
---|
562 | 'Circle (x, y), radius [, color] [, start] [, end] [, aspect] [, f] [, color2]
|
---|
563 |
|
---|
564 | Dim hBrush As HBRUSH
|
---|
565 | Dim radi2 As Long
|
---|
566 | Dim sw As Long
|
---|
567 | Dim i1 As Long, i2 As Long, i3 As Long, i4 As Long
|
---|
568 |
|
---|
569 | Dim hPen = CreatePen(PS_SOLID,1,GetBasicColor(ColorCode))
|
---|
570 | If bFill Then
|
---|
571 | hBrush=CreateSolidBrush(GetBasicColor(BrushColor))
|
---|
572 | Else
|
---|
573 | hBrush=GetStockObject(NULL_BRUSH)
|
---|
574 | End If
|
---|
575 |
|
---|
576 | Dim hDC=GetDC(_PromptSys_hWnd)
|
---|
577 | SelectObject(hDC,hPen)
|
---|
578 | SelectObject(hDC,hBrush)
|
---|
579 | Dim hOldPen=SelectObject(_PromptSys_hMemDC,hPen)
|
---|
580 | Dim hOldBrush=SelectObject(_PromptSys_hMemDC,hBrush)
|
---|
581 |
|
---|
582 | If Aspect<1 Then
|
---|
583 | radi2=(CDbl(radius)*Aspect) As Long
|
---|
584 | Else
|
---|
585 | radi2=radius
|
---|
586 | radius=(CDbl(radius)/Aspect) As Long
|
---|
587 | End If
|
---|
588 |
|
---|
589 | If StartPos=0 And EndPos=0 Then
|
---|
590 | Ellipse(hDC,x-radius,y-radi2,x+radius,y+radi2)
|
---|
591 | Ellipse(_PromptSys_hMemDC,x-radius,y-radi2,x+radius,y+radi2)
|
---|
592 | Else
|
---|
593 | StartPos *=StartPos
|
---|
594 | EndPos *=EndPos
|
---|
595 |
|
---|
596 | If StartPos<0 Or EndPos<0 Then
|
---|
597 | sw=1
|
---|
598 | Else
|
---|
599 | sw=0
|
---|
600 | End If
|
---|
601 |
|
---|
602 | StartPos = Abs(StartPos)
|
---|
603 | EndPos = Abs(EndPos)
|
---|
604 |
|
---|
605 | If StartPos<=78.5 Then
|
---|
606 | i1=78
|
---|
607 | i2=Int(StartPos)
|
---|
608 | ElseIf StartPos<=235.5 Then
|
---|
609 | StartPos -= 78.5
|
---|
610 | i1=78-Int(StartPos)
|
---|
611 | i2=78
|
---|
612 | ElseIf StartPos<=392.5 Then
|
---|
613 | StartPos -= 235.5
|
---|
614 | i1=-78
|
---|
615 | i2=78-Int(StartPos)
|
---|
616 | ElseIf StartPos<=549.5 Then
|
---|
617 | StartPos -= 392.5
|
---|
618 | i1=-78+Int(StartPos)
|
---|
619 | i2=-78
|
---|
620 | ElseIf StartPos<=628 Then
|
---|
621 | StartPos -= 549.5
|
---|
622 | i1=78
|
---|
623 | i2=-78+Int(StartPos)
|
---|
624 | End If
|
---|
625 |
|
---|
626 | If EndPos<=78.5 Then
|
---|
627 | i3=78
|
---|
628 | i4=Int(EndPos)
|
---|
629 | ElseIf EndPos<=235.5 Then
|
---|
630 | EndPos -= 78.5
|
---|
631 | i3=78-Int(EndPos)
|
---|
632 | i4=78
|
---|
633 | ElseIf EndPos<=392.5 Then
|
---|
634 | EndPos -= 235.5
|
---|
635 | i3=-78
|
---|
636 | i4=78-Int(EndPos)
|
---|
637 | ElseIf EndPos<=549.5 Then
|
---|
638 | EndPos -= 392.5
|
---|
639 | i3=-78+Int(EndPos)
|
---|
640 | i4=-78
|
---|
641 | ElseIf EndPos<=628 Then
|
---|
642 | EndPos -= 549.5
|
---|
643 | i3=78
|
---|
644 | i4=-78+Int(EndPos)
|
---|
645 | End If
|
---|
646 |
|
---|
647 | If sw Then
|
---|
648 | Pie(hDC,x-radius,y-radi2,x+radius,y+radi2, x+i1,y-i2,x+i3,y-i4)
|
---|
649 | Pie(_PromptSys_hMemDC,x-radius,y-radi2,x+radius,y+radi2, x+i1,y-i2,x+i3,y-i4)
|
---|
650 | Else
|
---|
651 | Arc(hDC,x-radius,y-radi2,x+radius,y+radi2, x+i1,y-i2,x+i3,y-i4)
|
---|
652 | Arc(_PromptSys_hMemDC,x-radius,y-radi2,x+radius,y+radi2, x+i1,y-i2,x+i3,y-i4)
|
---|
653 | End If
|
---|
654 | End If
|
---|
655 |
|
---|
656 | ReleaseDC(_PromptSys_hWnd,hDC)
|
---|
657 | SelectObject(_PromptSys_hMemDC,hOldPen)
|
---|
658 | SelectObject(_PromptSys_hMemDC,hOldBrush)
|
---|
659 | DeleteObject(hPen)
|
---|
660 | If bFill Then DeleteObject(hBrush)
|
---|
661 | End Macro
|
---|
662 |
|
---|
663 | 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)
|
---|
664 | '呼び出し方法は以下のようになります(コンパイラがパラメータの並びを最適化します)
|
---|
665 | 'Line (sx,sy)-[STEP](ex,ey),[ColorCode],[B/Bf],[BrushColor]
|
---|
666 | Dim temp As Long
|
---|
667 |
|
---|
668 | If sx=&H80000000 And sy=&H80000000 Then
|
---|
669 | sx=_PromptSys_GlobalPos.x
|
---|
670 | sy=_PromptSys_GlobalPos.y
|
---|
671 | End If
|
---|
672 |
|
---|
673 | If bStep Then
|
---|
674 | ex += sx
|
---|
675 | ey += sy
|
---|
676 | Else
|
---|
677 | If fType Then
|
---|
678 | 'ラインの場合(四角形でない場合)
|
---|
679 | If sx>ex Then
|
---|
680 | temp=ex
|
---|
681 | ex=sx
|
---|
682 | sx=temp
|
---|
683 | End If
|
---|
684 | If sy>ey Then
|
---|
685 | temp=ey
|
---|
686 | ey=sy
|
---|
687 | sy=temp
|
---|
688 | End If
|
---|
689 | End If
|
---|
690 | End If
|
---|
691 |
|
---|
692 | Dim hDC = GetDC(_PromptSys_hWnd)
|
---|
693 | Dim hPen = CreatePen(PS_SOLID, 1, GetBasicColor(ColorCode))
|
---|
694 | Dim hBrush As HBRUSH
|
---|
695 | If fType=2 Then
|
---|
696 | hBrush=CreateSolidBrush(GetBasicColor(BrushColor))
|
---|
697 | Else
|
---|
698 | hBrush=GetStockObject(NULL_BRUSH)
|
---|
699 | End If
|
---|
700 |
|
---|
701 | SelectObject(hDC,hPen)
|
---|
702 | SelectObject(hDC,hBrush)
|
---|
703 | Dim hOldPen = SelectObject(_PromptSys_hMemDC,hPen)
|
---|
704 | Dim hOldBrush = SelectObject(_PromptSys_hMemDC,hBrush)
|
---|
705 |
|
---|
706 | Select Case fType
|
---|
707 | Case 0
|
---|
708 | 'line
|
---|
709 | MoveToEx(_PromptSys_hMemDC,sx,sy,ByVal NULL)
|
---|
710 | LineTo(_PromptSys_hMemDC,ex,ey)
|
---|
711 | SetPixel(_PromptSys_hMemDC,ex,ey,GetBasicColor(ColorCode))
|
---|
712 | MoveToEx(hDC,sx,sy,ByVal NULL)
|
---|
713 | LineTo(hDC,ex,ey)
|
---|
714 | SetPixel(hDC,ex,ey,GetBasicColor(ColorCode))
|
---|
715 | Case Else
|
---|
716 | 'Rectangle
|
---|
717 | Rectangle(hDC,sx,sy,ex+1,ey+1)
|
---|
718 | Rectangle(_PromptSys_hMemDC,sx,sy,ex+1,ey+1)
|
---|
719 | End Select
|
---|
720 |
|
---|
721 | ReleaseDC(_PromptSys_hWnd,hDC)
|
---|
722 | SelectObject(_PromptSys_hMemDC,hOldPen)
|
---|
723 | SelectObject(_PromptSys_hMemDC,hOldBrush)
|
---|
724 | DeleteObject(hPen)
|
---|
725 | If fType=2 Then DeleteObject(hBrush)
|
---|
726 |
|
---|
727 | _PromptSys_GlobalPos.x=ex
|
---|
728 | _PromptSys_GlobalPos.y=ey
|
---|
729 | End Macro
|
---|
730 |
|
---|
731 | Macro PSET(x As Long, y As Long)(ColorCode As Long)
|
---|
732 | '呼び出し方法は以下のようになります(コンパイラがパラメータの並びを最適化します)
|
---|
733 | 'PSet (x,y),ColorCode
|
---|
734 |
|
---|
735 | Dim hDC=GetDC(_PromptSys_hWnd)
|
---|
736 | SetPixel(hDC,x,y,GetBasicColor(ColorCode))
|
---|
737 | SetPixel(_PromptSys_hMemDC,x,y,GetBasicColor(ColorCode))
|
---|
738 | ReleaseDC(_PromptSys_hWnd,hDC)
|
---|
739 |
|
---|
740 | _PromptSys_GlobalPos.x=x
|
---|
741 | _PromptSys_GlobalPos.y=y
|
---|
742 | End Macro
|
---|
743 |
|
---|
744 | Macro PAINT(x As Long, y As Long, BrushColor As Long)(ByVal LineColor As Long)
|
---|
745 | '呼び出し方法は以下のようになります(コンパイラがパラメータの並びを最適化します)
|
---|
746 | 'Paint (x,y),BrushColor,LineColor
|
---|
747 |
|
---|
748 | Dim hDC As HDC
|
---|
749 | Dim hBrush As HBRUSH, hOldBrush As VoidPtr
|
---|
750 |
|
---|
751 | hBrush=CreateSolidBrush(GetBasicColor(BrushColor))
|
---|
752 |
|
---|
753 | hDC=GetDC(_PromptSys_hWnd)
|
---|
754 | SelectObject(hDC,hBrush)
|
---|
755 | hOldBrush=SelectObject(_PromptSys_hMemDC,hBrush)
|
---|
756 |
|
---|
757 | ExtFloodFill(hDC,x,y,GetBasicColor(LineColor),FLOODFILLBORDER)
|
---|
758 | ExtFloodFill(_PromptSys_hMemDC,x,y,GetBasicColor(LineColor),FLOODFILLBORDER)
|
---|
759 |
|
---|
760 | ReleaseDC(_PromptSys_hWnd,hDC)
|
---|
761 | SelectObject(_PromptSys_hMemDC,hOldBrush)
|
---|
762 | DeleteObject(hBrush)
|
---|
763 | End Macro
|
---|
764 |
|
---|
765 |
|
---|
766 | '-----------
|
---|
767 | ' Functions
|
---|
768 | '-----------
|
---|
769 |
|
---|
770 | Function Inkey$() As String
|
---|
771 | If _PromptSys_KeyChar=0 Then
|
---|
772 | Inkey$=""
|
---|
773 | Else
|
---|
774 | Inkey$=Chr$(_PromptSys_KeyChar)
|
---|
775 | End If
|
---|
776 | _PromptSys_KeyChar=0
|
---|
777 | End Function
|
---|
778 |
|
---|
779 | Function Input$(length As Long) As String
|
---|
780 | Dim i As Long
|
---|
781 |
|
---|
782 | If length<=0 Then
|
---|
783 | Input$=""
|
---|
784 | Exit Function
|
---|
785 | End If
|
---|
786 |
|
---|
787 | i=0
|
---|
788 | While 1
|
---|
789 | If _PromptSys_KeyChar Then
|
---|
790 | Input$=Input$+Chr$(_PromptSys_KeyChar)
|
---|
791 | _PromptSys_KeyChar=0
|
---|
792 | i++
|
---|
793 | If i>=length Then
|
---|
794 | Exit While
|
---|
795 | End If
|
---|
796 | End If
|
---|
797 | Sleep(1)
|
---|
798 | Wend
|
---|
799 | End Function
|
---|
800 |
|
---|
801 |
|
---|
802 | #endif '_INC_PROMPT
|
---|