I need to identify, for example, when we hit a text box in a web page, we get a "| " key sign right (Which would blink, until we type)

If you don't get what i am saying, go to google and click on the search text box, u would see a " | " sign that is blinking.

I need to write a C++ code to identify this sign, as in when the focus changes to this sign to trigger a certain event. I am unable to find what this sign is called. Can some some help me by providing some sample code or a tutorial or some sort of a pointer for me to start learning about this.

Dani AI

Generated

As called it a "cursor" and pointed toward control focus, a clearer name for the blinking vertical bar inside a page is the text caret (aka insertion point). The mouse pointer (the I‑beam icon that appears when hovering over text) is a separate thing; OS mouse-position APIs return the pointer location, not which HTML element has the caret.

When hosting a WebBrowser (the browser control) the document engine manages DOM focus and the caret. Host-level focus checks (for example, a WinForms Control.Focused or raw mouse coordinates) only say whether the host control has focus or where the pointer is — they do not identify which input inside the page is focused. The robust approach is to subscribe to DOM focus events inside the loaded page and forward those events to the host.

Example (managed WinForms): after the page finishes loading, attach handlers to input/textarea elements and handle their focus events:

// in DocumentCompleted
var doc = webBrowser1.Document;
foreach (HtmlElement el in doc.GetElementsByTagName("input"))
    el.AttachEventHandler("onfocus", OnElementFocus);
foreach (HtmlElement el in doc.GetElementsByTagName("textarea"))
    el.AttachEventHandler("onfocus", OnElementFocus);

void OnElementFocus(object sender, EventArgs e)
{
    var el = sender as HtmlElement;
    // inspect el.GetAttribute("id") / name / value and notify host
}

For native C++ hosting (MSHTML/ActiveX) either (a) use the MSHTML COM interfaces (IHTMLDocument2/IHTMLElementCollection and IHTMLElement3::attachEvent) and implement an IDispatch sink to receive events, or (b) inject a small script that registers focus/focusin handlers and calls back into the host (via the host object exposed to script or by posting messages). Notes: attach handlers after the document (and any frames) are ready; dynamic/AJAX pages may require re-scanning or delegation (listen for focusin on the document); cross-zone/protected-mode security can affect script injection.

Recommended Answers

All 5 Replies

That '|' sign is called a cursor. If you want win32 api GUI program then there are cursor functions, such as GetCursorPosition()

That '|' sign is called a cursor. If you want win32 api GUI program then there are cursor functions, such as GetCursorPosition()

It can't be a cursor, because when you click on the text box the "| " sign appears, then try moving your mouse away, then the cursor position will also change without any change done to the " | " position.

and also i belive that getcursorposition() would give the X and Y axis of the cursor.

Any Idea About This ?

Am I correct in assuming you're doing a Windows Forms application? The textBox has a Focused method (http://msdn.microsoft.com/en-us/library/system.windows.forms.control.focused(v=VS.100).aspx , for the latest incarnation, but it goes back to .NET 1.1).

It can't be a cursor

It is still referred to as a cursor, as it was called that long before there were mice or windows hehe :)

Am I correct in assuming you're doing a Windows Forms application? The textBox has a Focused method (http://msdn.microsoft.com/en-us/library/system.windows.forms.control.focused(v=VS.100).aspx , for the latest incarnation, but it goes back to .NET 1.1).

It is still referred to as a cursor, as it was called that long before there were mice or windows hehe :)

The link that you gave, talks about a text box in a windows Form. Mine is different

I have created a WIndows form based web browser, So the web browser that i created has a text box, where you can enter a web address, and click the 'go' button for the web page to appear.

For example say we entered www.google.com, and it opened successfully. In the googl.com home page there is a text box right ? when i click on that there will be a "I-BEAM" icon or " | " sign. I need to identify this sign that appears in google.com's search text bar.


Hope i made my self clear. help appreciated

Yes, you did. Thanks for clarifying. The text box is probably not accessible through your program. I don't remember much about the web browser control, but I don't know that you can pick out elements (like you could in DOM scripting in JavaScript). I think using the HTTPWebRequest type functions you could do your own POST of the page, but I don't know enough about that to help you.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.