home *** CD-ROM | disk | FTP | other *** search
/ PC Shareware 1996 December / PC_Shareware-1996-12.iso / windows / spectrum / sources / poke.c < prev    next >
Encoding:
C/C++ Source or Header  |  1996-05-22  |  2.7 KB  |  95 lines

  1.  
  2. /* Poke.c: Poke dialog interface implementation.
  3.  *
  4.  * Copyright 1996 Rui Fernando Ferreira Ribeiro.
  5.  *
  6.  * This program is free software; you can redistribute it and/or modify
  7.  * it under the terms of the GNU General Public License as published by
  8.  * the Free Software Foundation; either version 2 of the License, or
  9.  * (at your option) any later version.
  10.  *
  11.  * This program is distributed in the hope that it will be useful,
  12.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  14.  * GNU General Public License for more details.
  15.  *
  16.  * You should have received a copy of the GNU General Public License
  17.  * along with this program; if not, write to the Free Software
  18.  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  19.  */
  20.  
  21. #include <windows.h>
  22. #include "wspecem.h"        // Local header
  23. #include "env.h"
  24.  
  25. //   determine wich value there's on the box, and if there is one, return
  26. // it
  27. static BOOL ReadInt(HWND hwnd,int Control,unsigned short Min,
  28.             unsigned short  Max, unsigned short *Val)
  29. {
  30.     BOOL fError;
  31.     int n;
  32.  
  33.     n=(int)GetDlgItemInt(hwnd,Control,&fError,FALSE);
  34.     if (!fError || (n < Min) || (n > Max))
  35.         return(TRUE);
  36.     else
  37.         *Val=n;
  38.     return(FALSE);
  39. }
  40.  
  41. // dispatcher : handle the dialog
  42. BOOL CALLBACK DoPoke(HWND hwnd,UINT Message,WPARAM wParam,LPARAM lParam)
  43. {
  44.    static unsigned short address = 16384;
  45.    unsigned short val;
  46.  
  47.    char szBuffer[7];
  48.  
  49.     switch(Message)
  50.     {
  51.        case WM_INITDIALOG:
  52.           wsprintf((LPSTR)szBuffer, "%u", address);
  53.       SendDlgItemMessage(hwnd,IDC_ADDRESS,WM_SETTEXT,
  54.             0,(LPARAM)(LPSTR)szBuffer);
  55.       val = (unsigned char)readbyte(address);
  56.       wsprintf((LPSTR)szBuffer, "%u", val);
  57.       SendDlgItemMessage(hwnd,IDC_VALUE,WM_SETTEXT,
  58.             0,(LPARAM)(LPSTR)szBuffer);
  59.           return(TRUE);
  60.  
  61.        case WM_COMMAND:
  62.           switch(wParam)
  63.       {
  64.          case IDOK:
  65.         if(ReadInt(hwnd,IDC_ADDRESS,16384,65535,&address))
  66.         {
  67.            MessageBeep(MB_ICONEXCLAMATION);
  68.            MessageBox(hwnd, "Address must be between 16384 and 65535.",
  69.               "Poke", MB_OK | MB_ICONEXCLAMATION);
  70.            SetFocus(GetDlgItem(hwnd, IDC_ADDRESS) );
  71.                    return(TRUE);
  72.         }
  73.  
  74.         if(ReadInt(hwnd,IDC_VALUE,0,255,&val))
  75.         {
  76.            MessageBeep(MB_ICONEXCLAMATION);
  77.            MessageBox(hwnd, "Value must be between 0 and 255.",
  78.               "Poke", MB_OK | MB_ICONEXCLAMATION);
  79.            SetFocus(GetDlgItem(hwnd, IDC_VALUE) );
  80.                    return(TRUE);
  81.         }
  82.                 writebyte(address, val);
  83.             EndDialog(hwnd,1);
  84.         return(TRUE);
  85.  
  86.              case IDCANCEL:
  87.                 EndDialog(hwnd,0);
  88.             return(TRUE);
  89.           }
  90.     }
  91.     return(FALSE);
  92. }
  93.  
  94. /* EOF: Poke.c */
  95.