home *** CD-ROM | disk | FTP | other *** search
/ Programming Tool Box / SIMS_2.iso / code / cdspy / nm_mod.bas < prev    next >
BASIC Source File  |  1995-02-26  |  15KB  |  487 lines

  1. Option Explicit
  2. Option Compare Text
  3. DefInt A-Z
  4. Declare Function LockWindowUpdate Lib "User" (ByVal hwndLock As Integer) As Integer
  5. Declare Function SetSysModalWindow Lib "User" (ByVal hWnd As Integer) As Integer
  6. Declare Function GetFreeSpace Lib "Kernel" (ByVal wFlags) As Long
  7. Declare Function GetWinFlags Lib "Kernel" () As Long
  8. Declare Function GetVersion Lib "Kernel" () As Long
  9. Declare Function GetSystemMetrics Lib "User" (ByVal nIndex As Integer) As Integer
  10. Declare Function GetFreeSystemResources Lib "User" (ByVal fuSysResource As Integer) As Integer
  11. Declare Sub SetWindowPos Lib "User" (ByVal hWnd As Integer, ByVal hWndInsertAfter As Integer, ByVal X As Integer, ByVal Y As Integer, ByVal cx As Integer, ByVal cy As Integer, ByVal wFlags As Integer)
  12. Declare Function GetDeviceCaps Lib "GDI" (ByVal hDC As Integer, ByVal nIndex As Integer) As Integer
  13. Declare Function GetSystemMenu Lib "User" (ByVal hWnd As Integer, ByVal bRevert As Integer) As Integer
  14. Declare Function RemoveMenu Lib "User" (ByVal hMenu As Integer, ByVal nPosition As Integer, ByVal wFlags As Integer) As Integer
  15. Declare Function GetPrivateProfileString Lib "Kernel" (ByVal lpApplicationName$, ByVal lpKeyName$, ByVal lpDefault As String, ByVal lpReturnedString$, ByVal nSize As Integer, ByVal lpFileName As String) As Integer
  16. Declare Sub WritePrivateProfileString Lib "Kernel" (ByVal lpApplicationName$, ByVal lpKeyName$, ByVal lpString$, ByVal lplFileName$)
  17.  
  18. Global Const C_AnzahlBreite = 3
  19. Global Const C_AnzahlHoehe = 7
  20.  
  21. Const WF_STANDARD = &H10
  22. Const WF_ENHANCED = &H20
  23. Const WF_80x87 = &H400
  24. Const SM_DEBUG = 22
  25. Const GFSR_SYSTEMRESOURCES = &H0
  26. Const MF_BYPOSITION = &H400
  27. Const KEY_ESCAPE = &H1B
  28.  
  29.  
  30. Global G_TabName$
  31. Global Const C_Ordner = 1
  32. Global Const C_Dokument = 2
  33. Global Const C_Information = 3
  34.  
  35. ' Kontrolliert die Gⁿltigkeit der Koordinaten eines Formulars
  36. '
  37. Function F_CheckFormSize (F_Source As Form, FrmWidth As Long, FrmHeight As Long) As Integer
  38. Static flg_Aktiv As Integer
  39. If F_Source.WindowState = 1 Then
  40.   F_CheckFormSize = False
  41. Else
  42.   If flg_Aktiv = True Then Exit Function
  43.   flg_Aktiv = True
  44.   
  45.   If F_Source.Width < FrmWidth Then
  46.     F_Source.Width = FrmWidth
  47.   End If
  48.   If F_Source.Height < FrmHeight Then
  49.     F_Source.Height = FrmHeight
  50.   End If
  51.   
  52.   F_CheckFormSize = True
  53.   flg_Aktiv = False
  54. End If
  55. End Function
  56.  
  57. Function F_EntferneNull$ (Text As String)
  58. Text = Trim$(Text)
  59. Do
  60.     If Len(Text$) <= 1 Then Exit Do
  61.     If Left$(Text, 1) = Chr$(0) Then
  62.         Text = Mid$(Text, 2)
  63.     Else
  64.         Exit Do
  65.     End If
  66. Loop
  67. Do
  68.     If Len(Text$) <= 1 Then Exit Do
  69.     If Right$(Text, 1) = Chr$(0) Then
  70.         Text = Mid$(Text, 1, Len(Text) - 1)
  71.     Else
  72.         Exit Do
  73.     End If
  74. Loop
  75.  
  76. F_EntferneNull = Text
  77. End Function
  78.  
  79. Function F_FileExist (ByVal DateiName$)
  80. On Error Resume Next
  81. Dim Datei$
  82. If DateiName$ = "" Then Exit Function
  83. Datei$ = Dir$(DateiName$)
  84. If Trim$(Datei$) = "" Or Asc(DateiName$) = 0 Then
  85.     F_FileExist = False
  86. Else
  87.     F_FileExist = True
  88. End If
  89.  
  90. End Function
  91.  
  92. Function F_GetPrivatIni (ByVal section As String, ByVal Key As String) As String
  93. Dim lplFileName As String
  94. Dim retVal As String, AppName As String, worked As Integer
  95.  
  96. lplFileName$ = App.EXEName + ".INI"
  97.  
  98.     retVal = String$(255, 0)
  99.     worked = GetPrivateProfileString(section, Key, "", retVal, Len(retVal), lplFileName$)
  100.     If worked = 0 Then
  101.         F_GetPrivatIni = ""
  102.     Else
  103.         F_GetPrivatIni = Left(retVal, worked)
  104.     End If
  105. End Function
  106.  
  107. Function F_Test256Color ()
  108.  
  109. Dim Tmp_AnzahlBitP As Integer
  110. Dim Tmp_AnzahlFarben As Integer
  111.  
  112. ' Anzahl Farben
  113. Tmp_AnzahlFarben = GetDeviceCaps(Screen.ActiveForm.hDC, 104)
  114.  
  115. ' Anzahl Bit pro Pixel
  116. Tmp_AnzahlBitP = GetDeviceCaps(Screen.ActiveForm.hDC, 12)
  117. If Tmp_AnzahlBitP = 8 And Tmp_AnzahlFarben = 256 Then
  118.     F_Test256Color = True
  119. Else
  120.     F_Test256Color = False
  121. End If
  122.  
  123. End Function
  124.  
  125. Sub FreezeOff ()
  126. Dim Dummy As Integer
  127. Dummy = LockWindowUpdate(0)
  128. End Sub
  129.  
  130. Sub FreezeOn (ByVal Handle As Integer)
  131. Dim Dummy As Integer
  132. Dummy = LockWindowUpdate(Handle)
  133. End Sub
  134.  
  135. Function HIBYTE (ShortInt As Integer) As Integer
  136.     HIBYTE% = ShortInt% \ 256
  137. End Function
  138.  
  139. Function HIWORD (LongInt As Long) As Integer
  140.     HIWORD% = LongInt& \ 65536
  141. End Function
  142.  
  143. Function LOBYTE (ShortInt As Integer) As Integer
  144.     LOBYTE% = ShortInt% Mod 256
  145. End Function
  146.  
  147. Function LOWORD (LongInt As Long) As Integer
  148.     LOWORD% = LongInt& Mod 65536
  149. End Function
  150.  
  151. Sub P_ChangeFont (F_Source As Form, F_Name As String)
  152. Dim I As Integer
  153.  
  154. For I = 0 To F_Source.Controls.Count - 1
  155.     F_Source.Controls(I).FontName = F_Name
  156. Next I
  157.  
  158. End Sub
  159.  
  160. ' Alle Schriftgr÷ssen der Controls innerhalb des Formulars F_Source
  161. ' werden auf die neue gr÷sse Fontsize angepasst
  162. '
  163. ' F_Source -> Formular
  164. ' Fontsize -> Schriftgr÷sse
  165. '
  166. Sub P_ChangeFontSize (F_Source As Form, FontSize As Single)
  167.  
  168. On Error Resume Next
  169. Dim I As Integer
  170.  
  171. For I = 0 To F_Source.Controls.Count - 1
  172.     F_Source.Controls(I).FontSize = FontSize
  173. Next I
  174.  
  175. End Sub
  176.  
  177. ' Die Feldnamen der Tabelle TableName aus der Datenbank DataBaseName
  178. ' werden in einem Control O_Source angezeigt
  179. '
  180. ' DataBaseName -> Name der Datenbank
  181. ' TableName -> Name der Tabelle oder Name des Queries
  182. ' O_Source -> Name des Objektes (Liste oder Combo-Box)
  183. '
  184. Sub P_ReadFields (ByVal DataBaseName As String, ByVal TableName As String, O_Source As Control)
  185. On Error Resume Next
  186. Dim Db As DataBase
  187. Dim Sn As SnapShot
  188. Dim I As Integer
  189.  
  190. Set Db = OpenDatabase(DataBaseName)
  191. Set Sn = Db.CreateSnapshot(TableName)
  192.  
  193. O_Source.Clear
  194. For I = 0 To Sn.Fields.Count - 1
  195.     O_Source.AddItem Sn.Fields(I).Name
  196. Next I
  197.  
  198. End Sub
  199.  
  200. ' Alle Records des Feldes FieldName aus der Tabelle TableName
  201. ' werden in einem Control O_Source angezeigt
  202. '
  203. ' DataBaseName -> Name der Datenbank
  204. ' TableName -> Name der Tabelle oder Name des Queries
  205. ' FieldName -> Feldname
  206. ' O_Source -> Name des Objektes (Liste oder Combo-Box)
  207. '
  208. Sub P_ReadFieldValue (DataBaseName As String, ByVal TableName As String, ByVal FieldName As String, O_Source As Control)
  209.  
  210. Dim Db As DataBase
  211. Dim Sn As SnapShot
  212.  
  213. Dim I As Integer
  214.  
  215. Set Db = OpenDatabase(DataBaseName)
  216. Set Sn = Db.CreateSnapshot(TableName)
  217.  
  218. O_Source.Clear
  219. Do While Not Sn.EOF
  220.     O_Source.AddItem Format$(Sn.Fields(FieldName))
  221.     Sn.MoveNext
  222. Loop
  223.     
  224. End Sub
  225.  
  226. ' Alle Tabellen der Datenbank DataBaseName werden im
  227. ' Control O_Source angezeigt
  228. '
  229. ' DataBaseName -> Name der Datenbank'
  230. ' O_Source -> Name des Objektes (Liste oder Combo-Box)
  231. '
  232. Sub P_ReadTables (ByVal DataBaseName As String, O_Source As Control)
  233.  
  234. Dim Db As DataBase
  235. Dim TableList As SnapShot
  236.  
  237. Set Db = OpenDatabase(DataBaseName)
  238. Set TableList = Db.ListTables()
  239.  
  240. O_Source.Clear
  241. While TableList.EOF = False
  242.     If TableList!Attributes And &H80000002 Then
  243.     Else
  244.         O_Source.AddItem TableList!Name
  245.     End If
  246.     TableList.MoveNext
  247. Wend
  248.  
  249. End Sub
  250.  
  251. Sub P_RemoveItemsSysMenu (F_Source As Form, Positon As Integer)
  252.     
  253.     Dim HSysMenu As Integer
  254.     Dim Dummy As Integer
  255.     HSysMenu = GetSystemMenu(F_Source.hWnd, 0)
  256.     Dummy = RemoveMenu(HSysMenu, Positon, MF_BYPOSITION)
  257.  
  258. End Sub
  259.  
  260. Sub P_ResizeFormCenter (Source As Form)
  261.  
  262. Source.Left = (Screen.Width - Source.Width) / 2
  263. Source.Top = (Screen.Height - Source.Height) / 2
  264.  
  265. End Sub
  266.  
  267. ' Anpassen eines Control-Arrays O_Source2 an ein ⁿberliegendes Control O_Source1
  268. ' wobei die Ausrichtung vertikal erfolgt.
  269. '
  270. ' F_Source -> Formular
  271. ' O_Source1 -> ⁿberliegendes Control
  272. ' O_Source2 -> Control-Array das ausgerichtet werden muss
  273. ' Anzahl -> Anzahl der Objekte(O_Source2) die angezeigt werden mⁿssen
  274. ' Abstand1 ->  Linker, rechter, oberer und unterer Abstand des auszurichtenden objektes an
  275. ' das Vaterelement
  276. ' Abstand2 -> Zwischenabstand
  277. '
  278. Sub P_ResizeMultiObjectToParents (F_Source As Form, O_Source1 As Control, O_Source2 As Control, Anzahl As Integer, Abstand1 As Integer, Abstand2 As Integer)
  279. Dim I As Integer
  280. Dim II As Integer
  281. Dim Tmp_Hoehe As Integer
  282. Dim Tmp_Breite As Integer
  283. Dim Tmp_Zwischenhoehe As Integer
  284.  
  285.  
  286. For I = 0 To F_Source.Controls.Count - 1
  287.     If O_Source2 = F_Source.Controls(I) Then
  288.         For II = I To F_Source.Controls.Count - 1
  289.             If O_Source2 = F_Source.Controls(II) Then
  290.                 F_Source.Controls(II).Visible = False
  291.             End If
  292.         Next II
  293.         Tmp_Hoehe = O_Source1.Height - (Abstand1 * 2) - ((Anzahl - 1) * Abstand2)
  294.         Tmp_Breite = O_Source1.Width - (Abstand1 * 2)
  295.         Tmp_Zwischenhoehe = Tmp_Hoehe / Anzahl
  296.         For II = Anzahl - 1 To 0 Step -1
  297.             F_Source.Controls(I + II).Top = Abstand1 + (II * Tmp_Zwischenhoehe) + (II * Abstand2)
  298.             F_Source.Controls(I + II).Left = Abstand1
  299.             F_Source.Controls(I + II).Width = Tmp_Breite
  300.             F_Source.Controls(I + II).Height = Tmp_Zwischenhoehe
  301.             F_Source.Controls(I + II).Visible = True
  302.         Next II
  303.         Exit For
  304.     End If
  305. Next I
  306.  
  307. End Sub
  308.  
  309. ' Control wird an einem Formular ausgerichtet
  310. '
  311. ' F_Source -> Formular
  312. ' O_Source -> Objekt das ausgerichtet werden muss
  313. '
  314. Sub P_ResizeObjectToForm (F_Source As Form, O_Source As Control, Abstand)
  315.  
  316. O_Source.Left = Abstand
  317. O_Source.Top = Abstand
  318. O_Source.Width = F_Source.ScaleWidth - (2 * Abstand)
  319. O_Source.Height = F_Source.ScaleHeight - (2 * Abstand)
  320.  
  321. End Sub
  322.  
  323. ' Ein Control wird an einem ⁿberliegenden Control ausgerichtet
  324. '
  325. ' O_OutSource -> ⁿberliegendes Control
  326. ' O_InSource -> Control das ausgerichtet werden muss
  327. ' Abstand -> Abstand des auszurichtenden Controls zum Vaterobjekt
  328. '
  329. Sub P_ResizeObjectToObject (O_OutSource As Control, O_InSource As Control, Abstand As Integer)
  330.  
  331. O_InSource.Left = Abstand
  332. O_InSource.Top = Abstand
  333. O_InSource.Width = O_OutSource.Width - (2 * Abstand)
  334. O_InSource.Height = O_OutSource.Height - (2 * Abstand)
  335.  
  336. End Sub
  337.  
  338. Sub P_SetSysModal (F_Source As Form)
  339.  Dim Dummy As Integer
  340.  Dummy = SetSysModalWindow(F_Source.hWnd)
  341. End Sub
  342.  
  343. Sub P_SetWindowTop (F_Source As Form)
  344.     
  345.     ' Setze das Fenster (F_Source) auf die oberste Position
  346.     ' muss  nach jedem Laden des Fenster neu aufgerufen werden
  347.  
  348.     SetWindowPos F_Source.hWnd, -1, 0, 0, 0, 0, &H10 Or &H40
  349.  
  350. End Sub
  351.  
  352. Sub P_SystemInfo (WVersion As String, FreeMemory As Long, FreeResources As Integer)
  353.  
  354. Dim WinFlags As Long
  355. Dim Mode As String
  356. Dim Version As Long
  357. Dim lKBfree As Long
  358. Dim KBfree As String
  359. Dim SystemMetrics As Integer
  360.     
  361. 'fill the mode label...
  362. Mode = "Windows version "
  363.  
  364. ' Get current Windows configuration
  365. Version = GetVersion()
  366. Mode = Mode + Format(LOBYTE(LOWORD(Version)), "#") + "." + Format(HIBYTE(LOWORD(Version)), "#") + "  -  "
  367. WinFlags = GetWinFlags()
  368. If WinFlags And WF_ENHANCED Then Mode = Mode + "Enhanced Mode" Else Mode = Mode + "Standard Mode"
  369. SystemMetrics = GetSystemMetrics(SM_DEBUG)
  370. If SystemMetrics <> 0 Then Mode = Mode + " (DEBUG)"
  371. WVersion = Mode
  372.  
  373. FreeMemory = GetFreeSpace(0) \ 1024
  374. FreeResources = GetFreeSystemResources(GFSR_SYSTEMRESOURCES)
  375.  
  376. End Sub
  377.  
  378. Sub P_Warte (Sekunden)
  379.  
  380. Dim Temp_Zeit As Double
  381. Temp_Zeit = Timer
  382. Do While Not Temp_Zeit + Sekunden < Timer
  383.     DoEvents
  384. Loop
  385.  
  386. End Sub
  387.  
  388. Sub P_WritePrivatInit (ByVal Sektion$, ByVal Key$, ByVal Result$)
  389. Dim lpApplicationName$
  390. Dim lpKeyName$
  391. Dim lpString$
  392. lpApplicationName$ = Sektion$
  393. lpKeyName$ = Key$
  394. lpString$ = Result$
  395.  
  396. Dim Dummy As Integer
  397. Dim lplFileName As String
  398.  
  399. lplFileName$ = App.EXEName + ".INI"
  400. lpKeyName$ = lpKeyName$ + String$(255 - Len(lpKeyName$), 0)
  401. lpString$ = lpString$ + String$(255 - Len(lpString$), 0)
  402.  
  403. WritePrivateProfileString lpApplicationName$, lpKeyName$, lpString$, lplFileName$
  404.  
  405. End Sub
  406.  
  407. Sub Show3d (Frm As Form)
  408. ' Colors
  409. On Error Resume Next
  410. Const BLACK = &H0&
  411. Const WHITE = &HFFFFFF
  412. Const GRAY = &HC0C0C0
  413. Const DGRAY = &H808080
  414.  
  415. Dim Ct As Control
  416. Dim I As Integer
  417. Dim Tx As Integer
  418. Dim Ty As Integer
  419.  
  420. Tx = Screen.TwipsPerPixelX
  421. Ty = Screen.TwipsPerPixelY
  422. Frm.AutoRedraw = True
  423.  
  424. ' Zeichne Formular
  425. Frm.BackColor = &HC0C0C0
  426. If Frm.BorderStyle = 0 Or Frm.BorderStyle = 1 Or Frm.BorderStyle = 3 Then
  427.     Frm.DrawWidth = 2
  428.     Frm.Line (0, 0)-(Frm.ScaleWidth, Frm.ScaleHeight), DGRAY, B
  429.     Frm.DrawWidth = 1
  430.     Frm.Line (0, 0)-(Frm.ScaleWidth, Frm.ScaleHeight), WHITE, B
  431. End If
  432.  
  433. For I = 0 To Frm.Controls.Count - 1
  434.     Set Ct = Frm.Controls(I)
  435.     If TypeOf Ct Is Shape Then
  436.         Ct.Visible = False
  437.         Frm.DrawWidth = 2
  438.         Frm.Line (Ct.Left - (0 * Tx), Ct.Top - (0 * Ty))-(Ct.Width + (1 * Tx) + Ct.Left, Ct.Top + Ct.Height + (0 * Ty)), DGRAY, B
  439.         Frm.DrawWidth = 1
  440.         Frm.Line (Ct.Left - (1 * Tx), Ct.Top - (1 * Ty))-(Ct.Width + (0 * Tx) + Ct.Left, Ct.Top + Ct.Height - (1 * Ty)), WHITE, B
  441.     End If
  442.     If TypeOf Ct Is PictureBox Then
  443.         Frm.Line (Ct.Left + (1 * Tx), Ct.Top + (1 * Ty))-(Ct.Width + (0 * Tx) + Ct.Left, Ct.Top + Ct.Height + (0 * Ty)), WHITE, B
  444.         Frm.Line (Ct.Left - (1 * Tx), Ct.Top - (1 * Ty))-(Ct.Width + (1 * Tx) + Ct.Left, Ct.Top + Ct.Height + (1 * Ty)), DGRAY, B
  445.         Frm.Line (Ct.Left - (2 * Tx), Ct.Top - (2 * Ty))-(Ct.Width + Ct.Left + (1 * Tx), Ct.Top + Ct.Height + (1 * Ty)), GRAY, B
  446.     End If
  447.     If TypeOf Ct Is Label Then
  448.  
  449.         Frm.FontSize = Ct.FontSize
  450.         Frm.FontName = Ct.FontName
  451.         Frm.FontBold = Ct.FontBold
  452.         Ct.Visible = False
  453.         Frm.CurrentX = Ct.Left + Tx
  454.         Frm.CurrentY = Ct.Top + Ty
  455.         Frm.ForeColor = WHITE
  456.         Frm.Print Ct.Caption
  457.         Frm.CurrentX = Ct.Left
  458.         Frm.CurrentY = Ct.Top
  459.         Frm.ForeColor = BLACK
  460.         Frm.Print Ct.Caption
  461.     End If
  462.     If TypeOf Ct Is TextBox Then
  463.         Frm.Line (Ct.Left + (1 * Tx), Ct.Top + (1 * Ty))-(Ct.Width + (0 * Tx) + Ct.Left, Ct.Top + Ct.Height + (0 * Ty)), WHITE, B
  464.         Frm.Line (Ct.Left - (1 * Tx), Ct.Top - (1 * Ty))-(Ct.Width + (1 * Tx) + Ct.Left, Ct.Top + Ct.Height + (1 * Ty)), DGRAY, B
  465.         Frm.Line (Ct.Left - (2 * Tx), Ct.Top - (2 * Ty))-(Ct.Width + Ct.Left + (1 * Tx), Ct.Top + Ct.Height + (1 * Ty)), GRAY, B
  466.     End If
  467.     If TypeOf Ct Is ListBox Then
  468.         Frm.Line (Ct.Left + (1 * Tx), Ct.Top + (1 * Ty))-(Ct.Width + (0 * Tx) + Ct.Left, Ct.Top + Ct.Height + (0 * Ty)), DGRAY, B
  469.         Frm.Line (Ct.Left - (1 * Tx), Ct.Top - (1 * Ty))-(Ct.Width + (1 * Tx) + Ct.Left, Ct.Top + Ct.Height + (1 * Ty)), WHITE, B
  470.         Frm.Line (Ct.Left - (2 * Tx), Ct.Top - (2 * Ty))-(Ct.Width + Ct.Left + (1 * Tx), Ct.Top + Ct.Height + (1 * Ty)), GRAY, B
  471.     End If
  472.     If TypeOf Ct Is ComboBox Then
  473.         Frm.Line (Ct.Left + (1 * Tx), Ct.Top + (1 * Ty))-(Ct.Width + (0 * Tx) + Ct.Left, Ct.Top + Ct.Height + (0 * Ty)), DGRAY, B
  474.         Frm.Line (Ct.Left - (1 * Tx), Ct.Top - (1 * Ty))-(Ct.Width + (1 * Tx) + Ct.Left, Ct.Top + Ct.Height + (1 * Ty)), WHITE, B
  475.         Frm.Line (Ct.Left - (2 * Tx), Ct.Top - (2 * Ty))-(Ct.Width + Ct.Left + (1 * Tx), Ct.Top + Ct.Height + (1 * Ty)), GRAY, B
  476.     End If
  477.     If TypeOf Ct Is Line Then
  478.         Ct.Visible = False
  479.         Frm.Line (Ct.X1 + (1 * Tx), Ct.Y1 + (1 * Ty))-(Ct.X2 + (1 * Tx), Ct.Y2 + (1 * Ty)), DGRAY
  480.         Frm.Line (Ct.X1 + (0 * Tx), Ct.Y1 + (0 * Ty))-(Ct.X2 + (0 * Tx), Ct.Y2 + (0 * Ty)), WHITE
  481.     End If
  482.  
  483. Next I
  484. Frm.AutoRedraw = False
  485. End Sub
  486.  
  487.