为了账号安全,请及时绑定邮箱和手机立即绑定

帮忙看看,请问WaitForInputIdle函数怎么用?

帮忙看看,请问WaitForInputIdle函数怎么用?

慕村225694 2021-08-05 18:07:20

WaitForInputIdle函数怎么用?

查看完整描述

2 回答

?
陪伴而非守候

TA贡献1711条经验 获得超9个赞

函数作用:等待新进程完成它的初始化并等待用户输入。
  hProcess
  [in] 进程的句柄。如果这个进程是一个控制台应用程序或者没有消息队列,函数立刻返回。
  dwMilliseconds
  [in] 超时间隔,单位为毫秒。如果 dwMilliseconds 设为 INFINITE,函数会一直等到进程空闲即初始化完成后才返回。
  该函数可以使一个线程挂起,直到规定线程初始化完成,等待用户输入。这对于父进程和子进程之间的同步是极其有用的,因为CreateProcess函数不会等待新进程完成它的初始化工作。在试图与子线程通讯前,父线程可以使用WaitForInputIdle来判断子线程是否已经初始化完成。举例来说,在试图与新进程关联的窗口之前,进程应该先调用WaitForInputIdle。

查看完整回答
反对 回复 2021-08-09
?
摇曳的蔷薇

TA贡献1736条经验 获得超9个赞

WaitForInputIdle

The WaitForInputIdle function waits until the specified process is waiting for user input with no input pending, or until the time-out interval has elapsed.

DWORD WaitForInputIdle(
HANDLE hProcess,
DWORD dwMilliseconds
);

Parameters
hProcess
[in] Handle to the process. If this process is a console application or does not have a message queue, WaitForInputIdle returns immediately.
dwMilliseconds
[in] 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 for this function.

Return code/value Description

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

Remarks
The WaitForInputIdle function enables a thread to suspend its execution until the 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.

Requirements
Client Requires Windows XP, Windows 2000 Professional, Windows NT Workstation, Windows Me, Windows 98, or Windows 95.
Server Requires Windows Server 2003, Windows 2000 Server, or Windows NT Server.
Header Declared in Winuser.h; include Windows.h.

Library Link to User32.lib.

DLL Requires User32.dll.



查看完整回答
反对 回复 2021-08-09
  • 2 回答
  • 0 关注
  • 41 浏览
我要回答

添加回答

回复

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信