home *** CD-ROM | disk | FTP | other *** search
/ World of Shareware - Software Farm 2 / wosw_2.zip / wosw_2 / QBAS / DIAMOND1.ZIP / DIATEST.ZIP / DIATEST.C next >
C/C++ Source or Header  |  1992-03-07  |  4KB  |  183 lines

  1. #include "windows.h"
  2. #include "diatest.h"
  3.  
  4. HANDLE hInst;
  5. HWND MainWin;
  6.  
  7.  
  8. char *PressStr[ 7 ] = { "Top Pressed", "Right Pressed", "Bottom Pressed",
  9.                         "Left Pressed", "Enabled", "Disabled", "Not on Pad" };
  10.  
  11.  
  12. int PASCAL WinMain( hInstance, hPrevInstance, lpCmdLine, nCmdShow )
  13. HANDLE hInstance;
  14. HANDLE hPrevInstance;
  15. LPSTR lpCmdLine;
  16. int nCmdShow;
  17. {
  18.    MSG msg;
  19.  
  20.    if( ! hPrevInstance )
  21.       if( ! InitApplication( hInstance ) )
  22.          return( FALSE );
  23.  
  24.    if( ! InitInstance( hInstance, nCmdShow ) )
  25.       return( FALSE );
  26.  
  27.    while( GetMessage( &msg, NULL, NULL, NULL ) )
  28.    {
  29.          TranslateMessage( &msg );
  30.          DispatchMessage( &msg );
  31.    }
  32.    return( msg.wParam );
  33. }
  34.  
  35. BOOL InitApplication( hInstance )
  36. HANDLE hInstance;
  37. {
  38.    WNDCLASS  wc;
  39.  
  40.    wc.style = NULL;
  41.    wc.lpfnWndProc = MainWndProc;
  42.  
  43.    wc.cbClsExtra = 0;
  44.    wc.cbWndExtra = 0;
  45.    wc.hInstance = hInstance;
  46.    wc.hIcon = LoadIcon( hInst, "MainIcon" );
  47.    wc.hCursor = LoadCursor( NULL, IDC_ARROW );
  48.    wc.hbrBackground = COLOR_WINDOW + 1;
  49.    wc.lpszMenuName = "MainMenu";
  50.    wc.lpszClassName = "DIATEST";
  51.  
  52.    return( RegisterClass( &wc ) );
  53. }
  54.  
  55. BOOL InitInstance(hInstance, nCmdShow)
  56. HANDLE hInstance;
  57. int nCmdShow;
  58. {
  59.    HWND hWnd;
  60.  
  61.    hInst = hInstance;
  62.  
  63.    hWnd = CreateWindow( "DIATEST",
  64.                         (LPSTR)"Diamond Control",
  65.                         WS_OVERLAPPEDWINDOW,
  66.                         CW_USEDEFAULT,
  67.                         CW_USEDEFAULT,
  68.                         200,
  69.                         200,
  70.                         NULL,
  71.                         NULL,
  72.                         hInstance,
  73.                         NULL );
  74.  
  75.    if( ! hWnd )
  76.       return( FALSE );
  77.    MainWin = hWnd;
  78.    ShowWindow( hWnd, nCmdShow );
  79.    UpdateWindow( hWnd );
  80.    return( TRUE );
  81. }
  82.  
  83. long FAR PASCAL MainWndProc( hWnd, message, wParam, lParam )
  84. HWND hWnd;
  85. unsigned message;
  86. WORD wParam;
  87. LONG lParam;
  88. {
  89.    FARPROC DlgProc;
  90.  
  91.    switch( message )
  92.    {
  93.       case WM_COMMAND:
  94.          if( wParam == IDM_EXIT )
  95.          {
  96.             PostQuitMessage( 0 );
  97.             break;
  98.          }
  99.  
  100.          if( wParam == IDM_ABOUT )
  101.          {
  102.             DlgProc = MakeProcInstance( About, hInst );
  103.             DialogBox( hInst, "ABOUT", MainWin, DlgProc );
  104.             FreeProcInstance( DlgProc );
  105.             break;
  106.          }
  107.          break;
  108.  
  109.  
  110.       case WM_DESTROY:
  111.          PostQuitMessage( 0 );
  112.          return( TRUE );
  113.  
  114.       default:
  115.          return( DefWindowProc( hWnd, message, wParam, lParam ) );
  116.    }
  117.    return( NULL );
  118. }
  119.  
  120. BOOL FAR PASCAL About( hDlg, message, wParam, lParam )
  121. HWND hDlg;
  122. unsigned message;
  123. WORD wParam;
  124. LONG lParam;
  125. {
  126.    HANDLE hMod;
  127.  
  128.    switch( message )
  129.    {
  130.       case WM_INITDIALOG:
  131.          SetProp( hDlg, MAKEINTRESOURCE( 1 ), 1 );
  132.          return( TRUE );
  133.  
  134.       case WM_CTLCOLOR:
  135.          if( HIWORD( lParam ) == CTLCOLOR_DLG ||
  136.              HIWORD( lParam ) == CTLCOLOR_STATIC )
  137.          {
  138.             SetBkColor( wParam, RGB( 192, 192, 192 ) );
  139.             SetBkMode( wParam, OPAQUE );
  140.             return( GetStockObject( LTGRAY_BRUSH ) );
  141.          }
  142.          break;
  143.  
  144.       case WM_COMMAND:
  145.          if( wParam == 101 )
  146.          {
  147.             if( GetProp( hDlg, MAKEINTRESOURCE( 1 ) ) )
  148.             {
  149.                SetProp( hDlg, MAKEINTRESOURCE( 1 ), 0 );
  150.                SendMessage( GetDlgItem( hDlg, 100 ), WM_ENABLE, FALSE, NULL );
  151.                SetWindowText( GetDlgItem( hDlg, 200 ), PressStr[ 5 ] );
  152.             }
  153.             else
  154.             {
  155.                SetProp( hDlg, MAKEINTRESOURCE( 1 ), 1 );
  156.                SendMessage( GetDlgItem( hDlg, 100 ), WM_ENABLE, TRUE, NULL );
  157.                SetWindowText( GetDlgItem( hDlg, 200 ), PressStr[ 4 ] );
  158.             }
  159.             break;
  160.          }
  161.  
  162.          if( wParam == IDOK )
  163.          {
  164.             RemoveProp( hDlg, MAKEINTRESOURCE( 1 ) );
  165.             EndDialog( hDlg, TRUE );
  166.             return( TRUE  );
  167.          }
  168.  
  169.          if( wParam == 100 )
  170.          {
  171.             if( LOWORD( lParam ) == -1 )
  172.                SetWindowText( GetDlgItem( hDlg, 200 ), PressStr[ 6 ] );
  173.             else
  174.                SetWindowText( GetDlgItem( hDlg, 200 ), PressStr[ LOWORD( lParam ) ] );
  175.             break;
  176.          }
  177.  
  178.          break;
  179.    }
  180.    return( FALSE );
  181. }
  182.  
  183.