home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 10 / 10.iso / l / l231 / 3.ddi / SAMPLES / WINDLL / SYSDATA.AS$ / SYSDATA
Encoding:
Text File  |  1992-11-12  |  14.1 KB  |  429 lines

  1. ;----------------------------------------------------------------------------;
  2. ;                               SYSDATA.ASM                                  ;
  3. ;----------------------------------------------------------------------------;
  4. ; Sample program that accesses the SYSINFO.DLL functions.                    ;
  5. ;----------------------------------------------------------------------------;
  6.  
  7.         .model  small, pascal, nearstack
  8.         .286
  9.  
  10.         ?WINPROLOGUE = 1
  11.         include win.inc                 ; Converted from WINDOWS.H
  12.         include dll.inc                 ; SYSINFO.DLL definitions
  13.         include sysdata.inc             ; equates for dialog controls
  14.  
  15. ;----------------------------------------------------------------------------;
  16. ;                        Prototypes & External Definitions                   ;
  17. ;----------------------------------------------------------------------------;
  18.  
  19. NPBYTE          TYPEDEF NEAR PTR BYTE
  20.  
  21. WinMain         PROTO PASCAL, hInstance:HANDLE,  hPrevInstance:HANDLE,
  22.             lpszCmdLine:LPSTR, nCmdShow:SWORD
  23. WndProc         PROTO FAR PASCAL,  :HWND, :WORD, :SWORD, :SDWORD
  24. SetDlg          PROTO,      :HWND
  25. SetKeyb         PROTO,      :HWND
  26. SetTime         PROTO,      :HWND
  27. int2hex         PROTO,      :WORD, :NPBYTE
  28. SetItem         PROTO,      :HWND, :WORD, :WORD
  29.  
  30. extern __astart:proc            ; When Windows load an app, it expects astart
  31.                 ; to have the necessary start-up code. We get
  32.                 ; astart from APPENTRY.ASM
  33.  
  34. ;----------------------------------------------------------------------------;
  35. ;                             Numeric Equates                                ;
  36. ;----------------------------------------------------------------------------;
  37.  
  38. TIMER_SECS       EQU    1000t           ; timer interval: 1000 mill = 1 second
  39. fNUMLOCK         EQU    020h            ; Flags within the Keyboard Status word
  40. fCAPLOCK         EQU    040h            ; that indicate different key modes
  41. fSHIFTS          EQU    003h
  42. fCONTROL         EQU    004h
  43.  
  44.  
  45. ;----------------------------------------------------------------------------;
  46. ;                               Data Segments                                ;
  47. ;----------------------------------------------------------------------------;
  48.  
  49.     .const 
  50.  
  51. szAppName       SBYTE   "SysData",0                   
  52. szSysIcon       SBYTE   "SysIcon",0
  53. szTooManyTimers SBYTE   "Too many clocks or timers!",0
  54.  
  55. szError         SBYTE   "Error",0
  56.  
  57. szCoNotInst     SBYTE   "Not Found",0
  58. szCoInst        SBYTE   "Found",0
  59.  
  60. szOff           SBYTE   "Off",0
  61. szOn            SBYTE   "On",0
  62.  
  63. hex             BYTE    '0123456789ABCDEF'      ; Table of hexadecimal digits
  64.                         ; for int2hex function
  65. ProcTable       NPBYTE  sz8086
  66.         NPBYTE  sz80186
  67.         NPBYTE  sz80286
  68.         NPBYTE  sz80386
  69.         NPBYTE  sz80486
  70.  
  71. sz8086          SBYTE   "8086",0
  72. sz80186         SBYTE   "80186",0
  73. sz80286         SBYTE   "80286",0
  74. sz80386         SBYTE   "80386",0
  75. sz80486         SBYTE   "80486",0
  76.  
  77.         .data
  78.  
  79. HexValue        BYTE    "xxxxh",0
  80. Initialized     BYTE    0
  81.         
  82. ;----------------------------------------------------------------------------;
  83. ;                               Code Segment                                 ;
  84. ;----------------------------------------------------------------------------;
  85.  
  86.         .code
  87.  
  88. ;----------------------------------------------------------------------------;
  89. ;                               WinMain                                      ;
  90. ;----------------------------------------------------------------------------;
  91. ;                                                                            ;
  92. ; Main routine called by Windows in program start. If no previous instances, ;
  93. ; sets up a window class and registers it, then sets up the message loop.    ;
  94. ;                                                                            ;
  95. ;----------------------------------------------------------------------------;
  96.  
  97. WinMain         PROC,   hInstance:HANDLE,  hPrevInstance:HANDLE,
  98.             lpszCmdLine:LPSTR, nCmdShow:SWORD
  99.         LOCAL   msg:MSG, wndclass:WNDCLASS
  100.  
  101.         ; Local variables: msg: message to be used in the message loop
  102.         ;                  wndclass: temp. to store window class
  103.         ;                  x,y Start-Client: Size of Initial Window
  104. ;
  105. ;--- Check for previous instances
  106. ;
  107.         .IF (hPrevInstance == 0)
  108.  
  109.             lea     di, wndclass    ; because we use a NEARSTACK,
  110.             ASSUME  di:PTR WNDCLASS ; ss=ds
  111.  
  112.             mov     WORD PTR [di].lpfnWndProc,   LROFFSET WndProc
  113.             mov     WORD PTR [di].lpfnWndProc+2, SEG WndProc
  114.  
  115.             mov     [di].cbWndExtra, DLGWINDOWEXTRA
  116.  
  117.             xor     ax,ax
  118.             mov     [di].style,ax 
  119.             mov     [di].cbClsExtra, ax
  120.  
  121.             INVOKE  LoadIcon, hInstance, ADDR szSysIcon 
  122.             mov     [di].hIcon, ax 
  123.  
  124.             mov     ax, hInstance
  125.             mov     [di].hInstance, ax
  126.  
  127.             INVOKE  LoadCursor, NULL, IDC_ARROW
  128.             mov     [di].hCursor, ax
  129.  
  130.             mov     [di].hbrBackground, COLOR_WINDOW +1
  131.  
  132.             xor     ax, ax
  133.             mov     WORD PTR [di].lpszMenuName,   ax
  134.             mov     WORD PTR [di].lpszMenuName+2, ax
  135.  
  136.             mov     WORD PTR [di].lpszClassName,   OFFSET szAppName
  137.             mov     WORD PTR [di].lpszClassName+2, ds
  138.  
  139.             INVOKE  RegisterClass, di
  140.             .IF (ax == 0)
  141.                 mov     ax, FALSE
  142.                 jmp     doRet
  143.             .ENDIF
  144.  
  145.             ASSUME  di:NOTHING        
  146.  
  147.         .ENDIF     ;--- End of IF (hPrevInstance == 0)
  148.  
  149.     INVOKE  CreateDialog, hInstance, ADDR szAppName, 0, NULL
  150.     mov     si, ax
  151.     INVOKE  ShowWindow, si, nCmdShow
  152.  
  153. ;---- Create Timer for Window
  154.  
  155.         INVOKE  SetTimer, si, 1, TIMER_SECS, NULL
  156.         .IF (ax == 0)
  157.             INVOKE  MessageBox, si,ADDR szTooManyTimers, 
  158.                         ADDR szAppName,
  159.                         MB_ICONEXCLAMATION OR MB_OK
  160.             mov     ax, FALSE
  161.             INVOKE PostQuitMessage, 0               ; Quit.
  162.         .ENDIF
  163.  
  164. ;---- Message Loop
  165.  
  166.         .WHILE TRUE
  167.  
  168.             INVOKE  GetMessage,    ADDR msg, NULL, 0, 0
  169.  
  170.             .BREAK .IF (ax == 0)
  171.  
  172.             INVOKE  TranslateMessage, ADDR msg
  173.             INVOKE  DispatchMessage,  ADDR msg
  174.  
  175.         .ENDW
  176.  
  177.         mov     ax, msg.wParam
  178. doRet:
  179.         ret
  180.  
  181. WinMain         ENDP
  182.  
  183.  
  184. ;----------------------------------------------------------------------------;
  185. ;                                  SetTime                                   ;
  186. ;                                                                            ;
  187. ; Reads the System Time with GetSysTime, sets up the Dialog Item TIME_TEXT   ;
  188. ; with the resulting string. Then does the same for DATE_TEXT.               ;
  189. ;----------------------------------------------------------------------------;
  190.  
  191. SetTime PROC, hDlg:HWND
  192.  
  193.         INVOKE  GetSysTime
  194.         INVOKE  SetDlgItemText, hDlg, TIME_TEXT, dx::ax
  195.         INVOKE  GetSysDate
  196.         INVOKE  SetDlgItemText, hDlg, DATE_TEXT, dx::ax
  197.  
  198.         ret
  199. SetTime ENDP
  200.  
  201.  
  202. ;----------------------------------------------------------------------------;
  203. ;                                  SetKeyb                                   ;
  204. ;                                                                            ;
  205. ; Assumes DI has the keyboard status. Gets the control's text into buffer.   ;
  206. ; If the control's status has changed (if buffer+1 is not what it would be   ;
  207. ; set to) then set it to On or Off, otherwise return                         ;
  208. ;----------------------------------------------------------------------------;
  209.  
  210. SetItem PROC, hDlg:HWND, item:WORD, flag:WORD
  211.         LOCAL   buffer[3]:BYTE
  212.  
  213.     INVOKE  GetDlgItemText, hDlg, item, ADDR buffer, 3
  214.     
  215.     mov     bx, di
  216.     and     bx, flag
  217.     .IF bx
  218.         .IF (byte ptr buffer+1 != 'n')       ; 'n' means we have 'On'
  219.             mov     bx, OFFSET szOn
  220.         .ELSE
  221.             jmp     doRet
  222.         .ENDIF
  223.     .ELSE
  224.         .IF (byte ptr buffer+1 != 'f')       ; 'f' means we have 'Off'
  225.             mov     bx, OFFSET szOff
  226.         .ELSE
  227.             jmp     doRet
  228.         .ENDIF
  229.     .ENDIF
  230.     INVOKE  SetDlgItemText, hDlg, item, ds::bx
  231.  
  232. doRet:  
  233.     ret
  234.  
  235. SetItem ENDP
  236.  
  237.  
  238. ;----------------------------------------------------------------------------;
  239. ;                                  SetKeyb                                   ;
  240. ;                                                                            ;
  241. ; Reads the keyboard status with GetSysInfo, then uses SetItem to set the    ;
  242. ; appropiate controls in the dialog box.                                     ;
  243. ;----------------------------------------------------------------------------;
  244.  
  245. SetKeyb PROC, hDlg:HWND
  246.  
  247.         INVOKE  GetSysInfo
  248.         mov     es, dx
  249.         mov     si, ax
  250.         ASSUME  SI:PTR SYSINFO
  251.         mov     di, es:[si].wKbStatus
  252.         INVOKE  SetItem, hDlg, NUMLOCK,fNUMLOCK
  253.         INVOKE  SetItem, hDlg, CAPLOCK,fCAPLOCK
  254.         INVOKE  SetItem, hDlg, CONTROL,fCONTROL
  255.         INVOKE  SetItem, hDlg, SHIFTS, fSHIFTS
  256.         ASSUME  SI:NOTHING
  257.  
  258.         ret
  259. SetKeyb ENDP
  260.  
  261. ;----------------------------------------------------------------------------;
  262. ;                                  SetDlg                                    ;
  263. ;                                                                            ;
  264. ; Reads the System Time with GetSysTime, sets up the Dialog Item TIME_TEXT   ;
  265. ; with the resulting string. Then does the same for DATE_TEXT. Then gets the ;
  266. ; other system information with GetSysInfo and sets the appropiate Dialog    ;
  267. ; Items. Note that KEYBSTAT and VIDEOMODE take the hex of the value returned.;
  268. ; Since ES is not guaranteed to be preserved, have to restore it after every ;
  269. ; SetDlgItemInt or Text. A table is used to look up the processor type.      ;
  270. ;----------------------------------------------------------------------------;
  271.  
  272. SetDlg  PROC, hDlg:HWND
  273.  
  274.         INVOKE  SetTime, hDlg
  275.         INVOKE  SetKeyb, hDlg
  276.  
  277.         INVOKE  GetSysInfo
  278.         mov     di, dx
  279.         mov     si, ax
  280.  
  281.         ASSUME  SI:PTR SYSINFO
  282.  
  283.         lea     ax, [si].szWinVer
  284.         INVOKE  SetDlgItemText, hDlg, WINVERSION, di::ax
  285.         lea     ax, [si].szDOSVer
  286.         INVOKE  SetDlgItemText, hDlg, DOSVERSION, di::ax
  287.         lea     ax, [si].szROM
  288.         INVOKE  SetDlgItemText, hDlg, ROMBIOS, di::ax
  289.  
  290.         mov     es, di
  291.         mov     al, es:[si].cFloppy
  292.         INVOKE  SetDlgItemInt, hDlg, FLOPPIES, al, FALSE
  293.  
  294.         mov     es, di
  295.         mov     bl, es:[si].cVidMode
  296.         INVOKE  int2hex, bl, ADDR HexValue
  297.         INVOKE  SetDlgItemText, hDlg, VIDEOMODE, ADDR HexValue
  298.  
  299.         mov     es, di
  300.         .IF es:[si].bCoproc
  301.             mov     ax, OFFSET szCoInst
  302.         .ELSE
  303.             mov     ax, OFFSET szCoNotInst
  304.         .ENDIF
  305.         INVOKE  SetDlgItemText, hDlg, COPROC, ds::ax
  306.         
  307.         mov     es, di
  308.         mov     bl, es:[si].cProcType
  309.         .IF (bl < 5)
  310.             xor     bh, bh
  311.             shl     bx, 1
  312.             mov     ax, ProcTable[bx]
  313.         .ELSE
  314.             mov     ax, OFFSET szError
  315.         .ENDIF
  316.         INVOKE  SetDlgItemText, hDlg, PROCTYPE, ds::ax
  317.  
  318.         ASSUME  SI:NOTHING
  319.  
  320.         ret
  321.         
  322. SetDlg  ENDP
  323.         
  324.  
  325. ;----------------------------------------------------------------------------;
  326. ; int2hex 
  327. ; Converts a WORD into its hexadecimal representation. 
  328. ; Based on Chapter 4 of the MASM Programmer's guide
  329. ;----------------------------------------------------------------------------;
  330.  
  331. int2hex PROC NEAR USES ax bx si, number:WORD, string:NPBYTE
  332.  
  333.     mov     bx, OFFSET hex          ; load table address
  334.     mov     si, string
  335.  
  336.     mov     ax, number              ; load value to convert 
  337.     shr     ax, 12                  ; shift right to get into table index
  338.     and     ax, 0000Fh              ; remove all but least-significant byte
  339.     xlat                            ; translate
  340.     mov     [si], al                ; store as last byte
  341.  
  342.     mov     ax, number              ; load value to convert 
  343.     shr     ax, 8                   ; shift right to get into table index
  344.     and     ax, 0000Fh              ; remove all but least-significant byte
  345.     xlat                            ; translate
  346.     mov     [si+1], al              ; store as third to last byte
  347.  
  348.     mov     ax, number              ; load value to convert 
  349.     shr     ax, 4                   ; shift right to get into table index
  350.     and     ax, 0000Fh              ; remove all but least-significant byte
  351.     xlat                            ; translate
  352.     mov     [si+2], al              ; store as second to last byte
  353.  
  354.     mov     ax, number              ; load value to convert 
  355.     and     ax, 0000Fh              ; remove all but least-significant byte
  356.     xlat                            ; translate
  357.     mov     [si+3], al              ; store as last byte in string
  358.  
  359.     ret
  360.  
  361. int2hex ENDP
  362.  
  363.  
  364. ;----------------------------------------------------------------------------;
  365. ;                                  WndProc                                   ;
  366. ;                                                                            ;
  367. ; Because this is a Dialog Box/Window, we cannot intercept the WM_CREATE     ;
  368. ; message to set up the initial values of the Dialog Box. We have to wait for;
  369. ; the timer or the keyboard status to change to set values. Initialized is a ;
  370. ; flag to determine if the other values need to be set.                      ;
  371. ; If we get a timer message, set the time and date.                          ;
  372. ; If we get a KEYDOWN or KEYUP message, set the Keyboard Status              ;
  373. ; If we get a WININICHANGE, SETFOCUS, or SYSKEYUP, some data could change.   ;
  374. ;       Reset the dialog items                                               ; 
  375. ; A Close Window will get us out.                                            ;
  376. ;----------------------------------------------------------------------------;
  377.  
  378. WndProc         PROC FAR PASCAL, hWnd:HWND, iMessage:WORD, wParam:SWORD,
  379.                  lParam:SDWORD
  380.         ; Windows gives us: the handle of the Window, the Message ID,
  381.         ; and two parameters for the message
  382.  
  383.  
  384.         .IF (iMessage == WM_TIMER)
  385.             .IF Initialized
  386.                 INVOKE  SetTime, hWnd
  387.             .ELSE
  388.                 mov     Initialized, TRUE
  389.                 INVOKE  SetDlg, hWnd
  390.             .ENDIF                  
  391.             
  392.         .ELSEIF (iMessage == WM_KEYDOWN) || (iMessage == WM_KEYUP)
  393.             .IF Initialized
  394.                 INVOKE  SetKeyb, hWnd
  395.             .ELSE
  396.                 mov     Initialized, TRUE
  397.                 INVOKE  SetDlg, hWnd
  398.             .ENDIF                  
  399.             
  400.         .ELSEIF (iMessage == WM_SETFOCUS) || (iMessage == WM_SYSKEYUP)\
  401.             || (iMessage == WM_WININICHANGE)
  402.             INVOKE  SetDlg, hWnd
  403.             jmp doDefault
  404.  
  405.         .ELSEIF (iMessage==WM_DESTROY)
  406.             INVOKE  KillTimer, hWnd, 1
  407.             INVOKE  PostQuitMessage, 0
  408.  
  409.         .ELSE
  410. doDefault:
  411.             INVOKE  DefWindowProc, hWnd, iMessage, wParam,lParam
  412.             jmp doRet
  413.  
  414.         .ENDIF
  415.  
  416.         mov ax, 0
  417.         cwd
  418. doRet:
  419.         ret
  420.  
  421. WndProc         ENDP
  422.  
  423.  
  424.         END  __astart   ; so that the code of the application will
  425.                     ; start with the Windows start-up code
  426.  
  427.  
  428.  
  429.