Code sample Home

Create Windows-rendered text

This code sample demonstrates difference of rendering two text types - LC_ENT_TEXT and LC_ENT_TEXTWIN.
// Mode variants:
// 0 - add new text style 
// 1 - modify "Standard" text style
//-----------------------------------------------
void DemoTextWin (HANDLE hLcWnd, int Mode)
{
  HANDLE hDrw, hBlock, hTStyle;
  int    Align;
  double X, Y, H, WScale, Angle, Oblique;
  WCHAR* szText = L"Hello World!";
  WCHAR* szStyleName = L"My TextStyle";

  // get drawing and block, linked with CAD window
  hDrw = lcPropGetHandle( hLcWnd, LC_PROP_WND_DRW );
  hBlock = lcPropGetHandle( hLcWnd, LC_PROP_WND_BLOCK );

  if (Mode == 0){
    // get text style with specified name
    hTStyle = lcDrwGetObjectByName( hDrw, LC_OBJ_TEXTSTYLE, szStyleName );
    if (hTStyle == NULL){
      // the style don't exist, create new text style
      hTStyle = lcDrwAddTextStyle( hDrw, szStyleName, L"Times New Roman", true );
    }
  }else{
    // set font "Arial" for the text style "Standard"
    hTStyle = lcPropGetHandle( hDrw, LC_PROP_DRW_TEXTSTYLE_STD );
    lcPropPutBool( hTStyle, LC_PROP_TSTYLE_WINFONT, true );
    lcPropPutStr( hTStyle, LC_PROP_TSTYLE_FONT, L"Arial" );
    lcPropPutBool( hTStyle, LC_PROP_TSTYLE_SOLID, true );
  }
  // make this text style active
  lcPropPutHandle( hDrw, LC_PROP_DRW_TEXTSTYLE, hTStyle );

  Align = LC_TA_CENBOT;  // center-bottom
  X = 0.0;
  Y = 0.0;
  H = 5.0;
  Oblique = 0.0;
  WScale = 1.0;
  Angle = 0.0;
  lcBlockAddText2( hBlock, szText, X, Y, Align, H, WScale, Angle, Oblique );
  Y = Y + (H * 1.5);
  lcBlockAddTextWin2( hBlock, szText, X, Y, Align, H, WScale, Angle, Oblique );

  // update view
  lcBlockUpdate( hBlock, true, 0 );
  lcWndExeCommand( hLcWnd, LC_CMD_ZOOM_EXT, 0 );
}
This will create drawings as shown on pictures below:



Used functions:

lcBlockAddText2
lcBlockAddTextWin2

lcDrwGetObjectByName
lcDrwAddTextStyle
lcBlockUpdate
lcWndExeCommand

lcPropGetHandle
lcPropPutHandle
lcPropPutBool
lcPropPutStr