source: Include/basic/prompt.sbp@ 258

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

Prompt.sbp内を名前空間に入れた。EnvironmentのMachineName, UserName, GetFolderPathを実装。

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