挑战高手,高难度问题:关于“控制台”(用 AllocConsole打开的)的几个问题!!!(300分)

测试后两个问题都出现了。<br>1.console处于选定状态下无法writemessage,切换到console窗口后取消选定状态,刚才的writemessage起作用<br>我想是因为console窗口处于选定状态时不接受其他消息<br>2.关闭console窗口后整个程序关闭<br>console与主窗口处于一个进程,它接受关闭消息执行exitprocess将整个进程关闭。<br><br>可能的解决方法:<br>1.将console的system menu、max、min什么的统统拿掉,同时设置为不允许鼠标输入,使产生问题的根源不至于出现[:D]<br>2.用createprocess将console建立于另一个进程,应该可以解决第二个问题<br>3.可能可以捕捉console的input事件,解决第一个问题,可以研究研究SDK,我没有仔细看<br><br>另外,那个窗口消息处理函数好像没有起作用,不知道怎么回事
 
我觉得问题可能出现在 MyConRoutine 函数上,你返回值为真但并没有对相应的信号<br>进行处理。你看看他的说明吧:<br>If the function handles the control signal, it should return TRUE. If it <br>returns FALSE, the next handler function in the list of handlers for this <br>process is used. <br>Each console process has its own list of HandlerRoutine functions. Initially, <br>this list contains only a default handler function that calls ExitProcess. <br>A console process adds or removes additional handler functions by calling the <br>SetConsoleCtrlHandler function, which does not affect the list of handler <br>functions for other processes. When a console process receives any of the <br>control signals, its handler functions are called on a last-registered, <br>first-called basis until one of the handlers returns TRUE. If none of the <br>handlers returns TRUE, the default handler is called. <br>
 
To tseug:<br>&nbsp; &nbsp; 如果真是问题出现在 MyConRoutine 函数上,那该怎么解决呢?那段话我早就仔细看过,<br>可是试了半天,还是没用,不知是何原因。[:(]<br>
 
看来此题无人能答了![:(]
 
不好意思, 这些天放假, 等7号以后我再看看吧
 
快来帮帮我呀![8D]
 
function MyConRoutine(dwCtrlType:DWORD):BOOL; // &nbsp;control signal type<br>begin<br>&nbsp; Case dwCtrlType of<br>&nbsp; 2:<br>&nbsp; &nbsp;Form1.SetConsoleWin(SW_HIDE);<br>&nbsp; end;<br>&nbsp; Result:=BOOL(True);<br>end;<br>
 
To guzlc:<br>&nbsp; &nbsp; 还是不行呀!
 
怎么没人啦???[:(]
 
人都到哪去了?
 
我的环境是win2000server + IE6没问题;<br>思考中。<br>
 
都快一年了,还是没办法解决此问题,哎……[:(]
 
好惨的问题
 
我没仔细看你的代码,所以后一个问题为什么会这样我就不知道,至于前一个问题吗,<br>你只要用API在那窗口上模拟点一下右键就行了,我以前这样做过,没问题。
 
呵呵,我也帮不了你,因为我们的问题一模一样。
 
哈哈,经过近一年的折磨,第一个问题终于基本解决了!(其实应该说是绕过去了@_@)<br>只要把 WriteBtnClick 改成如下代码即可解决第一个问题!<br>procedure TForm1.WriteBtnClick(Sender: TObject);<br>var<br>&nbsp; FHandle:Hwnd;<br><br>&nbsp; function GetConsoleWHND:HWND;<br>&nbsp; begin<br>&nbsp; &nbsp; if Win32Platform=VER_PLATFORM_WIN32_NT then &nbsp; //若操作系统为 NT,则找'ConsoleWindowClass'<br>&nbsp; &nbsp; &nbsp; &nbsp;Result:=FindWindow('ConsoleWindowClass',nil)<br>&nbsp; &nbsp; else &nbsp; &nbsp; //操作系统为 Windows,则找'tty'<br>&nbsp; &nbsp; &nbsp; &nbsp;Result:=FindWindow('tty',nil);<br>&nbsp; end;<br><br>begin<br>&nbsp; FHandle:=GetConsoleWHND; &nbsp; &nbsp; &nbsp;//取得控制台窗口句柄<br>&nbsp; SetForegroundWindow(FHandle); //强制控制台窗口为当前激活窗口,否则下面的SendMessage在这种状态下会无效<br>&nbsp; ShowWindow(FHandle,SW_RESTORE); //如果控制台窗口在最小化状态,则SendMessage也无效<br>&nbsp; SendMessage(FHandle,WM_RBUTTONDOWN,0,0); &nbsp;//每当要输出信息之前,先模拟鼠标右键<br>&nbsp; SendMessage(FHandle,WM_RBUTTONUP,0,0);<br>&nbsp; writeln('test message'); &nbsp;//OK,此问题已成功绕过<br>end;<br><br>&nbsp; &nbsp; 非常感谢各位的帮助,这个困扰我已久的问题终于解决了,我真高兴!谢谢大家!<br>&nbsp; &nbsp; 但是我的第二个问题依然如故,有人能够解决吗?
 
顶部