home *** CD-ROM | disk | FTP | other *** search
/ Jason Aller Floppy Collection / 267.img / RESIDNTC.ZIP / DEMOS.ZIP / R_HELLO.C < prev    next >
Encoding:
C/C++ Source or Header  |  1990-02-14  |  2.7 KB  |  117 lines

  1. #include "tsr.h"
  2. #include "resproto.h"
  3. #include "stdio.h"
  4. #include "conio.h"
  5. #include "process.h"
  6.   
  7. /* R_HELLO.C */
  8. /* print Hello World! when Alt-H,
  9. Ctrl-H or Right-shift-J is pressed */
  10.   
  11. /* scan codes for H and J keys used below */
  12. #define SCAN_H 0x23
  13. #define SCAN_J 0x24
  14.   
  15. /* window save buffer declared globally */
  16. char  scrnbuf[300];
  17.   
  18. /* define two extra hotkeys */
  19. struct HKEYS more_keys[2] = {SCAN_H,CTRL_KEY,1,
  20. SCAN_J,RIGHT_SHIFT,2};
  21.   
  22. /* unique signature function number for
  23.    identification in tsrloaded()  */
  24.   
  25. /* hotkey number which is only needed for multiple hotkeys */
  26. extern int _hotkey_num;
  27.   
  28. unsigned int r_hello = 0x1260;
  29.   
  30. void resprog();
  31.   
  32. void main()
  33. {
  34. int  rc;           /* return code variable */
  35. /* declare function to execute when we get
  36.    control in TSR (when hotkey is hit)  */
  37.   
  38. /* test if our TSR is already loaded */
  39. if (!tsrloaded(r_hello))
  40.     {
  41.     if ((rc = inittsr(ALT_KEY, SCAN_H, resprog,
  42.         20, r_hello, SIG ,(void far *)NULL)) != 0)
  43.         {
  44.         printf("Could Not Load. Error = %d \n",
  45.         rc);
  46.         exit(1);
  47.         }
  48.     }
  49. }
  50.   
  51. /* this function gets control when popped up */
  52. void resprog()
  53. {
  54. int page;               /* video page */
  55. int mode;               /* video mode */
  56. int key;                        /* key hit    */
  57. /* retrieve video mode and video page */
  58. getvmod(&mode,&page);
  59.   
  60. /* see if we are in 80 column text modes */
  61. if ( mode != 2 && mode != 3 && mode != 7 )
  62.     {
  63.     putch(7);  /* if yes, beep and exit */
  64.     return;
  65.     }
  66.   
  67. /* save window in center of screen */
  68. savwindo(10,28,15,52,scrnbuf);
  69.   
  70. savcur();     /* save cursor  */
  71.   
  72. /*  clear the window in reverse video */
  73. scroll_vid(0,0,7,10,28,15,52,1);
  74.   
  75. loc_cur(12,34);   /* locate cursor in window */
  76. printf("Hello World!");
  77. loc_cur(13,34);   /* locate cursor in window */
  78. printf("Hotkey # = %d",_hotkey_num);
  79.   
  80. key = getch();    /* wait for a key to return */
  81. if(key == 0)        /* if extended key, get it */
  82.     getch();
  83.   
  84. rstcur();        /* put cursor back */
  85.   
  86. /* restore the window in center of screen */
  87. rstwindo(10,28,15,52,scrnbuf);
  88.   
  89. /* if Q key was hit, try to unload program */
  90.     if ((key == 'Q') || (key == 'q')){
  91.     key = freetsr();    /* use key for return code */
  92.         if (key != 0){      /*  if can not free beep */
  93.         putch(7);
  94.         putch(7);
  95.         }
  96.     }
  97.   
  98. return;
  99. }
  100.   
  101. void tsrpre()
  102. {
  103. tsrhotkeys(r_hello,(struct HKEYS far *)more_keys,2);
  104. printf("Program successfully loaded!!!!\n");
  105. printf("Hit Alt-H, Ctrl-H, or RightShift-J to Pop-Up\n");
  106. printf("Hit any key to continue.\n");
  107. getch();
  108. return;
  109. }
  110.   
  111. void tsrpost()
  112. {
  113.     /* beep once*/
  114. putch(7);
  115. return;
  116. }
  117.