home *** CD-ROM | disk | FTP | other *** search
/ Amiga ISO Collection / AmigaUtilCD2.iso / Programming / Pascal / MAXONPASCAL3.DMS / in.adf / DEMOS-OS2.0 / CxTest.p < prev    next >
Encoding:
Text File  |  1994-08-25  |  3.7 KB  |  130 lines

  1. { Dieses kleine Prog. demonstriert die Erstellung von  }
  2. { HotKeys mit der commodities.library. Die Funktion    }
  3. { HotKey vereinfacht das Erstellen von HotKeys. Sie ist}
  4. { aber noch ausbaufähig (Fehlermeldungen etc.) !!      }
  5. {                                                      }
  6. { ©1994 by Björn "BOMBER" Schotte (BOMBERSOFT)         }
  7. {                                                      }
  8. { Written in MaxonPASCAL 3 (© by MAXON)                }
  9. {                                          BS/26/07/94 }
  10.  
  11. { Anmerkung: Das Programm basiert zum einen auf dem    }
  12. {            Pascal-Prog. Usershell aus der Kickstart  }
  13. {            09/92 und dem C-Prog. ActivateII aus der  }
  14. {            Kickstart 04/92                           }
  15. {            (basiert nur nach dem Erstellen von Hot-  }
  16. {            Keys !!)                                  }
  17.  
  18. PROGRAM CommoditiesTest;
  19.  
  20. {$opt q}
  21.  
  22. USES Exec;
  23.  
  24. {$incl"commodities.lib",
  25.       "libraries/commodities_functions.h",
  26.       "dos.lib"}
  27.  
  28. CONST
  29.   EVT_HOT = 1; { Erstes HotKey ID}
  30.   HOTKEY1  = "lalt f1"; { Definition des HotKeys (Tastenkombination etc.) }
  31.   EVT_POPKEY = 2; { Zweites HotKey ID }
  32.   POPKEY1  = "ralt f1"; { Definition des HotKeys }
  33.  
  34. VAR
  35.   mp : p_MsgPort;
  36.   co,broker,co1,filter1,filter2,send1,send2,co2 : p_CxObj;
  37.   b  : NewBroker;
  38.   done : BOOLEAN;
  39.   mask,x,x1 : LONG;
  40.   msg : p_CxMsg;
  41.   id,typ,err : LONG;
  42.   s,s1 : STR;
  43.  
  44. { Erstellt einen HotKey }
  45. FUNCTION  HotKey(beschr : STR; VAR co:p_CxObj; id:LONG) : p_CxObj;
  46. VAR
  47.   s : p_CxObj;
  48. BEGIN
  49.   HotKey := NIL;
  50.   co := CxFilter(PTR(beschr));
  51.   IF co = NIL THEN EXIT;
  52.   s := CxSender(mp,id);
  53.   IF s = NIL THEN
  54.   BEGIN
  55.     DeleteCxObj(co);
  56.     EXIT;
  57.   END;
  58.   AttachCxObj(co,s);
  59.   AttachCxObj(co,CxTranslate(NIL));
  60.   AttachCxObj(broker,co);
  61.   HotKey := co;
  62. END;
  63.  
  64. BEGIN
  65.   OpenLib(CxBase,"commodities.library",37);
  66.   mp := CreateMsgPort;
  67.   IF mp = NIL THEN Error("MessagePort could not be set up !!");
  68.   mp^.mp_Node.ln_Name := "TestPort";
  69.   AddPort(mp); { Port öffentlich machen }
  70.   { Broker-Struktur ausfüllen }
  71.   b := NewBroker(NB_VERSION,"TestBroker","TestBroker","Hallo",NBU_UNIQUE,
  72.                  0,0,mp,0);
  73.   { Broker erstellen: }
  74.   broker := CxBroker(^b,NIL);
  75.   IF broker<>NIL THEN
  76.   BEGIN
  77.     { HotKeys erstellen }
  78.     co := NIL;
  79.     co1 := NIL;
  80.     x := SIGBREAKF_CTRL_C;
  81.     x1 := 1 SHL mp^.mp_SigBit;
  82.     s := HOTKEY1;
  83.     co := HotKey(s,co,EVT_HOT);
  84.     s := POPKEY1;
  85.     co1 := HotKey(s,co1,EVT_POPKEY);
  86.     err := ActivateCxObj(broker,1); { Broker aktivieren !! }
  87.     done := FALSE;
  88.     REPEAT
  89.       { Auf CTRL-C oder Signal von Commodity warten !! }
  90.       mask := _Wait(x OR x1);
  91.       IF (mask AND x) = x THEN done := TRUE
  92.       ELSE IF (mask AND x1) = x1 THEN
  93.       BEGIN
  94.         msg := p_CxMsg(GetMsg(mp));
  95.         WHILE msg<>NIL DO
  96.         BEGIN
  97.           id := CxMsgID(msg);
  98.           typ := CxMsgType(msg);
  99.           CASE typ OF
  100.             CXM_IEVENT:
  101.               CASE id OF
  102.                 EVT_HOT: Writeln("HotKey"); { HotKey gedrückt }
  103.                 EVT_POPKEY: Writeln("PopKey"); { PopKey gedrückt }
  104.               ELSE END;
  105.             CXM_COMMAND:
  106.               { Kommt vom Proggy "Exchange" }
  107.               CASE id OF
  108.                 CXCMD_KILL : done := TRUE; { Commodity beenden }
  109.               ELSE END;
  110.           ELSE END;
  111.           msg := p_CxMsg(GetMsg(mp));
  112.         END;
  113.       END;
  114.     UNTIL done;
  115.     err := ActivateCxObj(broker,0); { Broker deaktivieren }
  116.     DeleteCxObjAll(broker); { Alle Objekte, die am Broker hängen, löschen }
  117.     { Noch anstehende Messages replyen }
  118.     msg := p_CxMsg(GetMsg(mp));
  119.     WHILE msg<>NIL DO
  120.     BEGIN
  121.       ReplyMsg(p_Message(msg));
  122.       msg := p_CxMsg(GetMsg(mp));
  123.     END;
  124.   END;
  125.   RemPort(mp); { Port vorm System entfernen }
  126.   DeleteMsgPort(mp); { Löschen des Ports }
  127. END.
  128.  
  129.  
  130.