控制台服务程序如何禁止在界面上进行编辑操作

zhcosin 2014-08-22 04:16:23
现维护着一个后台服务程序,界面是控制台的,目前有一个现象,就是如果用鼠标到界面上左上角点出下拉菜单,选编辑后到缓冲区内选择文本后进程就处于阻塞状态,网络交互完全停止,按ESC键后恢复正常,如果按住滚动条不放也会有一样的效果. 所以想问一下,如何禁止windows控制台界面上的编辑操作,让它变成不可选择标记的.
...全文
540 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
zhcosin 2014-08-22
  • 打赏
  • 举报
回复
引用 5 楼 zhao4zhong1 的回复:
ReadConsoleInput The ReadConsoleInput function reads data from a console input buffer and removes it from the buffer. BOOL ReadConsoleInput( HANDLE hConsoleInput, // handle to a console input buffer PINPUT_RECORD lpBuffer, // address of the buffer for read data DWORD nLength, // number of records to read LPDWORD lpNumberOfEventsRead // address of number of records read ); Parameters hConsoleInput Handle to the input buffer. The handle must have GENERIC_READ access. lpBuffer Pointer to an INPUT_RECORD buffer that receives the input buffer data. nLength Specifies the size, in input records, of the buffer pointed to by the lpBuffer parameter. lpNumberOfEventsRead Pointer to a 32-bit variable that receives the number of input records read. Return Values If the function succeeds, the return value is nonzero. If the function fails, the return value is zero. To get extended error information, call GetLastError. Remarks If the number of records requested in the nLength parameter exceeds the number of records available in the buffer, the number available is read. The function does not return until at least one input record has been read. A process can specify a console input buffer handle in one of the wait functions to determine when there is unread console input. When the input buffer is not empty, the state of a console input buffer handle is signaled. To determine the number of unread input records in a console's input buffer, use the GetNumberOfConsoleInputEvents function. To read input records from a console input buffer without affecting the number of unread records, use the PeekConsoleInput function. To discard all unread records in a console's input buffer, use the FlushConsoleInputBuffer function. Windows NT: This function uses either Unicode characters or 8-bit characters from the console's current code page. The console's code page defaults initially to the system's OEM code page. To change the console's code page, use the SetConsoleCP or SetConsoleOutputCP functions, or use the chcp or mode con cp select= commands. QuickInfo Windows NT: Requires version 3.1 or later. Windows: Requires Windows 95 or later. Windows CE: Unsupported. Header: Declared in wincon.h. Import Library: Use kernel32.lib. Unicode: Implemented as Unicode and ANSI versions on Windows NT. See Also Consoles and Character-Mode Support Overview, Console Functions, FlushConsoleInputBuffer, GetNumberOfConsoleInputEvents, INPUT_RECORD, PeekConsoleInput, ReadConsole, ReadFile, SetConsoleCP, SetConsoleOutputCP, WriteConsoleInput INPUT_RECORD The INPUT_RECORD structure is used to report input events in the console input buffer. These records can be read from the input buffer by using the ReadConsoleInput or PeekConsoleInput function, or written to the input buffer by using the WriteConsoleInput function. typedef struct _INPUT_RECORD { // ir WORD EventType; union { KEY_EVENT_RECORD KeyEvent; MOUSE_EVENT_RECORD MouseEvent; WINDOW_BUFFER_SIZE_RECORD WindowBufferSizeEvent; MENU_EVENT_RECORD MenuEvent; FOCUS_EVENT_RECORD FocusEvent; } Event; } INPUT_RECORD; Members EventType Handle to the type of input event and the event record stored in the Event member. This member can have one of the following values: Value Meaning KEY_EVENT The Event member contains a KEY_EVENT_RECORD structure with information about a keyboard event. MOUSE_EVENT The Event member contains a MOUSE_EVENT_RECORD structure with information about a mouse movement or button press event. WINDOW_BUFFER_SIZE_EVENT The Event member contains a WINDOW_BUFFER_SIZE_RECORD structure with information about the new size of the screen buffer. MENU_EVENT The Event member contains a MENU_EVENT_RECORD structure. These events are used internally and should be ignored. FOCUS_EVENT The Event member contains a FOCUS_EVENT_RECORD structure. These events are used internally and should be ignored. Event Contains a KEY_EVENT_RECORD, MOUSE_EVENT_RECORD, WINDOW_BUFFER_SIZE_RECORD, MENU_EVENT_RECORD, or FOCUS_EVENT_RECORD structure, depending on the event type specified by the EventType member. QuickInfo Windows NT: Requires version 3.1 or later. Windows: Requires Windows 95 or later. Windows CE: Unsupported. Header: Declared in wincon.h. See Also Consoles and Character-Mode Support Overview, Console Structures, FOCUS_EVENT_RECORD, KEY_EVENT_RECORD, MENU_EVENT_RECORD, MOUSE_EVENT_RECORD, PeekConsoleInput, ReadConsoleInput, WriteConsoleInput
谢谢。
赵4老师 2014-08-22
  • 打赏
  • 举报
回复
ReadConsoleInput The ReadConsoleInput function reads data from a console input buffer and removes it from the buffer. BOOL ReadConsoleInput( HANDLE hConsoleInput, // handle to a console input buffer PINPUT_RECORD lpBuffer, // address of the buffer for read data DWORD nLength, // number of records to read LPDWORD lpNumberOfEventsRead // address of number of records read ); Parameters hConsoleInput Handle to the input buffer. The handle must have GENERIC_READ access. lpBuffer Pointer to an INPUT_RECORD buffer that receives the input buffer data. nLength Specifies the size, in input records, of the buffer pointed to by the lpBuffer parameter. lpNumberOfEventsRead Pointer to a 32-bit variable that receives the number of input records read. Return Values If the function succeeds, the return value is nonzero. If the function fails, the return value is zero. To get extended error information, call GetLastError. Remarks If the number of records requested in the nLength parameter exceeds the number of records available in the buffer, the number available is read. The function does not return until at least one input record has been read. A process can specify a console input buffer handle in one of the wait functions to determine when there is unread console input. When the input buffer is not empty, the state of a console input buffer handle is signaled. To determine the number of unread input records in a console's input buffer, use the GetNumberOfConsoleInputEvents function. To read input records from a console input buffer without affecting the number of unread records, use the PeekConsoleInput function. To discard all unread records in a console's input buffer, use the FlushConsoleInputBuffer function. Windows NT: This function uses either Unicode characters or 8-bit characters from the console's current code page. The console's code page defaults initially to the system's OEM code page. To change the console's code page, use the SetConsoleCP or SetConsoleOutputCP functions, or use the chcp or mode con cp select= commands. QuickInfo Windows NT: Requires version 3.1 or later. Windows: Requires Windows 95 or later. Windows CE: Unsupported. Header: Declared in wincon.h. Import Library: Use kernel32.lib. Unicode: Implemented as Unicode and ANSI versions on Windows NT. See Also Consoles and Character-Mode Support Overview, Console Functions, FlushConsoleInputBuffer, GetNumberOfConsoleInputEvents, INPUT_RECORD, PeekConsoleInput, ReadConsole, ReadFile, SetConsoleCP, SetConsoleOutputCP, WriteConsoleInput INPUT_RECORD The INPUT_RECORD structure is used to report input events in the console input buffer. These records can be read from the input buffer by using the ReadConsoleInput or PeekConsoleInput function, or written to the input buffer by using the WriteConsoleInput function. typedef struct _INPUT_RECORD { // ir WORD EventType; union { KEY_EVENT_RECORD KeyEvent; MOUSE_EVENT_RECORD MouseEvent; WINDOW_BUFFER_SIZE_RECORD WindowBufferSizeEvent; MENU_EVENT_RECORD MenuEvent; FOCUS_EVENT_RECORD FocusEvent; } Event; } INPUT_RECORD; Members EventType Handle to the type of input event and the event record stored in the Event member. This member can have one of the following values: Value Meaning KEY_EVENT The Event member contains a KEY_EVENT_RECORD structure with information about a keyboard event. MOUSE_EVENT The Event member contains a MOUSE_EVENT_RECORD structure with information about a mouse movement or button press event. WINDOW_BUFFER_SIZE_EVENT The Event member contains a WINDOW_BUFFER_SIZE_RECORD structure with information about the new size of the screen buffer. MENU_EVENT The Event member contains a MENU_EVENT_RECORD structure. These events are used internally and should be ignored. FOCUS_EVENT The Event member contains a FOCUS_EVENT_RECORD structure. These events are used internally and should be ignored. Event Contains a KEY_EVENT_RECORD, MOUSE_EVENT_RECORD, WINDOW_BUFFER_SIZE_RECORD, MENU_EVENT_RECORD, or FOCUS_EVENT_RECORD structure, depending on the event type specified by the EventType member. QuickInfo Windows NT: Requires version 3.1 or later. Windows: Requires Windows 95 or later. Windows CE: Unsupported. Header: Declared in wincon.h. See Also Consoles and Character-Mode Support Overview, Console Structures, FOCUS_EVENT_RECORD, KEY_EVENT_RECORD, MENU_EVENT_RECORD, MOUSE_EVENT_RECORD, PeekConsoleInput, ReadConsoleInput, WriteConsoleInput
longdenghua 2014-08-22
  • 打赏
  • 举报
回复
不知你控制台打印的信息有没有用,没用的话修改你的程序把控制台隐藏掉,有的话只有尽可能的不去做这个操作了。
passion_wu128 2014-08-22
  • 打赏
  • 举报
回复
“选择文本后进程就处于阻塞状态”,这个是你程序在等待吧。另一个个人觉得不用处理,谁会一直按住滚动条不放???
zhcosin 2014-08-22
  • 打赏
  • 举报
回复
这个不行哦,目前这个问题只是内部发现有这个问题,现场还没有出现,而且这个问题也不是特别紧要,用户目前不知道这个问题,知道了也肯定不会认可这种解决方式的。
赵4老师 2014-08-22
  • 打赏
  • 举报
回复
最简单的办法是使用nircmd工具将控制台窗口隐藏。 使用时再显示。 http://www.nirsoft.net

64,636

社区成员

发帖
与我相关
我的任务
社区描述
C++ 语言相关问题讨论,技术干货分享,前沿动态等
c++ 技术论坛(原bbs)
社区管理员
  • C++ 语言社区
  • encoderlee
  • paschen
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
  1. 请不要发布与C++技术无关的贴子
  2. 请不要发布与技术无关的招聘、广告的帖子
  3. 请尽可能的描述清楚你的问题,如果涉及到代码请尽可能的格式化一下

试试用AI创作助手写篇文章吧