Events Home

Event processing permits you to control user actions while the user is running your application. LiteCAD features several types of events that can be used to instantiate additional procedural code. For each of these events you create an "event procedure" in your application. It has the following syntax:

 void __stdcall EventProc (
   HANDLE hEvent

You have to define only those event procedures that you intend to use. Whenever the user performs any specified action, LiteCAD calls your previously defined corresponding procedure. Some events are manifested by setting a return value, in those cases, LiteCAD's behavior is dependant upon the return value.

These are service functions used to control events:

Function Event
lcEventSetProc Defines an application-defined event procedure for specific event
lcEventReturnCode Defines return code of event procedure
lcEventsEnable Enables or disables events generation

LiteCAD has the following types of events (defined by LC_PROP_EVENT_TYPE property):

Event type Meaning

Mouse and keyboard
LC_EVENT_MOUSEMOVE Window cursor position has been changed
LC_EVENT_LBDOWN Left mouse button has been pressed
LC_EVENT_LBUP Left mouse button has been released
LC_EVENT_LBDBLCLK Left mouse button double click
LC_EVENT_RBDOWN Right mouse button has been pressed
LC_EVENT_RBUP Right mouse button has been released
LC_EVENT_SNAP Allows a mouse to stick to specific points
LC_EVENT_KEYDOWN Keyboard key has been pressed

LC_EVENT_PAINT LiteCAD window is being redrawn
LC_EVENT_WNDVIEW View position has been changed in LiteCAD window
LC_EVENT_FILETAB User selects File Tab (to change active drawing in a window)
LC_EVENT_VIEWBLOCK Window has changed active block

LC_EVENT_ADDENTITY Graphic entity has been added
LC_EVENT_ENTPROP Entity's property value has been changed
LC_EVENT_ENTMOVE Entity has been moved
LC_EVENT_ENTSCALE Entity has been scaled
LC_EVENT_ENTROTATE Entity has been rotated
LC_EVENT_ENTMIRROR Entity has been mirrored
LC_EVENT_ENTERASE Entity flag "Deleted" was changed
LC_EVENT_GRIPMOVE User has moved entity's grip
LC_EVENT_GRIPDRAG User is dragging entity's grip
LC_EVENT_PICKENT User clicks on entity
LC_EVENT_SELECT Selection set has been changed
LC_EVENT_DRAWIMAGE Draw custom images

LC_EVENT_DRWPROP Drawing's property value has been changed
LC_EVENT_FILE Drawing has been loaded from a file or saved to a file
LC_EVENT_EXTENTS Drawing's extents has been changed

Custom command
LC_EVENT_ADDCMD LiteCAD initializes commands. Use this event to add custom commands.
LC_EVENT_CCMD Custom command interface
LC_EVENT_WAITPOINT Generated on mouse move while the function lcWndWaitPoint is running

LC_EVENT_ADDSTR LiteCAD initializes GUI strings
LC_EVENT_HELP User clicks on "Help" button in LiteCAD dialog
LC_EVENT_MAGNIFIER Magnifier property has been changed
LC_EVENT_NAVIGATOR Navigator (aerial view) property has been changed
LC_EVENT_GRID Coordinate grid property has been changed
LC_EVENT_OSNAP Object snap property has been changed
LC_EVENT_PTRACK Polar tracking property has been changed
LC_EVENT_ORTHO "Ortho mode" property has been changed

Some events are manifested by setting a return value, in those cases, LiteCAD's behavior is dependant upon the return value.
The function lcEventReturnCode is used to set event return code.

Inside the event procedure, you can access the following event properties by using the hEvent parameter:

Property Type Access Meaning
LC_PROP_EVENT_TYPE int R Event type (LC_EVENT_MOUSEMOVE and other)
LC_PROP_EVENT_APPPRM1 int R Application-defined parameter 1
LC_PROP_EVENT_APPPRM2 handle R Application-defined parameter 2
LC_PROP_EVENT_WND handle R LiteCAD design window
LC_PROP_EVENT_DRW handle R Drawing
LC_PROP_EVENT_HDC handle R Device context
LC_PROP_EVENT_HCMD handle R Object defined in a custom command
int RW Integer value.
The meaning depends on event type.
float RW Float value.
The meaning depends on event type.
string RW string value.
The meaning depends on event type.

Code sample:
// LiteCAD event procedure
void CALLBACK EventProc (HANDLE hEvent)
  int EventType;
  LcApplication* pApp = (LcApplication*)lcPropGetHandle( hEvent, LC_PROP_EVENT_APPPRM2 );
  if (pApp){
    EventType = lcPropGetInt( hEvent, LC_PROP_EVENT_TYPE );
    switch( EventType ){
      case LC_EVENT_MOUSEMOVE:  pApp->OnMouseMove( hEvent );  break;
      case LC_EVENT_KEYDOWN:    pApp->OnKeyDown( hEvent ); break;

bool LcApplication::Init (HINSTANCE hInst, LPCWSTR szAppDir)
  BOOL  bInit;
  lcEventSetProc( LC_EVENT_MOUSEMOVE, EventProc, 0, (HANDLE)this );
  lcEventSetProc( LC_EVENT_KEYDOWN, EventProc, 0, (HANDLE)this );
  bInit = lcInitialize();

void LcApplication::OnMouseMove (HANDLE hEvent)
  WCHAR szBuf[256], szNum[16];
  double X, Y;
  HANDLE hLcWnd = lcPropGetHandle( hEvent, LC_PROP_EVENT_WND );

  X = lcPropGetFloat( hLcWnd, LC_PROP_WND_CURX );
  Y = lcPropGetFloat( hLcWnd, LC_PROP_WND_CURY );

  // X
  okDblToStr( X, szNum );
  swprintf( szBuf, L"X: %s", szNum );
  lcStatbarText( m_hStatBar, 1, szBuf );
  // Y
  okDblToStr( Y, szNum );
  swprintf( szBuf, L"Y: %s", szNum );
  lcStatbarText( m_hStatBar, 2, szBuf );

  lcStatbarRedraw( m_hStatBar );

void LcApplication::OnKeyDown (HANDLE hEvent)
  UINT VirtKey, Flags;
  BOOL bShift, bCtrl;
  double X, Y;
  HANDLE hLcWnd, hLcDrw, hBlock;

  VirtKey = lcPropGetInt( hEvent, LC_PROP_EVENT_INT1 );
  Flags   = lcPropGetInt( hEvent, LC_PROP_EVENT_INT2 );
  bShift  = lcPropGetInt( hEvent, LC_PROP_EVENT_INT3 );
  bCtrl   = lcPropGetInt( hEvent, LC_PROP_EVENT_INT4 );
  X = lcPropGetFloat( hEvent, LC_PROP_EVENT_FLOAT1 );
  Y = lcPropGetFloat( hEvent, LC_PROP_EVENT_FLOAT2 );
  hLcWnd = lcPropGetHandle( hEvent, LC_PROP_EVENT_WND );
  hLcDrw = lcPropGetHandle( hEvent, LC_PROP_EVENT_DRW );
  hBlock = lcPropGetHandle( hEvent, LC_PROP_EVENT_BLOCK );

  if (OnKeyDown( VirtKey, Flags )){
    lcEventReturnCode( 1 );