C++ 如何确认之前是否通过AttachThreadInput附加了线程?

C++ 如何确认之前是否通过AttachThreadInput附加了线程?,c++,winapi,C++,Winapi,tl;dr 使用AttachThreadInput函数时,我可以选择附加或分离另一个线程 有没有办法知道附件是否已经存在 长版本 我有甲级: ClassA::attach(::HWND window) { ::AttachThreadInput(::GetCurrentThreadId(), ::GetWindowThreadProcessId(window, NULL), TRUE); } ClassA::detach(::HWND window) { ::AttachT

tl;dr

使用
AttachThreadInput
函数时,我可以选择附加或分离另一个线程

有没有办法知道附件是否已经存在

长版本

我有甲级:

ClassA::attach(::HWND window)
{ 
    ::AttachThreadInput(::GetCurrentThreadId(), ::GetWindowThreadProcessId(window, NULL), TRUE);
}

ClassA::detach(::HWND window)
{ 
    ::AttachThreadInput(::GetCurrentThreadId(), ::GetWindowThreadProcessId(window, NULL), FALSE);
}

ClassA::doSomething()
{
    // things happen
}
…和B类:

ClassB::doSomethingElse(::HWND window)
{
    ::AttachThreadInput(::GetCurrentThreadId(), ::GetWindowThreadProcessId(window, NULL), TRUE);

    // do something else

    ::AttachThreadInput(::GetCurrentThreadId(), ::GetWindowThreadProcessId(window, NULL), FALSE);
}
我想修改B类,使其能够识别现有的附件,并且仅当附件不存在时才附加/分离

这将允许我这样做:

ClassA a;
ClassB b;

a.attach(window);
b.doSomethingElse(window);
a.doSomething();
a.detach(window);

没有可查询现有附件的API。您必须自己跟踪附件。

没有可查询现有附件的API。您必须自己跟踪附件。

没有可查询现有附件的API。您必须自己跟踪附件。

没有可查询现有附件的API。您必须自己跟踪附件