Warning: file_get_contents() [function.file-get-contents]: SSL: 远程主机强迫关闭了一个现有的连接。 in D:\wwwroot\huidong\wwwroot\function.inc.php on line 884

Warning: file_get_contents(https://whois.pconline.com.cn/jsLabel.jsp?ip=127.0.0.1) [function.file-get-contents]: failed to open stream: HTTP request failed! in D:\wwwroot\huidong\wwwroot\function.inc.php on line 884
GetFocus 和 SetFocus 获取和设置焦点的问题(跨线程调用无效) - huidong

huidong

首页 | 会员登录 | 关于争取 2022 寒假做出汇东网 Ver3.0.0 !
搜索文章


GetFocus 和 SetFocus 跨线程调用是无效的。

解决方法:

https://blog.csdn.net/ribut9225/article/details/21620139

    bool SysControlBase::isFocused()
    {
        DWORD SelfThreadId = GetCurrentThreadId();                        // 获取自身线程 ID
        DWORD ForeThreadId = GetWindowThreadProcessId(m_hParent, NULL);    // 根据窗口句柄获取线程 ID
        AttachThreadInput(ForeThreadId, SelfThreadId, true);            // 附加到线程
        HWND hWnd = GetFocus();                                            // 获取具有输入焦点的窗口句柄
        AttachThreadInput(ForeThreadId, SelfThreadId, false);            // 取消附加到线程
        return hWnd == GetHandle();
    }

这是判断是否获取到焦点的。设置焦点就不用那么麻烦了,可以这样:

    void SysControlBase::SetFocus(bool focused)
    {
        SendMessage(GetHandle(), focused ? WM_SETFOCUS : WM_KILLFOCUS, 0, 0);
    }

以上所给代码都是在 SysControlBase 类中的。所以要替换 GetHandle() 函数为自己的控件句柄,替换 m_hParent 为控件的父窗口句柄。



返回首页


Copyright (C) 2018-2024 huidong