Q ========================================= 张 teacher, hello! After reading your old article ?? TWebBrowser programming brief, I feel very helpful. I have encountered a problem now. How do I programmatically control a link to a linkage? For example, provincial, county-level SELECT, automatically enter certain values from the external program control, look forward to your help, 2004-10-14 answer ==================== ==================== 1, set the selectedIndex property of the IHTMLSelectlement interface to change the selected list item. 2, dynamically add a list item. Create an option object, HRESULT CreateElement (BSTR etag, // tag name);
Add IHTMLSELECTELEMENT :: Add to add the created Option object to the list HRESULT ADD (IHTMLELEMENT * Element, Variant Before //, VT_I4 type VARIANT);
See MSDN in more detailed content.
3. To manipulate each item in the list, first get a collection of list items from the IHTMLSelectTelement's item property, and then manipulate it through the IHTMLOptionElement interface. The following example demonstrates how to add a text of each of the drop-down list to a BSTR array pszoptText.
HRESULT GETOPTIONS (IHTMLSELECTELEMENT * PPVSELECT, BSTR * PSZOPTTEXT, Long * PLITEMS) {iDispatch * ppvdispoption; htmloptionelent * ppvoption; hResult HRESULT
// Get the number of Optoin objects in the SELECT object PPVSELECT-> GET_LENGTH (PLITEMS); for (long i = 0; i <* plitms; i ) {
// Get the idispatch pointer _variant_t index = i; hResult = ppvselect-> item (index, index, & ppvdispopption); if failed (HRESULT) Return (HRESULT);
// get IHTMLOptionElement interfaces hResult ppvdispOption-> QueryInterface (IID_IHTMLOptionElement, (void **) & ppvOption) =;. PpvdispOption-> Release (); if FAILED (hResult) return (hResult); // add text to the BSTR array hResult. = ppvoption-> get_text (& (pszopttext [i]))); ppvoption-> release (); if failed (hresult) return (} return s_ok;}) Reference address: FAQ: Manipulating drop-down list