source: Include/basic/prompt.sbp@ 232

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

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

File size: 25.5 KB
RevLine 
[1]1'prompt.sbp
2
3
4#ifndef _INC_PROMPT
5#define _INC_PROMPT
6
7
[126]8#require <api_imm.sbp>
9#require <Classes/System/Math.ab>
[1]10
[142]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
[1]35Dim _PromptSys_hWnd As HWND
36Dim _PromptSys_dwThreadID As DWord
[127]37Dim _PromptSys_hInitFinish As HANDLE
[1]38
39'text
[126]40Type _PromptSys_CharacterInformation
41 ForeColor As COLORREF
42 BackColor As COLORREF
43 StartPos As Long
44End Type
[125]45
[126]46Type _PromptSys_LineInformation
47 Length As Long
[142]48 Text As *StrChar
[126]49 CharInfo As *_PromptSys_CharacterInformation
50End Type
51
[137]52Dim _PromptSys_LogFont As LOGFONT
[1]53Dim _PromptSys_hFont As HFONT
54Dim _PromptSys_FontSize As SIZE
[142]55Dim _PromptSys_InputStr[255] As StrChar
[1]56Dim _PromptSys_InputLen As Long
57Dim _PromptSys_KeyChar As Byte
58Dim _PromptSys_CurPos As POINTAPI
[126]59Dim _PromptSys_TextLine[100] As _PromptSys_LineInformation
[121]60Dim _PromptSys_NowTextColor As COLORREF
61Dim _PromptSys_NowBackColor As COLORREF
[1]62Dim _PromptSys_SectionOfBufferAccess As CRITICAL_SECTION
63
[142]64Dim _System_OSVersionInfo As OSVERSIONINFO
[1]65
[126]66_PromptSys_InputLen = -1
[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
[127]74_PromptSys_hInitFinish = CreateEvent(0, FALSE, FALSE, 0)
[142]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
[127]81WaitForSingleObject(_PromptSys_hInitFinish, INFINITE)
[1]82
83Sub DrawPromptBuffer(hDC As HDC, StartLine As Long, EndLine As Long)
84 Dim i As Long, i2 As Long, i3 As Long
85
[121]86 Dim hOldFont = SelectObject(hDC, _PromptSys_hFont) As HFONT
[1]87
88 'Scroll
89 Dim rc As RECT
[121]90 GetClientRect(_PromptSys_hWnd, rc)
[125]91 While (_PromptSys_CurPos.y+1) * _PromptSys_FontSize.cy > rc.bottom and _PromptSys_CurPos.y > 0
[126]92 _System_free(_PromptSys_TextLine[0].Text)
93 _System_free(_PromptSys_TextLine[0].CharInfo)
[125]94 For i = 0 To 100 - 1
[126]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
[1]98 Next
[126]99 _PromptSys_TextLine[100].Length = 0
[142]100 _PromptSys_TextLine[100].Text = _System_calloc(SizeOf (StrChar) * 255)
[126]101 _PromptSys_TextLine[100].CharInfo = _System_calloc(SizeOf (_PromptSys_CharacterInformation) * 255)
[90]102 _PromptSys_CurPos.y--
[1]103
104 'Redraw
[125]105 StartLine = -1
[1]106 Wend
107
[126]108 i = 0' : Debug
[125]109 While i * _PromptSys_FontSize.cy < rc.bottom and i <= 100
[1]110 If StartLine=-1 or (StartLine<=i and i<=EndLine) Then
[126]111 Dim currentLineCharInfo = _PromptSys_TextLine[i].CharInfo
112
[125]113 Dim sz As SIZE
[127]114 i3 = _PromptSys_TextLine[i].Length
[142]115 _PromptSys_GetTextExtentPoint32(hDC, _PromptSys_TextLine[i].Text, i3, sz)
[121]116
[1]117 BitBlt(hDC,_
[125]118 sz.cx, i * _PromptSys_FontSize.cy, _
[1]119 rc.right, _PromptSys_FontSize.cy, _
[125]120 _PromptSys_hMemDC, sz.cx, i * _PromptSys_FontSize.cy, SRCCOPY)
[1]121
[126]122 While i2 < i3
123 SetTextColor(hDC, currentLineCharInfo[i2].ForeColor)
124 If currentLineCharInfo[i2].BackColor = -1 Then
[121]125 SetBkMode(hDC, TRANSPARENT)
[1]126 Else
[121]127 SetBkMode(hDC, OPAQUE)
[126]128 SetBkColor(hDC, currentLineCharInfo[i2].BackColor)
[1]129 End If
130
[121]131 Dim tempLen As Long
[126]132 If _System_IsDoubleUnitChar(_PromptSys_TextLine[i].Text[i2], _PromptSys_TextLine[i].Text[i2+1]) Then
[121]133 tempLen = 2
[1]134 Else
[121]135 tempLen = 1
[1]136 End If
[121]137 With _PromptSys_FontSize
[142]138 _PromptSys_TextOut(hDC, currentLineCharInfo[i2].StartPos, i * .cy, VarPtr(_PromptSys_TextLine[i].Text[i2]) As *StrChar, tempLen)
[121]139 End With
[126]140 i2 += tempLen
141 Wend
[1]142 End If
143
[90]144 i++
[1]145 Wend
146
[121]147 SelectObject(hDC, hOldFont)
[1]148End Sub
149
150Sub PRINT_ToPrompt(buf As String)
151 EnterCriticalSection(_PromptSys_SectionOfBufferAccess)
[121]152 With _PromptSys_CurPos
[126]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
[1]158 'Addition
[142]159 Dim i2 = 0 As Long, i3 As Long
[126]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
[132]168 Dim currentLineCharInfo = _PromptSys_TextLine[.y].CharInfo
[126]169 _PromptSys_TextLine[.y].Text[.x] = buf[i2]
170 currentLineCharInfo[.x].ForeColor = _PromptSys_NowTextColor
171 currentLineCharInfo[.x].BackColor = _PromptSys_NowBackColor
[1]172
[126]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
[142]190 _PromptSys_GetTextExtentPoint32(hdc, VarPtr(buf.Chars[i2]) As *StrChar, charLen, sz)
[126]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++
[1]200 End If
[126]201 Next
202 _PromptSys_TextLine[.y].Length = Math.Max(_PromptSys_TextLine[.y].Length, .x)
[1]203
204 'Draw the text buffer added
[126]205 DrawPromptBuffer(hdc, StartLine, .y)
206 SelectObject(hdc, hOldFont)
207 ReleaseDC(_PromptSys_hWnd, hdc)
[121]208 End With
[1]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
[126]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
[1]236
[126]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)
[1]244
[126]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)
[1]251
[126]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
[121]287 End With
[126]288 ImmSetCompositionWindow(himc, CompForm)
[137]289 ImmSetCompositionFont(himc, _PromptSys_LogFont)
[126]290 End If
291 ImmReleaseContext(hwnd, himc)
[1]292
[126]293 CreateCaret(hwnd, 0, 9, 6)
[132]294 With _PromptSys_CurPos
295 SetCaretPos(_PromptSys_TextLine[.y].CharInfo[.x].StartPos, (.y + 1) * _PromptSys_FontSize.cy - 7)
296 End With
[126]297 ShowCaret(hwnd)
298 End If
299End Sub
[1]300
[126]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
[1]331 End If
[126]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
[142]337/*
[126]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
[121]343#ifdef UNICODE 'A版ウィンドウプロシージャ用
[126]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)
[119]348#else
[126]349 TempStr = ZeroString(lstrlen(pTemp) + 1)
350 lstrcpy(StrPtr(TempStr), pTemp)
[119]351#endif
[126]352 memcpy(VarPtr(_PromptSys_InputStr[_PromptSys_InputLen]), TempStr.Chars, SizeOf (Char) * TempStr.Length)
353 _PromptSys_InputLen += TempStr.Length
[1]354
[126]355 GlobalUnlock(hGlobal)
356 CloseClipboard()
[142]357*/
[126]358 Else
359 _PromptSys_InputStr[_PromptSys_InputLen] = wParam As Byte
360 _PromptSys_InputLen++
[1]361
[126]362 TempStr.ReSize(1)
363 TempStr[0] = wParam As Char
364 End If
[1]365
[126]366 SendMessage(hwnd, WM_KILLFOCUS, 0, 0)
367 PRINT_ToPrompt(TempStr)
368 SendMessage(hwnd, WM_SETFOCUS, 0, 0)
369 End If
370End Sub
[1]371
[142]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
[126]392Function _PromptWnd_OnImeCompostion(hwnd As HWND, wp As WPARAM, lp As LPARAM) As LRESULT
[125]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
[142]399 Dim tempStr As String
400 Dim str As *StrChar
[151]401#ifdef __STRING_IS_NOT_UNICODE
[142]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
[125]417 ImmReleaseContext(hwnd, himc)
[142]418 _System_free(str)
[125]419
[142]420 memcpy(VarPtr(_PromptSys_InputStr[_PromptSys_InputLen]), tempStr.Chars, SizeOf (StrChar) * tempStr.Length)
421 _PromptSys_InputLen += tempStr.Length
[125]422
[142]423 SendMessage(hwnd, WM_KILLFOCUS, 0, 0) : Debug
[125]424 PRINT_ToPrompt(tempStr)
425 SendMessage(hwnd, WM_SETFOCUS, 0, 0)
426
[126]427 _PromptWnd_OnImeCompostion = 0
[125]428 Else
[126]429 _PromptWnd_OnImeCompostion = DefWindowProc(hwnd, WM_IME_COMPOSITION, wp, lp)
[125]430 End If
431End Function
432
[1]433Function PromptMain(dwData As Long) As Long
[142]434 GetVersionEx(_System_OSVersionInfo)
435
[1]436 Dim i As Long
437 'Allocate
[126]438 For i = 0 To 100
439 With _PromptSys_TextLine[i]
440 .Length = 0
[142]441 .Text = _System_calloc(SizeOf (StrChar) * 255)
[126]442 .CharInfo = _System_calloc(SizeOf (_PromptSys_CharacterInformation) * 255)
443 End With
[1]444 Next
445
446 'Current Colors initialize
[126]447 _PromptSys_NowTextColor = RGB(255, 255, 255)
448 _PromptSys_NowBackColor = RGB(0, 0, 0)
[1]449
450 'Setup
[125]451 With _PromptSys_ScreenSize
452 .cx = GetSystemMetrics(SM_CXSCREEN)
453 .cy = GetSystemMetrics(SM_CYSCREEN)
454 End With
[1]455
456 'LogFont initialize
[121]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
[1]473
[137]474 _PromptSys_hFont = CreateFontIndirect(_PromptSys_LogFont)
[1]475
476 'Critical Section
477 InitializeCriticalSection(_PromptSys_SectionOfBufferAccess)
478
479 'Regist Prompt Class
480 Dim wcl As WNDCLASSEX
[123]481 ZeroMemory(VarPtr(wcl), Len(wcl))
482 With wcl
483 .cbSize = Len(wcl)
484 .hInstance = GetModuleHandle(0)
[126]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
[123]489 .lpszClassName = "PROMPT"
490 .lpfnWndProc = AddressOf(PromptProc)
491 .hbrBackground = GetStockObject(BLACK_BRUSH)
492 End With
[121]493 Dim atom = RegisterClassEx(wcl)
[1]494
495 'Create Prompt Window
[192]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, _
[125]498 0, 0, wcl.hInstance, 0)
[123]499 ShowWindow(_PromptSys_hWnd, SW_SHOW)
[119]500 UpdateWindow(_PromptSys_hWnd)
[127]501 SetEvent(_PromptSys_hInitFinish)
[123]502 Dim msg As MSG
[1]503 Do
[123]504 Dim iResult = GetMessage(msg, 0, 0, 0)
[126]505 If iResult = 0 Or iResult = -1 Then Exit Do
[1]506 TranslateMessage(msg)
507 DispatchMessage(msg)
508 Loop
509
[121]510 '強制的に終了する
[208]511 End 'ExitProcess(0)
[121]512
[1]513 EnterCriticalSection(_PromptSys_SectionOfBufferAccess)
[126]514
515 For i = 0 to 100
516 _System_free(_PromptSys_TextLine[i].Text)
517 _System_free(_PromptSys_TextLine[i].CharInfo)
[121]518 Next
[17]519
[1]520 LeaveCriticalSection(_PromptSys_SectionOfBufferAccess)
521
522 DeleteCriticalSection(_PromptSys_SectionOfBufferAccess)
523
[208]524 End 'ExitProcess(0)
[1]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
[126]536 If num = 0 Then num = 1
[1]537
[126]538 If num = 1 Or num = 3 Then
[1]539 'Clear the text screen
[123]540 For i = 0 To 100
[126]541 With _PromptSys_TextLine[i]
[192]542 .Text[0] = 0 '_System_FillChar(_PromptSys_TextLine[i].Text, -1 As StrChar, 0)
[126]543 .Length = 0
544 End With
[1]545 Next
[123]546 With _PromptSys_CurPos
547 .x = 0
548 .y = 0
549 End With
[1]550 End If
551
[126]552 If num = 2 Or num = 3 Then
[1]553 'Clear the graphics screen
[126]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)
[1]559 End If
560
561 'Redraw
[126]562 InvalidateRect(_PromptSys_hWnd, ByVal 0, 0)
[1]563End Macro
564
565Macro COLOR(TextColorCode As Long)(BackColorCode As Long)
[126]566 _PromptSys_NowTextColor = GetBasicColor(TextColorCode)
567 If BackColorCode = -1 Then
568 _PromptSys_NowBackColor = -1
[1]569 Else
[126]570 _PromptSys_NowBackColor = GetBasicColor(BackColorCode)
[1]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)
[142]579 Dim i As Long, i2 As Long, i3 As Long
[1]580 Dim buf As String
581
582*InputReStart
583
584 PRINT_ToPrompt(ShowStr)
585
586 'Input by keyboard
[126]587 _PromptSys_InputLen = 0
588 SendMessage(_PromptSys_hWnd, WM_SETFOCUS, 0, 0)
589 While _PromptSys_InputLen <> -1
[1]590 Sleep(10)
591 Wend
[126]592 SendMessage(_PromptSys_hWnd, WM_KILLFOCUS, 0, 0)
[1]593
594 'Set value to variable
[121]595 i = 0
596 i2 = 0
597 buf = ZeroString(lstrlen(_PromptSys_InputStr))
[1]598 While 1
[121]599 i3 = 0
[1]600 While 1
[121]601 If _PromptSys_InputStr[i2] = &h2c Then
602 buf.Chars[i3] = 0
[1]603 Exit While
604 End If
605
[121]606 buf.Chars[i3] = _PromptSys_InputStr[i2]
[1]607
[121]608 If _PromptSys_InputStr[i2] = 0 Then Exit While
[1]609
[90]610 i2++
611 i3++
[1]612 Wend
613
[121]614 _System_Input_SetArgument(_System_InputDataPtr[i], _System_InputDataType[i], buf, i3)
[1]615
[90]616 i++
[126]617 If _System_InputDataPtr[i] = 0 and _PromptSys_InputStr[i2] = &h2c Then 'Asc(",")
[1]618 PRINT_ToPrompt(Ex"入力データの個数が多すぎます\r\n")
619 Goto *InputReStart
[126]620 ElseIf _PromptSys_InputStr[i2] = 0 Then
[1]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
[121]629 i2++
[1]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)
[126]638 If x < 0 Then x = 0
639 If y < 0 Then y = 0
640 If y > 100 Then y = 100
[123]641 With _PromptSys_CurPos
642 .x = x
643 .y = y
644 End With
[1]645
[126]646 Dim i = _PromptSys_TextLine[y].Length
[123]647 If i < x Then
[192]648 _System_FillChar(VarPtr(_PromptSys_TextLine[y].Text[i]), x - i, &h20 As StrChar) 'Asc(" ")
[126]649 Dim i2 As Long
650 For i2 = i To ELM(x)
651 _PromptSys_TextLine[y].CharInfo[i2].BackColor = -1
[1]652 Next
[126]653 _PromptSys_TextLine[y].Length = x
[1]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
[121]668 Dim hPen = CreatePen(PS_SOLID,1,GetBasicColor(ColorCode))
[126]669 Dim hBrush As HBRUSH
[1]670 If bFill Then
[126]671 hBrush = CreateSolidBrush(GetBasicColor(BrushColor))
[1]672 Else
[126]673 hBrush = GetStockObject(NULL_BRUSH)
[1]674 End If
675
[126]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)
[1]681
[126]682 Dim radi2 As Long
[1]683 If Aspect<1 Then
[89]684 radi2=(CDbl(radius)*Aspect) As Long
[1]685 Else
686 radi2=radius
[89]687 radius=(CDbl(radius)/Aspect) As Long
[1]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
[126]694 Dim sw As Long
[90]695 StartPos *=StartPos
696 EndPos *=EndPos
[1]697
698 If StartPos<0 Or EndPos<0 Then
699 sw=1
700 Else
701 sw=0
702 End If
703
[90]704 StartPos = Abs(StartPos)
705 EndPos = Abs(EndPos)
[1]706
707 If StartPos<=78.5 Then
708 i1=78
709 i2=Int(StartPos)
710 ElseIf StartPos<=235.5 Then
[90]711 StartPos -= 78.5
[1]712 i1=78-Int(StartPos)
713 i2=78
714 ElseIf StartPos<=392.5 Then
[90]715 StartPos -= 235.5
[1]716 i1=-78
717 i2=78-Int(StartPos)
718 ElseIf StartPos<=549.5 Then
[90]719 StartPos -= 392.5
[1]720 i1=-78+Int(StartPos)
721 i2=-78
722 ElseIf StartPos<=628 Then
[90]723 StartPos -= 549.5
[1]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
[90]732 EndPos -= 78.5
[1]733 i3=78-Int(EndPos)
734 i4=78
735 ElseIf EndPos<=392.5 Then
[90]736 EndPos -= 235.5
[1]737 i3=-78
738 i4=78-Int(EndPos)
739 ElseIf EndPos<=549.5 Then
[90]740 EndPos -= 392.5
[1]741 i3=-78+Int(EndPos)
742 i4=-78
743 ElseIf EndPos<=628 Then
[90]744 EndPos -= 549.5
[1]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
[126]758 SelectObject(hDC, hOldPenDC)
759 SelectObject(hDC, hOldBrushDC)
760 ReleaseDC(_PromptSys_hWnd, hDC)
761 SelectObject(_PromptSys_hMemDC, hOldPen)
762 SelectObject(_PromptSys_hMemDC, hOldBrush)
[1]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
[126]772 If sx = &H80000000 And sy = &H80000000 Then
773 With _PromptSys_GlobalPos
774 sx = .x
775 sy = .y
776 End With
[1]777 End If
778
779 If bStep Then
[90]780 ex += sx
781 ey += sy
[1]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
[121]798 Dim hDC = GetDC(_PromptSys_hWnd)
799 Dim hPen = CreatePen(PS_SOLID, 1, GetBasicColor(ColorCode))
800 Dim hBrush As HBRUSH
[1]801 If fType=2 Then
[126]802 hBrush = CreateSolidBrush(GetBasicColor(BrushColor))
[1]803 Else
[126]804 hBrush = GetStockObject(NULL_BRUSH)
[1]805 End If
806
[126]807 SelectObject(hDC, hPen)
808 SelectObject(hDC, hBrush)
809 Dim hOldPen = SelectObject(_PromptSys_hMemDC, hPen)
810 Dim hOldBrush = SelectObject(_PromptSys_hMemDC, hBrush)
[1]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)
[126]831 If fType = 2 Then DeleteObject(hBrush)
832 With _PromptSys_GlobalPos
833 .x = ex
834 .y = ey
835 End With
[1]836End Macro
837
838Macro PSET(x As Long, y As Long)(ColorCode As Long)
839 '呼び出し方法は以下のようになります(コンパイラがパラメータの並びを最適化します)
840 'PSet (x,y),ColorCode
841
[126]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
[1]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
[126]856 Dim hBrush = CreateSolidBrush(GetBasicColor(BrushColor))
[1]857
[126]858 Dim hDC = GetDC(_PromptSys_hWnd)
859 Dim hOldBrush = SelectObject(_PromptSys_hMemDC, hBrush)
860 Dim hOldBrushWndDC = SelectObject(hDC, hBrush)
[1]861
[126]862 ExtFloodFill(hDC, x, y, GetBasicColor(LineColor), FLOODFILLBORDER)
863 ExtFloodFill(_PromptSys_hMemDC, x, y, GetBasicColor(LineColor), FLOODFILLBORDER)
[1]864
[126]865 ReleaseDC(_PromptSys_hWnd, hDC)
866 SelectObject(_PromptSys_hMemDC, hOldBrush)
867 SelectObject(hDC, hOldBrushWndDC)
[1]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
[90]898 i++
[126]899 If i >= length Then
[1]900 Exit While
901 End If
902 End If
903 Sleep(1)
904 Wend
905End Function
906
907
[89]908#endif '_INC_PROMPT
Note: See TracBrowser for help on using the repository browser.