home *** CD-ROM | disk | FTP | other *** search
/ Programming Tool Box / SIMS_2.iso / code / print / pms3 / pmswitch.bas < prev    next >
Encoding:
BASIC Source File  |  1995-02-27  |  3.7 KB  |  126 lines

  1. DefSng A-Z
  2.  
  3. 'Define Ini File Constants
  4. Global Continue As Integer
  5. Global Const IniFileName = "win.ini"
  6. Global Section As String
  7. Global KeyName As String
  8. Global nDefault As Integer
  9. Global DefaultStr As String
  10. Global ReturnStr As String
  11. Global Numeric As Integer
  12. Global PMStatus As String
  13.  
  14.  
  15. ' WININI File Declarations **********************************
  16. Declare Function GetProfileString Lib "Kernel" (ByVal lpAppName As String, ByVal lpKeyName As String, ByVal lpDefault As String, ByVal lpReturnedString As String, ByVal nSize As Integer) As Integer
  17. Declare Function WriteProfileString Lib "Kernel" (ByVal lpAppName As String, ByVal lpKeyName As String, ByVal lpString As String) As Integer
  18.  
  19.  
  20. ' Define Windows Message Handler Constants and Structures
  21. Type POINTAPI
  22.   X As Integer
  23.   Y As Integer
  24. End Type
  25.  
  26. Type MSG
  27.   hWnd As Integer
  28.   Message As Integer
  29.   wParam As Integer
  30.   lParam As Long
  31.   Time As Long
  32.   Pt As POINTAPI
  33. End Type
  34. Global SysMessage As MSG
  35.  
  36. ' Windows Message Handler Declares
  37. Declare Function GetMessage% Lib "USER" (lpMsg As MSG, ByVal hWnd%, ByVal wMsgFilterMin%, ByVal wMsgFilterMax%)
  38. Declare Function TranslateMessage% Lib "USER" (lpMsg As MSG)
  39. Declare Function DispatchMessage& Lib "USER" (lpMsg As MSG)
  40.  
  41.  
  42. ' Define System Menu Constants
  43. Global Const MF_SEPARATOR = &H800
  44. Global Const MF_STRING = &H0
  45. Global Const WM_SYSCOMMAND = &H112
  46.  
  47. 'System Menu Declares
  48. Declare Function AppendMenu% Lib "USER" (ByVal hMenu%, ByVal wFlags%, ByVal wIDNewItem%, ByVal lpNewItem As Any)
  49. Declare Function GetSystemMenu% Lib "USER" (ByVal hWnd%, ByVal bRevert%)
  50.  
  51. ' Routine to manually handle messages from Windows
  52. ' Program remains in loop until closed, but permits
  53. ' gives control back to Windows with each loop
  54. '
  55. Sub ProcessWinMessage ()
  56.  
  57.     Do While GetMessage%(SysMessage, 0, 0, 0)
  58.  
  59.         'Gets message from Windows
  60.         Result% = TranslateMessage%(SysMessage)
  61.  
  62.         ' Process if message is from the System Menu
  63.         If SysMessage.Message = WM_SYSCOMMAND Then
  64.             
  65.             Select Case SysMessage.wParam
  66.                 Case 1  'User clicked About PMSwitch
  67.                     PMSAbout.Show 1
  68.  
  69.                 Case -4000  'User clicked close
  70.                     End
  71.             End Select
  72.         End If
  73.  
  74.         ' Dispatch any message back to Windows
  75.         ' Note that with DispatchMessage, no DoEvents is needed
  76.         Ret& = DispatchMessage&(SysMessage)
  77.  
  78.     Loop
  79.  
  80.  
  81. End Sub
  82.  
  83. Sub ReadWinIni (Section As String, KeyName As String, DefaultStr As String, ReturnStr As String, nDefault As Integer)
  84. ' Read data from Win.Ini
  85.  
  86.     Dim RetStr As String * 255 'Create an empty string to be filled
  87.     nSize% = 255
  88.     lenRetString% = GetProfileString(Section, KeyName, DefaultStr, RetStr$, nSize%)
  89.     ReturnStr = Left$(RetStr$, lenRetString%)
  90.     
  91.     ' Set PMStatus based on current status of Print Manager in Win.Ini
  92.     If ReturnStr = "yes" Or ReturnStr = "Yes" Then
  93.         PMStatus = "yes"
  94.     Else
  95.         PMStatus = "no"
  96.     End If
  97.  
  98. End Sub
  99.  
  100. Sub SaveWinIni (Section As String, KeyName As String, PMStatus As String)
  101.     ' Update WinIni file
  102.         
  103.     ResultCode% = WriteProfileString(Section, KeyName, PMStatus)
  104.     If ResultCode% = 0 Then
  105.         MsgBox "Error updating INI file!", 16, "ERROR!"
  106.     End If
  107.  
  108. End Sub
  109.  
  110. Sub SysMenuAdd ()
  111. ' Add About PMSwitch... item to System Menu
  112.     
  113.     hMenu% = GetSystemMenu%(PMSwitch.hWnd, False)
  114.  
  115.     Result% = AppendMenu%(hMenu%, MF_SEPARATOR, 0, "")  'Add separator bar
  116.     Result% = AppendMenu%(hMenu%, MF_STRING, 1, "&About PMSwitch...")
  117.     
  118.  
  119. End Sub
  120.  
  121. Sub TurnPMOff (Section As String, KeyName As String, PMStatus As String)
  122.     PMStatus = "no"
  123.     SaveWinIni Section, KeyName, PMStatus
  124. End Sub
  125.  
  126.