home *** CD-ROM | disk | FTP | other *** search
Wrap
Option Explicit '**************************************************** '* COMMON01.BAS Version 1.1 Date: 4/30/94 * '* DPM Computer Solutions * '* 8430-D Summerdale Road San Diego CA 92126-5415 * '* InterNet: DPMCS@HIGH-COUNTRY.COM * '* Compuserve: 74227,1557 * '**************************************************** Declare Function WritePrivateProfileString Lib "Kernel" (ByVal AppName As String, ByVal KeyName As String, ByVal NewString As String, ByVal FileName As String) As Integer Declare Function GetPrivateProfilestring Lib "Kernel" (ByVal AppName As String, ByVal KeyName As String, ByVal default As String, ByVal ReturnedString As String, ByVal MAXSIZE As Integer, ByVal FileName As String) As Integer Declare Function GetKeyState Lib "User" (ByVal NVirtKey%) As Integer Declare Function FindWindow Lib "User" (ByVal lpClassName As Any, ByVal lpWindowName As Any) As Integer Declare Sub ShowWindow Lib "User" (ByVal hWnd As Integer, ByVal nCmdShow As Integer) Declare Sub SFocus Lib "User" Alias "SetFocus" (ByVal hWnd As Integer) 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) Global hWnd As Integer Const SWP_NOMOVE = 2 Const SWP_NOSIZE = 1 Const HWND_TOPMOST = -1 Const HWND_NOTOPMOST = -2 '******************************************************* '* Procedure Name: AppRunning * '*-----------------------------------------------------* '* Created: 2/8/94 By: MSDN * '* Modified: By: * '*=====================================================* '*Checks to see if the current application is already * '*running. To use just call the sub. If the application* '*is already running, it will end the current * '*application. * '* * '******************************************************* Sub AppRunning () Dim sMsg As String If App.PrevInstance Then sMsg = App.EXEName & " already running! " MsgBox sMsg, 4112 End End If End Sub '******************************************************* '* Procedure Name: CenterForm * '*-----------------------------------------------------* '* Created: 2/10/94 By: VB Programmers Journal * '* Modified: 4/24/94 By: David McCarter * '*=====================================================* '*This code will center a form in the center of the * '*screen. To use it, just call the sub and pass it the * '*form name [Call CenterForm main] * '* * '* * '******************************************************* Sub CenterForm (frmIN As Form) Dim iTop, iLeft As Integer If frmIN.WindowState <> 0 Then Exit Sub iTop = (Screen.Height - frmIN.Height) \ 2 iLeft = (Screen.Width - frmIN.Width) \ 2 If iTop And iLeft Then frmIN.Move iLeft, iTop End If End Sub '******************************************************* '* * '* Procedure Name:CenterMDIChild * '* * '* Created:2/10/94 By:VB Prog Journl * '* Modified: By: * '* * '* Comments: * '* * '******************************************************* '******************************************************* '* Procedure Name: CenterMDIChild * '*-----------------------------------------------------* '* Created: 2/10/94 By: VB Programmers Journal * '* Modified: 3/24/94 By: D. McCarter * '*=====================================================* '* Centers a child form within a parent MDI form. To * '* use, call the sub and pass it the parent form name * '* and the child form name [CenterMDIChild form1 form2]* '* * '* * '******************************************************* Sub CenterMDIChild (frmParent As Form, frmChild As Form) Dim iTop, iLeft As Integer If frmParent.WindowState <> 0 Or frmChild.WindowState <> 0 Then Exit Sub iTop = (frmParent.ScaleHeight - frmChild.Height) \ 2 iLeft = (frmParent.ScaleWidth - frmChild.Width) \ 2 If iTop And iLeft Then frmChild.Move iLeft, iTop End If End Sub '******************************************************* '* Procedure Name: CheckUnique * '*-----------------------------------------------------* '* Created: 4/18/94 By: Terry Brooking * '* Modified: By: * '*=====================================================* '*Checks for previous instance of application, If found* '*ensures it's restored from Icon and Focused on! It is* '*up to main routine to end application if required. * '* * '* * '******************************************************* Function CheckUnique (F As Form) As Integer 'Check for previous instance of application. If found, ensures 'is restored from Icon and Focused on! It is up to Main routine 'to end application if required. Dim x As Integer Dim Title As String CheckUnique = True If App.PrevInstance Then 'MsgBox "Prev Instance found!" Title = F.Caption F.Caption = Title & " - New" 'This is necessary as you may find yourself! hWnd = FindWindow(0&, Title) F.Caption = Title 'Restore caption DoEvents If hWnd Then 'MsgBox "Handle found!" ShowWindow hWnd, 1 'Restores from Minimsed if necessary DoEvents SFocus hWnd 'Sets focus DoEvents CheckUnique = False End If End If End Function '******************************************************* '* Procedure Name: CutCopyPaste * '*-----------------------------------------------------* '* Created: By: VB Help File * '* Modified: By: * '*=====================================================* '*This procedure puts all the cut,copy paste commands * '*in one place. To use, just call the sub and pass it * '*your choice- 0=Cut, 1=Copy, 2=Paste, 3=Delete, * '*[Call CutCopyPaste 2] * '* * '******************************************************* Sub CutCopyPaste (iChoice As Integer) ' ActiveForm refers to the active form in the MDI form. If TypeOf Screen.ActiveControl Is TextBox Then Select Case iChoice Case 0 ' Cut. ' Copy selected text to Clipboard. Clipboard.SetText Screen.ActiveControl.SelText ' Delete selected text. Screen.ActiveControl.SelText = "" Case 1 ' Copy. ' Copy selected text to Clipboard. Clipboard.SetText Screen.ActiveControl.SelText Case 2 ' Paste. ' Put Clipboard text in text box. Screen.ActiveControl.SelText = Clipboard.GetText() Case 3 ' Delete. ' Delete selected text. Screen.ActiveControl.SelText = "" End Select End If End Sub '******************************************************* '* Procedure Name: GetAppPath * '*-----------------------------------------------------* '* Created: 3/24/94 By: David McCarter * '* Modified: By: * '*=====================================================* '*Returns the application path with a trailing \. * '*To use, call the function [SomeString=GetAppPath()] * '* * '* * '* * '******************************************************* Function GetAPPPath () As String Dim sTemp As String sTemp = App.Path If Right$(sTemp, 1) <> "\" Then sTemp = sTemp + "\" GetAPPPath = sTemp End Function '******************************************************* '* Procedure Name: CheckUnique * '*-----------------------------------------------------* '* Created: 4/18/94 By: KeepOnTop * '* Modified: By: * '*=====================================================* '*Keep form on top. Note that this is switched off if * '*form is minimised, so place in resize event as well. * '* * '* * '* * '******************************************************* Sub KeepOnTop (F As Form) 'Keep form on top. Note that this is switched off if form is 'minimised, so place in resize event as well. Const wFlags = SWP_NOMOVE Or SWP_NOSIZE SetWindowPos F.hWnd, HWND_TOPMOST, 0, 0, 0, 0, wFlags 'Window will stay on top 'To undo call again with HWND_NOTOPMOST DoEvents End Sub '******************************************************* '* Procedure Name: ReadINI * '*-----------------------------------------------------* '* Created: By: Daniel Bowen * '* Modified: 3/24/94 By: David McCarter * '*=====================================================* '*Returns a string from an INI file. To use, call the * '*functions and pass it the AppName, KeyName and INI * '*File Name, [sReg=ReadINI(App1,Key1,INIFile)]. If you * '*need the returned value to be a integer then use the * '*val command. * '******************************************************* Function ReadINI (AppName, KeyName, FileName As String) As String Dim sRet As String sRet = String(255, Chr(0)) ReadINI = Left(sRet, GetPrivateProfilestring(AppName, ByVal KeyName, "", sRet, Len(sRet), FileName)) End Function '******************************************************* '* Procedure Name: SelectText * '*-----------------------------------------------------* '* Created: 2/14/94 By: David McCarter * '* Modified: By: * '*=====================================================* '*Selects all the text in a text box. Call it when the * '*text box get focus, [SelectText Text1.text] * '* * '* * '* * '******************************************************* Sub SelectText (ctrIn As Control) ctrIn.SelStart = 0 ctrIn.SelLength = Len(ctrIn.Text) End Sub '******************************************************* '* Procedure Name: WriteINI * '*-----------------------------------------------------* '* Created: 2/10/94 By: David McCarter * '* Modified: By: * '*=====================================================* '*Writes a string to an INI file. To use, call the * '*function and pass it the AppName, KeyName, the New * '*String and the INI File Name, * '*[R=WriteINI(App1,Key1,sReg,INIFile)]. Returns a 1 if * '*there were no errors and a 0 if there were errors. * '******************************************************* Function WriteINI (AppName, KeyName, NewString, FileName As String) As Integer WriteINI = WritePrivateProfileString(AppName, KeyName, NewString, FileName) End Function