【发布时间】:2014-02-14 10:12:59
【问题描述】:
我正在尝试将 Chrome 窗口设置为前台并激活它以获得键盘的焦点。我的代码适用于记事本或 IE,但不适用于 Google Chrome。
//Getting the HWND of Chrome
HWND chromeWindow = FindWindow("Chrome_WidgetWin_1", NULL);
DWORD dwCurrentThread = GetCurrentThreadId();
DWORD dwFGThread = GetWindowThreadProcessId(GetForegroundWindow(), NULL);
AttachThreadInput(dwCurrentThread, dwFGThread, TRUE);
//Actions
AllowSetForegroundWindow(ASFW_ANY);
bool fore =SetForegroundWindow(chromeWindow);
if(fore==false){cout << "fore failed"<<endl;}
bool capture = SetCapture(chromeWindow);
if(capture==false){cout << "capture failed" <<endl;}
bool focus = SetFocus(chromeWindow);
if(focus==false){cout << "focus failed"<<endl;}
bool active = SetActiveWindow(chromeWindow);
if(active==false){cout << "active failed"<<endl;}
//Finishing
AttachThreadInput(dwCurrentThread, dwFGThread, FALSE);
代码将 Google Chrome 窗口设置为前台,但没有激活它或将键盘聚焦在它上面。我不知道出了什么问题。显示的结果是:
capture failed.
focus failed.
active failed.
我能做什么?
【问题讨论】:
标签: c# c++ google-chrome hwnd