跳转到内容

Palm OS/C 编程/使用自定义事件

来自维基教科书,开放的书籍,开放的世界

定义事件

[编辑 | 编辑源代码]
 #define  echoEvent  (firstUserEvent + 0)
 
 typedef struct
 {
   WChar  chr;  // just to demonstrate transporting data with an event
 }
 EchoEvent;


构建和排队事件

[编辑 | 编辑源代码]
 EventType  event;
 EchoEvent  *ee;
 
 // set the type of the event to the custom event type identifier
 event.eType = echoEvent;
 
 // interpret the Palm OS event storage area as a custom event
 ee = (EchoEvent *) &event.data.generic;
 
 // fill in the custom event
 ee->chr = chr;
 
 // place the filled out event on the event queue
 EvtAddEventToQueue( &event);


处理事件

[编辑 | 编辑源代码]
 // as an example of where stock events are handled..
 Boolean appHandleEvent( EventPtr event)
 
 ...
 
   switch ( event->eType)
   {
     case keyDownEvent:
 
     ...
 
     // custom events are handle naturally alongside stock events:
     case echoEvent:
 
       // interpret the Palm OS event storage area as a custom event
       EchoEvent  *ee = (EchoEvent *) &event->data.generic;
 
       // refer to the parts of the event
       ee->chr;
华夏公益教科书