2014-02-14 2 views
1

크롬 창을 포 그라운드로 설정하고 활성화하여 키보드 포커스를 얻으려고합니다. 내 코드는 메모장이나 IE에서 작동하지만 Chrome에서는 작동하지 않습니다.크롬 창을 활성화 설정 중 (C++)

//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 크롬 창을 설정하지만 나에 키보드 초점을 활성화하지 않습니다. 나는 무엇이 잘못되었는지 모른다. 표시되는 결과는 다음과 같습니다.

capture failed. 
focus failed. 
active failed. 

어떻게해야합니까?

답변

2

글쎄, 나는 대답 일을 전에 발견했다.

"Chrome_WidgetWin_1"과 같은 클래스 이름을 가진 두 개의 Chrome 창이 있으며 유용한 창이 두 번째 인 경우 첫 번째 창을 활성화하려고했습니다. 그래서 두 번째 창을 검색하고 나중에 해당 창에서 SetForegroundWindow()를 사용했습니다.

결과는 다음과 같습니다 어쨌든

//Getting the HWND of Chrome 
HWND chromeWindow = FindWindow("Chrome_WidgetWin_1", NULL); 
HWND chrome = GetWindow(chromeWindow, GW_HWNDNEXT); 

//Setting the window to the foreground (implies focus and activating) 
SetForegroundWindow(chrome); 

감사합니다.