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