yucad3d

Create a drawing & embed the CAD window

The canonical start of every host: create the drawing, embed yucad's child window, add an entity, repaint — and destroy on shutdown. (hc_Code_CreateDrw in the VeCAD help.)

// Create a drawing and embed the CAD window into your Win32 window.
#include "yucad_api.h"

int  g_hDwg   = 0;
YuHwnd g_cad  = nullptr;

void host_init(HWND hwndParent) {
    g_hDwg = CadCreate();                             // the drawing
    g_cad  = CadWndCreate(g_hDwg, hwndParent,         // yucad's child window
                          0, 0, 0, 800, 600);
    CadAddLine(g_hDwg, 0, 0, 0, 100, 50, 0);          // first entity
    CadUpdate(g_hDwg);                                // repaint
}

void host_done() {
    CadDestroy(g_hDwg);                               // releases window + doc
}
// Create a drawing and embed the CAD window into a VCL panel.
procedure TfrmMain.FormCreate(Sender: TObject);
begin
  FhDwg    := CadCreate;                              // the drawing
  FCadHwnd := CadWndCreate(FhDwg, pnlCad.Handle,      // yucad's child window
                           0, 0, 0, pnlCad.ClientWidth, pnlCad.ClientHeight);
  CadAddLine(FhDwg, 0, 0, 0, 100, 50, 0);             // first entity
  CadUpdate(FhDwg);                                   // repaint
end;

procedure TfrmMain.FormDestroy(Sender: TObject);
begin
  CadDestroy(FhDwg);                                  // releases window + doc
end;
// Create a drawing and embed the CAD window into a WinForms panel.
public MainForm()
{
    InitializeComponent();
    _hDwg    = YuCadApi.CadCreate();                  // the drawing
    _cadHwnd = YuCadApi.CadWndCreate(_hDwg, pnlCad.Handle,   // yucad's child window
                                     0, 0, 0, pnlCad.Width, pnlCad.Height);
    YuCadApi.CadAddLine(_hDwg, 0, 0, 0, 100, 50, 0);  // first entity
    YuCadApi.CadUpdate(_hDwg);                        // repaint
}

protected override void OnFormClosed(FormClosedEventArgs e)
{
    YuCadApi.CadDestroy(_hDwg);                       // releases window + doc
    base.OnFormClosed(e);
}
This code is extracted verbatim from the shipped demo hosts (examples/cpp, examples/delphi, examples/csharp) — run the matching menu item there to see it live.