读书人

关于WaitForInputIdle的疑义

发布时间: 2012-11-20 09:55:43 作者: rapoo

关于WaitForInputIdle的疑问.
在msdn上搜到解释说
Waits until the specified process has finished processing its initial input and is waiting for user input with no input pending, or until the time-out interval has elapsed.

这函数好像说可以等待用户没有输入才返回,
但是问题来了,那个等待的进程一开始就没人输入的,不是立即返回了??
那这个可以等待用户没有输入才返回
是什么意思呢.

[解决办法]
自己写个代码试下不就知道了么?
[解决办法]
不是还有个time-out 吗
[解决办法]
has finished processing its initial input
[解决办法]
http://www.google.com/codesearch
WaitForInputIdle
The WaitForInputIdle function waits until the given process is waiting for user input with no input pending, or until the time-out interval has elapsed.

The WaitForInputIdle function only works with GUI applications. If a console application calls the function, it returns immediately, with no wait.

DWORD WaitForInputIdle(
HANDLE hProcess, // handle to process
DWORD dwMilliseconds // time-out interval in milliseconds
);

Parameters
hProcess
Handle to the process.
dwMilliseconds
Specifies the time-out interval, in milliseconds. If dwMilliseconds is INFINITE, the function does not return until the process is idle.
Return Values
The following table shows the possible return values:

Value Meaning
0 The wait was satisfied successfully.
WAIT_TIMEOUT The wait was terminated because the time-out interval elapsed.
0xFFFFFFFF An error occurred. To get extended error information, use the GetLastError function.


Remarks
The WaitForInputIdle function enables a thread to suspend its execution until a specified process has finished its initialization and is waiting for user input with no input pending. This can be useful for synchronizing a parent process and a newly created child process. When a parent process creates a child process, the CreateProcess function returns without waiting for the child process to finish its initialization. Before trying to communicate with the child process, the parent process can use WaitForInputIdle to determine when the child's initialization has been completed. For example, the parent process should use WaitForInputIdle before trying to find a window associated with the child process.

The WaitForInputIdle function can be used at any time, not just during application startup.

QuickInfo
Windows NT: Requires version 3.1 or later.
Windows: Requires Windows 95 or later.
Windows CE: Unsupported.
Header: Declared in winuser.h.
Import Library: Use user32.lib.

See Also
Processes and Threads Overview, Process and Thread Functions, CreateProcess


读书人网 >C语言

热点推荐