c# - How to find out if the caret exists [in opera]? -
i'm trying solve following task: have opera browser , want find out, whether caret (text cursor) exist @ time. example, click on address bar, , want know caret blinking now. click on empty place on page , know there no caret exists.
in other words want define text element in focus now.
i know how solve task in many applications, of them uses standard windows controls such edit, can obtain focused window , check it's class winapi.
in other applications, controls rendering without native windows, can obtain automation ui.
but regret opera has 1 main window , doesn't provide access ui automation technology.
so, know how approach goal?)
edit:
thanks eric brown, solution of problem:
// consoleformsaa.cpp: определяет точку входа для консольного приложения. // #include "stdafx.h" #include <oleacc.h> #include <iostream> #pragma comment (lib, "oleacc.lib") void processcaretpos(hwnd hwnd); int _tmain(int argc, _tchar* argv[]) { (;;) { // active toplevel window hwnd hwnd = getforegroundwindow(); // current thread dword currentthreadid = getcurrentthreadid(); dword targetthreadid, targetprocessid; // target process , thread targetthreadid = getwindowthreadprocessid(hwnd, &targetprocessid); // attach current thread target thread messaging queue bool attached = attachthreadinput(currentthreadid, targetthreadid, true); // что это даст? Мы участвуем в обработке сообщений того потока // и все сис. вызовы, которые мы сделаем, будут посланы от имени того потока. if (attached) { try { // focused window handle (focused child of toplevel window) hwnd targetwindow = getfocus(); // procedure processcaretpos(targetwindow); } catch(...) {;} attachthreadinput(currentthreadid, targetthreadid, false); } sleep(1000); } return 0; } // void processcaretpos(hwnd hwnd) { iaccessible *pacccaret = null; variant varcaret; rect rccaret; varcaret.vt = vt_i4; varcaret.lval = childid_self; if (succeeded(accessibleobjectfromwindow(hwnd, objid_caret, iid_iaccessible, (void **)&pacccaret))) { hresult hr = pacccaret->acclocation( &rccaret.left, &rccaret.top, &rccaret.right, &rccaret.bottom, varcaret); if (!hr) { std::cout << "caret positon: " << rccaret.left << " " << rccaret.top << " " << rccaret.right << " " << rccaret.bottom << "\n"; } else std::cout << "there nothing carets" << "\n"; pacccaret->release(); } }
you're out of luck. however, if opera uses system caret (which might not; ie doesn't, example), can try using msaa query system caret location:
iaccessible *pacccaret = null; variant varcaret; rect rccaret; varcaret.vt = vt_i4; varcaret.lval = childid_self; if (succeeded(accessibleobjectfromwindow(hwnd, objid_caret, iid_iaccessible, (void **)&pacccaret))) { hr = pacccaret->acclocation( &rccaret.left, &rccaret.top, &rccaret.right, &rccaret.bottom, varcaret); pacccaret->release(); }
Comments
Post a Comment