home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / buttonc.zip / BUTTON.C
C/C++ Source or Header  |  1993-06-13  |  8KB  |  250 lines

  1. /*****************************************************************************/
  2. /*                                                                           */
  3. /*   Program    : Test Buttons                     Advanced Machine & Tool   */
  4. /*   Project    :                                  3824 Transportation Dr.   */
  5. /*   Author     : Court Sailor                     Fort Wayne, IN  46818     */
  6. /*   Date       : 05/12/1993                       (219) 489-3572            */
  7. /*                                                                           */
  8. /*   File Name  : BUTTONS.C                                                  */
  9. /*   Header File:                                                            */
  10. /*   Directory  : E:\PROTO\BUTTONS                                           */
  11. /*                                                                           */
  12. /*   Description:                                                            */
  13. /*                                                                           */
  14. /*                                                                           */
  15. /*   Revision # : 000                                                        */
  16. /*                                                                           */
  17. /*                                                                           */
  18. /*****************************************************************************/
  19. #define INCL_PM
  20. #define INCL_WIN
  21. #define INCL_GPI
  22. #define INCL_DOSPROCESS
  23. #define INCL_COMMOS2_32BIT
  24. #include <os2.h>
  25. #include <time.h>
  26. #include <conio.h>
  27. #include <stdio.h>
  28. #include <string.h>
  29. #include <stdlib.h>
  30. #include <commos2.h>
  31.  
  32. #include "mmilib.h"
  33. #include "touchscr.h"
  34.  
  35.  
  36. HAB   Hab;
  37. HMQ   Hmq;
  38. HWND  HWndSystem, HWndSystemClient;
  39. char  SystemClass[] = "System";
  40.  
  41.  
  42. void Thread1( HMQ  MsgQ );
  43.  
  44.  
  45. /*****************************************************************************/
  46. /*                                                                           */
  47. /*     Function:  SystemProcess                                              */
  48. /*                                                                           */
  49. /*     This function is designed to be the Main Menu of the MMI.  From here  */
  50. /*     an Operator can perform all the needed functions for this machine.    */
  51. /*                                                                           */
  52. /*****************************************************************************/
  53. MRESULT EXPENTRY SystemProcess( HWND HWnd, USHORT msg, MPARAM mp1, MPARAM mp2 )
  54. {
  55.    int     Choice;
  56.    char    Str[80];
  57.    USHORT  i, KeyFlags;
  58.    HPS     Hps;
  59.    RECTL   Rect;
  60.    HWND    HWndDlg;
  61.  
  62.    switch ( msg )
  63.       {
  64.       case WM_CREATE      : return( 0 );
  65.  
  66.       case WM_PAINT       : Hps = WinBeginPaint( HWnd, NULLHANDLE, &Rect );
  67.  
  68.                 GpiDrawBox( Hps, CLR_DARKGRAY, DRO_FILL, &Rect );
  69.                 GpiSetupRect( 120, 10, 520, 420, &Rect );
  70.                 GpiDrawBDBox( Hps, CLR_PALEGRAY, 3, BUMPED, &Rect );
  71.  
  72.                 WinEndPaint( Hps );
  73.                 return( 0 );
  74.  
  75.       case WM_BUTTON1DOWN : DosBeep( 1000, 10 );
  76.                 Hps = WinGetPS( HWnd );
  77.                 WinReleasePS( Hps );
  78.                 return( 0 );
  79.  
  80.       case WM_BUTTON1UP   : Hps = WinGetPS( HWnd );
  81.                 WinReleasePS( Hps );
  82.                 return( 0 );
  83.  
  84.       case WM_BUTTON2DOWN : Hps = WinGetPS( HWnd );
  85.                 WinReleasePS( Hps );
  86.                 return( 0 );
  87.  
  88.       case WM_DESTROY     : return( 0 );
  89.  
  90.       case WM_TOUCHSCREEN : WinSetPointerPos( HWND_DESKTOP, SHORT1FROMMP( mp1 ), SHORT2FROMMP( mp1 ) );
  91.                 return( 0 );
  92.  
  93.       case WM_TOUCHBUTTON : WinSendMsg( HWnd, WM_BUTTON1DOWN, mp1, mp2 );
  94.                 return( 0 );
  95.       }
  96.  
  97.    return WinDefWindowProc( HWnd, msg, mp1, mp2 );
  98. }
  99.  
  100.  
  101.  
  102.  
  103. int main()
  104. {
  105.    QMSG   Qmsg;
  106.    HPS    Hps;
  107.    TID    Thread1ID;
  108.    CHAR   Str[80];
  109.    ULONG  Err,
  110.       FrameFlags = FCF_TASKLIST | FCF_SYSMENU | FCF_MINMAX | FCF_TITLEBAR;
  111.  
  112.    /************************************************************************/
  113.    /*  Obtain a PM Window Handle from the O/S and create a Qmsg Queue.  */
  114.    /************************************************************************/
  115.    Hab = WinInitialize( 0 );
  116.    Hmq = WinCreateMsgQueue( Hab, 0 );
  117.  
  118.    /*****************************************************************************/
  119.    /*  Register the System Process with the O/S then create a Standard Window.  */
  120.    /*****************************************************************************/
  121.    WinRegisterClass( Hab,
  122.              SystemClass,
  123.              (PFNWP) SystemProcess,
  124.              CS_SIZEREDRAW,
  125.              0 );
  126.  
  127.    HWndSystem = WinCreateStdWindow( HWND_DESKTOP,
  128.                     WS_VISIBLE,
  129.                     &FrameFlags,
  130.                     SystemClass,
  131.                     "Touch Screen Dialog Button Tester",
  132.                     0L,
  133.                     NULLHANDLE,
  134.                     0,
  135.                     &HWndSystemClient );
  136.  
  137.    WinSetWindowPos( HWndSystem, HWND_BOTTOM,
  138.             0,                                               /* x pos */
  139.             0,                                               /* y pos */
  140.             640,                                             /* x size */
  141.             480,                                             /* y size */
  142.             SWP_ACTIVATE | SWP_MOVE | SWP_SIZE | SWP_SHOW);  /* flags  */
  143.  
  144.    /**********************************/
  145.    /*  Start Up the COMM Subsystem.  */
  146.    /**********************************/
  147.    Err = CommStartSystem( 3 );
  148.    if ( Err != COMM_ERROR_NOERROR )
  149.       {
  150.       sprintf( Str, "COMM Subsystem Start Error => %ld", Err );
  151.       WinMessageBox( HWndSystem, HWndSystem,
  152.              Str,
  153.              "TOUCH SCREEN INITIALIZATION",
  154.              1,
  155.              MB_CANCEL | MB_ERROR |
  156.              MB_DEFBUTTON1 | MB_SYSTEMMODAL );
  157.       }
  158.  
  159.    /**********************************/
  160.    /*  Initialize the Touch Screen.  */
  161.    /**********************************/
  162.    Err= InitializeTouchScreen( 1 );
  163.    if ( Err )
  164.       {
  165.       sprintf( Str, "Touch Screen Init Error => %ld", Err );
  166.       WinMessageBox( HWndSystem, HWndSystem,
  167.              Str,
  168.              "TOUCH SCREEN INITIALIZATION",
  169.              1,
  170.              MB_CANCEL | MB_ERROR |
  171.              MB_DEFBUTTON1 | MB_SYSTEMMODAL );
  172.       }
  173.  
  174.    DosCreateThread( &Thread1ID, (PFNTHREAD) Thread1, Hmq, 0L, 8192 );
  175. /*   DosSetPriority( 2, 2, 0, Thread1ID );*/
  176.  
  177.    /*******************************************************/
  178.    /*  Dispatch all messages to the SystemProc Function.  */
  179.    /*******************************************************/
  180.    while ( WinGetMsg( Hab, &Qmsg, 0, 0, 0 ) ) WinDispatchMsg( Hab, &Qmsg );
  181.  
  182.    /*****************************************************************/
  183.    /*  Distroy the System Process Main Window and close things up.  */
  184.    /*****************************************************************/
  185.    WinDestroyWindow( HWndSystem );
  186.    WinDestroyMsgQueue( Hmq );
  187.    WinTerminate( Hab );
  188.  
  189.    /********************************/
  190.    /*  Close Up the Touch Screen.  */
  191.    /********************************/
  192.    DosKillThread( Thread1ID );
  193.    TurnOffTouchScreen();
  194.  
  195.    return( 0 );
  196. }
  197.  
  198.  
  199.  
  200.  
  201. void Thread1( HMQ  MsgQ )
  202. {
  203.    int     X, Y, Action;
  204.    MPARAM  mp1 = 0,
  205.        mp2 = 0;
  206.  
  207.    while ( 1 == 1 )
  208.       {
  209.       /******************************************************************/
  210.       /*  Check the Touch Screen to see if any action has taken place.  */
  211.       /******************************************************************/
  212.       Action = GetTouchScreenSelection( &X, &Y );
  213.       X *= 8;  Y = 480 - (Y * 10);
  214.       mp1 = MPFROMLONG( X + ((ULONG) Y << 16 ) );
  215.  
  216.       /*************************************************************************/
  217.       /*  Post a message in the Message Queue that the Touch Screen was used.  */
  218.       /*************************************************************************/
  219.       if ( Action == TOUCH_TRACKING )
  220.      {
  221.      WinPostQueueMsg( MsgQ, WM_TOUCHSCREEN, mp1, mp2 );
  222.      }
  223.       else if ( Action == TOUCH_EXIT )
  224.      {
  225.      /***********************/
  226.      /*  This Works Great!  */
  227.      /***********************/
  228. /*     SystemProcess( HWndSystem, WM_BUTTON1DOWN, mp1, mp2 );
  229. */
  230.  
  231.      /***********************/
  232.      /*  This Works Great!  */
  233.      /***********************/
  234. /*     WinPostQueueMsg( MsgQ, WM_TOUCHBUTTON, mp1, mp2 );
  235. */
  236.  
  237.      /********************************/
  238.      /*  This DOES NOT Work At All.  */
  239.      /********************************/
  240.      WinSendMsg( HWndSystem, WM_BUTTON1DOWN, mp1, mp2 );
  241.      }
  242.       }
  243.  
  244. }
  245.  
  246.  
  247.  
  248.  
  249.  
  250.