原来写好一个控制台的程序也这么费劲 ( 积分: 100 )

  • 主题发起人 主题发起人 teclick
  • 开始时间 开始时间
T

teclick

Unregistered / Unconfirmed
GUEST, unregistred user!
program Project1;<br><br>{$APPTYPE CONSOLE}<br><br>uses<br> &nbsp;SysUtils, Windows;<br><br><br>procedure MyErrorExit(S: string);<br>begin<br> &nbsp;WriteLn(S);<br>end;<br><br>var<br> &nbsp;hStdin: THANDLE;<br> &nbsp;cNumRead, fdwMode, fdwSaveOldMode, i: DWORD;<br> &nbsp;irInBuf: array[0..128] of _INPUT_RECORD;<br>begin<br> &nbsp; &nbsp;// Get the standard input handle.<br> &nbsp; &nbsp;hStdin := GetStdHandle(STD_INPUT_HANDLE);<br> &nbsp; &nbsp;if hStdin = INVALID_HANDLE_VALUE then<br> &nbsp; &nbsp; &nbsp; &nbsp;MyErrorExit('GetStdHandle');<br><br> &nbsp; &nbsp;// Save the current input mode, to be restored on exit. <br><br> &nbsp; &nbsp;if not GetConsoleMode(hStdin, fdwSaveOldMode) then<br> &nbsp; &nbsp; &nbsp; &nbsp;MyErrorExit('GetConsoleMode');<br> <br> &nbsp; &nbsp;// Enable the window and mouse input events.<br><br> &nbsp; &nbsp;fdwMode := ENABLE_WINDOW_INPUT or ENABLE_MOUSE_INPUT;<br> &nbsp; &nbsp;if not SetConsoleMode(hStdin, fdwMode) then<br> &nbsp; &nbsp; &nbsp; &nbsp;MyErrorExit('SetConsoleMode');<br><br> &nbsp; &nbsp;// Loop to read and handle the input events.<br><br> &nbsp; &nbsp;while True do<br> &nbsp; &nbsp;begin<br><br> &nbsp; &nbsp; &nbsp; &nbsp;// Wait for the events.<br><br> &nbsp; &nbsp; &nbsp; &nbsp;if not ReadConsoleInput(<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;hStdin, &nbsp; &nbsp; &nbsp;// input buffer handle<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;irInBuf[0], &nbsp; &nbsp; // buffer to read into<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;128, &nbsp; &nbsp; &nbsp; &nbsp; // size of read buffer<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;cNumRead) then // number of records read<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;MyErrorExit('ReadConsoleInput');<br><br> &nbsp; &nbsp; &nbsp; &nbsp;// Dispatch the events to the appropriate handler.<br><br> &nbsp; &nbsp; &nbsp; &nbsp;for i := 0 to cNumRead-1 do<br> &nbsp; &nbsp; &nbsp; &nbsp;begin<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;case irInBuf.EventType of<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;KEY_EVENT: begin// keyboard input<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;//KeyEventProc(irInBuf.Event.KeyEvent);<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;//break;<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;WriteLn('key press');<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;end;<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;{<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;MOUSE_EVENT: begin// mouse input<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;//MouseEventProc(irInBuf.Event.MouseEvent);<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;//break;<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;end;<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;}<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;WINDOW_BUFFER_SIZE_EVENT: begin// scrn buf. resizing<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;//ResizeEventProc(<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;// &nbsp;irInBuf.Event.WindowBufferSizeEvent);<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;//break;<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;end;<br><br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;FOCUS_EVENT: &nbsp;begin// disregard focus events<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;end;<br><br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;MENU_EVENT: &nbsp; begin// disregard menu events<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;//break;<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;end;<br><br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;else MyErrorExit('unknown event type');<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;end;<br> &nbsp; &nbsp; &nbsp; &nbsp;end;<br> &nbsp; &nbsp;end;<br>end.
 
program Project1;<br><br>{$APPTYPE CONSOLE}<br><br>uses<br> &nbsp;SysUtils, Windows;<br><br><br>procedure MyErrorExit(S: string);<br>begin<br> &nbsp;WriteLn(S);<br>end;<br><br>var<br> &nbsp;hStdin: THANDLE;<br> &nbsp;cNumRead, fdwMode, fdwSaveOldMode, i: DWORD;<br> &nbsp;irInBuf: array[0..128] of _INPUT_RECORD;<br>begin<br> &nbsp; &nbsp;// Get the standard input handle.<br> &nbsp; &nbsp;hStdin := GetStdHandle(STD_INPUT_HANDLE);<br> &nbsp; &nbsp;if hStdin = INVALID_HANDLE_VALUE then<br> &nbsp; &nbsp; &nbsp; &nbsp;MyErrorExit('GetStdHandle');<br><br> &nbsp; &nbsp;// Save the current input mode, to be restored on exit. <br><br> &nbsp; &nbsp;if not GetConsoleMode(hStdin, fdwSaveOldMode) then<br> &nbsp; &nbsp; &nbsp; &nbsp;MyErrorExit('GetConsoleMode');<br> <br> &nbsp; &nbsp;// Enable the window and mouse input events.<br><br> &nbsp; &nbsp;fdwMode := ENABLE_WINDOW_INPUT or ENABLE_MOUSE_INPUT;<br> &nbsp; &nbsp;if not SetConsoleMode(hStdin, fdwMode) then<br> &nbsp; &nbsp; &nbsp; &nbsp;MyErrorExit('SetConsoleMode');<br><br> &nbsp; &nbsp;// Loop to read and handle the input events.<br><br> &nbsp; &nbsp;while True do<br> &nbsp; &nbsp;begin<br><br> &nbsp; &nbsp; &nbsp; &nbsp;// Wait for the events.<br><br> &nbsp; &nbsp; &nbsp; &nbsp;if not ReadConsoleInput(<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;hStdin, &nbsp; &nbsp; &nbsp;// input buffer handle<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;irInBuf[0], &nbsp; &nbsp; // buffer to read into<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;128, &nbsp; &nbsp; &nbsp; &nbsp; // size of read buffer<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;cNumRead) then // number of records read<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;MyErrorExit('ReadConsoleInput');<br><br> &nbsp; &nbsp; &nbsp; &nbsp;// Dispatch the events to the appropriate handler.<br><br> &nbsp; &nbsp; &nbsp; &nbsp;for i := 0 to cNumRead-1 do<br> &nbsp; &nbsp; &nbsp; &nbsp;begin<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;case irInBuf.EventType of<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;KEY_EVENT: begin// keyboard input<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;//KeyEventProc(irInBuf.Event.KeyEvent);<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;//break;<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;WriteLn('key press');<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;end;<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;{<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;MOUSE_EVENT: begin// mouse input<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;//MouseEventProc(irInBuf.Event.MouseEvent);<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;//break;<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;end;<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;}<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;WINDOW_BUFFER_SIZE_EVENT: begin// scrn buf. resizing<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;//ResizeEventProc(<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;// &nbsp;irInBuf.Event.WindowBufferSizeEvent);<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;//break;<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;end;<br><br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;FOCUS_EVENT: &nbsp;begin// disregard focus events<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;end;<br><br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;MENU_EVENT: &nbsp; begin// disregard menu events<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;//break;<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;end;<br><br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;else MyErrorExit('unknown event type');<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;end;<br> &nbsp; &nbsp; &nbsp; &nbsp;end;<br> &nbsp; &nbsp;end;<br>end.
 
楼主要实现什么
 
对一个控制台程序的测试,没有目的
 
接受答案了.
 
后退
顶部