Working with Layers

Take the following steps to show/hide layers from a vector drawing:

Start with the project you created in Implementing Hit Testing.

  1. Add these local variables under the HDC hDC; statement in the WndProc function:

    L_INT nIndex;   
    VECTORLAYER Layer;   
    VECTORLAYERDESC LayerDesc; 

  2. Add the following lines in WM_CREATE handler right after L_VecInit ( &Vector ); statement:

    L_VecLoadFile (MAKE_IMAGE_PATH(TEXT("random.dxf")), &Vector, NULL, NULL ); 

  3. Add the following lines before the case 'x' statement of the WM_CHAR message:

       case '1':   
       case '2':   
      // get layer from index   
      if( wParam == '1' )   
       nIndex = 0;   
      else   
       nIndex = 1;   
      L_VecGetLayerByIndex ( &Vector, nIndex, &Layer );   
      L_VecGetLayer ( &Vector, &Layer, &LayerDesc );   
      // flip the visible state of the layer   
      LayerDesc.bVisible = !LayerDesc.bVisible;   
      // update   
      L_VecSetLayer ( &Vector, &Layer, &LayerDesc );   
      L_VecFreeLayer ( &LayerDesc );   
      InvalidateRect( hWnd, NULL, FALSE );   
      break; 

  4. Compile and run the demo.

  5. The sample image (random.dxf) shipped with LEADTOOLS has 2 layers. You should be able to hide/show those layers by pressing 1 and 2 on your keyboard.  

Help Version 21.0.2021.7.2
Products | Support | Contact Us | Intellectual Property Notices
© 1991-2021 LEAD Technologies, Inc. All Rights Reserved.

LEADTOOLS Vector C API Help
Products | Support | Contact Us | Intellectual Property Notices
© 1991-2021 LEAD Technologies, Inc. All Rights Reserved.