source: branch/egtra-gdiplus/basic/prompt.sbp@ 604

Last change on this file since 604 was 208, checked in by イグトランス (egtra), 18 years ago

[207]参照型変数のNothing初期化に対応する修正

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