Focus setzen mit DHTML
-
Ich habe eine von CHTMLView abgeleitete Klasse mit der ich HTML-Seiten darstelle. Jetzt möchte ich den Fokus auf ein bestimmtes <input> Element setzen,
Das funktioniert aber nicht. Was fehlt noch?CWnd* CHtmlFenster::do_SetFocus(_bstr_t ID){ CWnd::SetFocus(); CWnd* w=GetFocus(); CComPtr<IHTMLElement> element; CComPtr<IHTMLControlElement> contr; CComPtr<IHTMLElement> contr2; HRESULT b=E_NOINTERFACE; if (getHtmlElement(ID,element)) { b=element->QueryInterface(IID_IHTMLControlElement, (void**) &contr); if (b==S_OK){ b=contr->focus(); // Beim Debuggen ist hier b==S_OK, also alles in Ordnung, der // Fokus wird trotzdem nicht gesetzt. } } return w; }Es ist sichergestellt das die Funktion erst ausgeführt wird, wenn die HTML-Seite geladen ist!
-
Vielleicht hilft dir das hier:
von[url] http://msdn.microsoft.com/workshop/browser/mshtml/reference/ifaces/controlelement/focus.asp [/url]
RemarksThis method fires the onfocus event.
As of Microsoft
Internet Explorer 5, elements that expose the IHTMLControlElement::focus method must have the TABINDEX attribute set.Elements cannot receive focus until the document finishes loading.
Außerdem find ich das ja mal echt cool das sich hie rmal einer mit DHTML in MFC auseinander setzt.
cu next
Tristan
-
Danke für die Anregung Tristan.
Ich habe eine Lösung gefunden.
Das Problem ist, das zuerst das HTML-Fenster (IHTMLWindow2) den Fokus erhalten muss, danach funktioniert es. (Ich habe keine Ahnung warum!).