:怎么判断一个进程是否有消息循环? 怎么判断一个进程是Console程序

高手进:如何判断一个进程是否有消息循环? 如何判断一个进程是Console程序?
已知:进程PID,进程HANDLE,求:

如何判断一个程序有没有消息循环?  

如何判断一个程序是Console程序?

诚盼高手解答,搜遍CSDN,GOOGLE,BAIDU了。

------解决方案--------------------
判断程序有没消息循环可以用PostThreadMessage
------解决方案--------------------
如上控制台程序有handle吗?http://www.delphibbs.com/delphibbs/modifyl.asp?lid=2046412


网上转的资料

控制台控制句柄


研究控制台输入模式时,一个常常引起关注的元素是控制台的控制句柄。这个句柄是每当某个系统级动作发生、而且可能影响到控制台时,Windows调用的函数。当控制台创建后,Windows简单地调用ExitProcess来安置一个空句柄。要安置你自己的句柄,用以下API调用:
function SetConsoleCtrlHandler(HandlerRoutine: TFNHandlerRoutine; Add: BOOL): BOOL; stdcall;


HandlerRoutine 是指向一个函数的指针。这个函数按stdcall调用,接受一个DWORD参数,返回布尔值。根据Add参数的不同值,把你的自定义函数增加到注册句柄列表中,或者从中移除它。在 Windows NT/2000下,可以把NULL作为一个HandlerRoutine增加或移除。这个特殊的句柄专为忽略 [Ctrl][C]而设计。


一旦系统事件发生,句柄就以被注册的相反顺序调用。以下DWORD参数是你的句柄可能收到的事件列表:

* CTRL_C_EVENT 用户按下[Ctrl][C]。
* CTRL_BREAK_EVENT 用户按下[Ctrl][Break]。
* CTRL_CLOSE_EVENT 用户试图关闭控制台窗口。
* CTRL_LOGOFF_EVENT 用户试图从系统注销。
* CTRL_SHUTDOWN_EVENT 用户试图关闭计算机。


每个句柄都有机会获得系统事件,自行处理或者传给下一个句柄。如果确信控制句柄能成功处理事件,就返回True。这样一来,事件就不会继续传递。否则,应该返回False,好让事件传递给链条中的下一个句柄。


最后三个事件,关闭、注销和关机消息,根据函数结果的不同而有不同的外部表现。如果所有句柄函数返回False,则进程将在最后一个句柄完成后立即退出。但是,如果其中任何一个句柄函数返回True,Windows就会提示用户确认是否关闭进程。用户可以选择立即结束进程,也可以选择不关闭进程。而且,如果函数执行超时,Windows也会让用户自行选择关闭进程、取消关闭或者继续等待。


如果有几个应用程序关联到同一个控制台,那么,它们都会收到传递给控制台窗口的信号。它们中的任何一个都有机会进行消息处理。此外,也可以把多个控制台程序作为一个控制台进程租对待。用 CreateProcess创建新控制台窗口时情形就是这样。如果没有指定CREATE_NEW_PROCESS_GROUP标志,则控制台进程的所有子进程都属于同一个组。这样,控制台程序就能用下面这个API把信号发送给一个指定的进程组。
function GenerateConsoleCtrlEvent(dwCtrlEvent: DWORD; dwProcessGroupId: DWORD): BOOL; stdcall;


这个函数把指定的信号传递给与调用进程相关联的控制台窗口。所有其它同组的程序都会收到这个信号。这可以用来实现一个父进程同时控制多个子进程的行为。
-----------------------------------------http://www.delphibbs.com/delphibbs/dispq.asp?lid=2308342

不知道这对lz是否有帮助
------解决方案--------------------
如何判断一个进程是Console程序?
====================================
看看对你有没有用
This article will discuss a very small utility to check if an EXE file is a console or GUI application.

There are no direct API calls, which gives us this information about an application. Whenever an application is created, the EXE file stores a whole lot of information in certain format. Therefore to dig out the information it is important to understand the format of executable files. All the data structure types used for various file headers are defined in WINNT.H file supplied with Win NT OS.

Starting from Win NT 3.1, a new file format was introduced by OS called Portable Executable (PE). The PE file format draws primarily from the COFF (Common Object File Format) specification that is common to UNIX® operating systems. The entire format consists of an MS-DOS MZ header, followed by a Real-Mode Stub Program, the PE file signature, the PE file header, the PE optional header, all of the section headers, and finally, all of the section bodies.

The MS-DOS header occupies the first 64 bytes of the PE file. The contents of this header are represented by IMAGE_DOS_HEADER data structure. The e_magic field of this structure is used to identify an MS-DOS compatible file type. All MS-DOS compatible executable files set this value to 0x54AD, which represents the ASCII characters MZ. MS-DOS headers are sometimes referred to as MZ headers for this reason. The final field, e_lfanew, is a 4-byte offset into the file where the PE file header is located.

The Real-Mode Stub Program is an actual program run by MS-DOS when the executable is loaded. For an actual MS-DOS executable image file, the application begins executing here.