Board index » cppbuilder » DHTMLED Retrieving the font at cursor (or how to retrieve a string from an activeX control without runtime errors)

DHTMLED Retrieving the font at cursor (or how to retrieve a string from an activeX control without runtime errors)


2006-01-28 10:15:44 AM
cppbuilder45
I am trying to retrieve the font used at the cursor in the DHTMLED control
(like a richedit but with HTML instead of RTF), but i keep getting runtime
errors.
Here's my code:
if (DHTMLEdit->Busy) return ;
if (DHTMLEdit->QueryStatus(DECMD_GETFONTNAME) == DECMDF_ENABLED)
{
::OleVariant v1;
::OLECMDEXECOPT tempvar = ::OLECMDEXECOPT_DODEFAULT ;
try{
v1 = (OleVariant)DHTMLEdit->ExecCommand(DECMD_GETFONTNAME, tempvar) ;
}catch(...){ }
}
If I don't add the try-catch i get an access violation in oleaut32.dll,
if i DO add the try-catch i get the following error during runtime:
'GetDefaultInterface()->ExecCommand(cmdID,cmdexecopt,pInVar,(VARIANT*)&pOutVar)':
The parameter is incorrect.
So the question is: How to retrieve this information correctly?
 
 

Re:DHTMLED Retrieving the font at cursor (or how to retrieve a string from an activeX control without runtime errors)

This works for me:
//---------------------------------------------------------------------------
String __fastcall THtmlEditBox::GetFontName()
// Get fontname of char under caret or in selected text
{
// See if the command is available
CMD_F retval = DHTMLEdit->QueryStatus(DECMD_GETFONTNAME);
if (retval == DECMDF_DISABLED)
// No font in selection
return String("");
if (retval == DECMDF_NINCHED)
// Mixed font types in selection
return String("");
if (retval == DECMDF_ENABLED)
{
// Get name of font at caret
TVariant vFontName = DHTMLEdit->ExecCommand(DECMD_GETFONTNAME,
Dhtmledlib_tlb::OLECMDEXECOPT_DODEFAULT, &TVariant(0));
if (vFontName.vt == VT_NULL || vFontName.vt == VT_EMPTY)
// Somehow failed to get fontname
return String("");
return String(vFontName);
}
}
HTH,
Willem.