Option Explicit
Dim File As File 'Файл с программой
Dim fso As New FileSystemObject 'Подключение библиотеки
Dim sAppPath As String 'Путь каталога к программе
'V Создание DSN____________________________________________________________________________________________________________________________
'Объявление констант
Private Const ODBC_ADD_DSN = 1 ' Добавляем источник данных
Private Const ODBC_CONFIG_DSN = 2 ' Настраиваем источник данных
Private Const ODBC_REMOVE_DSN = 3 ' Удаляем источник данных
Private Const vbAPINull As Long = 0 ' NULL указатель
'Объявление функции
#If Win32 Then
Private Declare Function SQLConfigDataSource Lib "ODBCCP32.DLL" _
(ByVal hwndParent As Long, ByVal fRequest As Long, _
ByVal lpszDriver As String, ByVal lpszAttributes As String) _
As Long
#Else
Private Declare Function SQLConfigDataSource Lib "ODBCINST.DLL" _
(ByVal hwndParent As Integer, ByVal fRequest As Integer, ByVal _
lpszDriver As String, ByVal lpszAttributes As String) As Integer
#End If
'A Создание DSN____________________________________________________________________________________________________________________________
'V Запрет закрытия формы нажатием на крестик-----------------------------------------------------------------------------------------------
Private Declare Function DeleteMenu Lib "user32" (ByVal hMenu As Long, ByVal nPosition As Long, ByVal wFlags As Long) As Long
Private Declare Function GetSystemMenu Lib "user32" (ByVal hWnd As Long, ByVal bRevert As Long) As Long
Private Const MF_BYPOSITION = &H400&
'A Запрет закрытия формы нажатием на крестик-----------------------------------------------------------------------------------------------
Private Sub Command1_Click()
On Error GoTo Er
Me.Visible = False
sAppPath = App.Path 'Определение местонахождения файлов с программой
If Right$(sAppPath, 1) <> "\" Then sAppPath = sAppPath & "\" 'Проверка на местонахождение на локальном диске
'V Создание DSN подключения________________________________________________________________________________________________________________________________________________________________________________________
If MsgBoxEx("Установить " & Chr(34) & "DSN" & Chr(34) & " подключение к " & Chr(34) & "SQL" & Chr(34) & " серверу?", vbYesNo, "Продолжение установки...", ImageList1.ListImages(1).Picture) = vbYes Then Call DSN
'A Создание DSN подключения________________________________________________________________________________________________________________________________________________________________________________________
'V Запуск установки DLL.bat________________________________________________________________________________________________________________________________________________________________________________________
Call RunDLL
'A Запуск установки DLL.bat________________________________________________________________________________________________________________________________________________________________________________________
'V Запуск установки "Autodesk Express Viewer"______________________________________________________________________________________________________________________________________________________________________
Call RunAutodeskViewer
'A Запуск установки "Autodesk Express Viewer"______________________________________________________________________________________________________________________________________________________________________
Unload Me
Exit Sub
Er:
MsgBox "Error " & Err.Number & ": " & Err.Description, vbOKOnly + vbCritical, "Error"
End Sub
Private Sub Command2_Click()
On Error GoTo Er
Unload Me
Exit Sub
Er:
MsgBox "Error " & Err.Number & ": " & Err.Description, vbOKOnly + vbCritical, "Error"
End Sub
Private Sub DSN()
On Error GoTo Er
'V Создание подключения______________________________________________________________________________________________________________________________________________________________________________________
#If Win32 Then
Dim intRet As Long
#Else
Dim intRet As Integer
#End If
Dim strDriver As String
Dim strAttributes As String
'Устанавливаем драйвер на SQL Server.
strDriver = "SQL Server"
'Устанавливаем атрибуты, разделённые нулями (null).
strAttributes = "SERVER=" & "69SQL" & Chr$(0)
strAttributes = strAttributes & "DESCRIPTION=" & "Constructor" & " DSN" & Chr$(0)
strAttributes = strAttributes & "DSN=" & "Constructor" & Chr$(0)
strAttributes = strAttributes & "DATABASE=" & "Constructor" & Chr$(0)
'V Удаление DSN_________________________________________________________________________________________________________________________________________________________________________________________
'Чтобы показать диалог, используем Form1.Hwnd вместо vbAPINull.
intRet = SQLConfigDataSource(vbAPINull, ODBC_REMOVE_DSN, _
strDriver, strAttributes)
If intRet Then
MsgBoxEx "Существующее " & Chr(34) & "DSN" & Chr(34) & " подключение " & Chr(34) & "Constructor" & Chr(34) & " удалено!" & vbCrLf & Chr(34) & "DSN" & Chr(34) & " подключение " & Chr(34) & "Constructor" & Chr(34) & " будет создано заново.", vbInformation, "Результат операции", ImageList1.ListImages(1).Picture
End If
intRet = Empty
'V Установка DSN________________________________________________________________________________________________________________________________________________________________________________________
'Чтобы показать диалог, используем Form1.Hwnd вместо vbAPINull.
intRet = SQLConfigDataSource(vbAPINull, ODBC_ADD_DSN, _
strDriver, strAttributes)
If intRet Then
MsgBoxEx Chr(34) & "DSN" & Chr(34) & " подключение " & Chr(34) & "Constructor" & Chr(34) & " создано!", vbInformation, "Результат операции", ImageList1.ListImages(1).Picture
Else
MsgBoxEx "DSN подключение " & Chr(34) & "Constructor" & Chr(34) & " не создано!", vbExclamation, "Результат операции", ImageList1.ListImages(1).Picture
End If
'A Создание подключения_____________________________________________________________________________________________________________________________________________________________________________________
Exit Sub
Er:
MsgBox "Error " & Err.Number & ": " & Err.Description, vbOKOnly + vbCritical, "Error"
End Sub
Private Sub RunDLL()
On Error GoTo Er
'V Запуск установки "Autodesk Express Viewer"_______________________________________________________________________________________________________________________________________________________________
On Error Resume Next 'Отключаем режим проверки ошибок
Set File = fso.GetFile(sAppPath & "\DLL.bat") 'Путь к файлу
If Err.Number > 0 Then
MsgBoxEx "Не найден файл с программой!", , "Ошибка установки программы", ImageList1.ListImages(3).Picture
Set File = Nothing
Err.Clear
On Error GoTo Er 'Возвращаем режим проверки ошибок
Exit Sub
End If
On Error GoTo Er
If MsgBoxEx("Необходимо внести изменения в реестр для корректной работы программы.", vbYesNo, "Продолжение установки...", ImageList1.ListImages(3).Picture) = vbYes Then Call Shell(File, vbMinimizedNoFocus) 'Запуск программы
Set File = Nothing
'A Запуск установки "Autodesk Express Viewer"_______________________________________________________________________________________________________________________________________________________________
Exit Sub
Er:
MsgBox "Error " & Err.Number & ": " & Err.Description, vbOKOnly + vbCritical, "Error"
End Sub
Private Sub RunAutodeskViewer()
On Error GoTo Er
'V Запуск установки "Autodesk Express Viewer"_______________________________________________________________________________________________________________________________________________________________
On Error Resume Next 'Отключаем режим проверки ошибок
Set File = fso.GetFile(sAppPath & "\ExpressViewerSetup.exe") 'Путь к файлу
If Err.Number > 0 Then
MsgBoxEx "Не найден файл с программой!", , "Ошибка установки программы", ImageList1.ListImages(2).Picture
Set File = Nothing
Err.Clear
On Error GoTo Er 'Возвращаем режим проверки ошибок
Exit Sub
End If
On Error GoTo Er
If MsgBoxEx("Установить " & Chr(34) & "Autodesk Express Viewer" & Chr(34) & " для просмотра эскизов КОИ?", vbYesNo, "Продолжение установки...", ImageList1.ListImages(2).Picture) = vbYes Then Call Shell(File, vbNormalFocus) 'Запуск программы
Set File = Nothing
'A Запуск установки "Autodesk Express Viewer"_______________________________________________________________________________________________________________________________________________________________
Exit Sub
Er:
MsgBox "Error " & Err.Number & ": " & Err.Description, vbOKOnly + vbCritical, "Error"
End Sub
Private Sub DelComponents(n As Byte)
On Error GoTo Er
Dim i As Byte
Dim s As String
Dim Flag As Boolean
If n = Empty Then n = 1
sAppPath = App.Path 'Определение местонахождения файлов с программой
If Right$(sAppPath, 1) <> "\" Then sAppPath = sAppPath & "\" 'Проверка на местонахождение на локальном диске
For i = n To 3
Flag = Empty
s = Empty
If i = 1 Then s = "ExpressViewerSetup.exe"
If i = 2 Then s = "DLL.bat"
If i = 3 Then s = App.Title & ".ini"
'V Запуск установки "Autodesk Express Viewer"_______________________________________________________________________________________________________________________________________________________________
On Error Resume Next 'Отключаем режим проверки ошибок
Set File = fso.GetFile(sAppPath & "\" & s) 'Путь к файлу
If Err.Number > 0 Then
Set File = Nothing
Err.Clear
On Error GoTo Er 'Возвращаем режим проверки ошибок
Flag = True
End If
If Flag = False Then
'V Удаление дистрибутива "Autodesk Express Viewer"_________________________________________________________________________________________________________________________________________________________________
SetAttr (File), vbNormal 'Снятие атрибута "Только чтение"
File.Delete
Set File = Nothing
If Err.Number > 0 Then
MsgBoxEx "Необходимо продолжить установку программы" & vbCrLf & Chr(34) & s & Chr(34) & "." & vbCrLf & "Нажмите ОК после завершения установки.", vbInformation + vbOKOnly, "Ждите...", ImageList1.ListImages(3).Picture
Err.Clear
On Error GoTo Er 'Возвращаем режим проверки ошибок
Call DelComponents(i)
End If
'A Удаление дистрибутива "Autodesk Express Viewer"_________________________________________________________________________________________________________________________________________________________________
End If
Next
Exit Sub
Er:
MsgBox "Error " & Err.Number & ": " & Err.Description, vbOKOnly + vbCritical, "Error"
End Sub
Private Sub Form_Load()
On Error GoTo Er
'V Чтение настроек формы*****************************************************************************************************************************************************
Dim sAppPath As String
sAppPath = App.Path 'Определение местонахождения файлов с программой
If Right$(sAppPath, 1) <> "\" Then sAppPath = sAppPath & "\" 'Проверка на местонахождение на локальном диске
sAppPath = sAppPath & App.Title & ".ini"
Me.Left = ReadFromINI(sAppPath, Me.Name, "Left", CStr(Me.Left))
Me.Top = ReadFromINI(sAppPath, Me.Name, "Top", CStr(Me.Top))
'A Чтение настроек формы*****************************************************************************************************************************************************
'V Запрет закрытия формы нажатием на крестик-----------------------------------------------------------------------------------------------
Call RemoveMenus
'A Запрет закрытия формы нажатием на крестик-----------------------------------------------------------------------------------------------
Exit Sub
Er:
MsgBox "Error " & Err.Number & ": " & Err.Description, vbOKOnly + vbCritical, "Error"
End Sub
Private Sub RemoveMenus()
On Error GoTo Er
'V Запрет закрытия формы нажатием на крестик-----------------------------------------------------------------------------------------------
Dim hMenu As Long
' Получаем дескриптор системного меню формы.
hMenu = GetSystemMenu(hWnd, False)
DeleteMenu hMenu, 6, MF_BYPOSITION
'A Запрет закрытия формы нажатием на крестик-----------------------------------------------------------------------------------------------
Exit Sub
Er:
MsgBox "Error " & Err.Number & ": " & Err.Description, vbOKOnly + vbCritical, "Error"
End Sub
Private Sub Form_Unload(Cancel As Integer)
On Error GoTo Er
'V Сохранение настроек формы*****************************************************************************************************************************************************
Dim sAppPath As String
sAppPath = App.Path 'Определение местонахождения файлов с программой
If Right$(sAppPath, 1) <> "\" Then sAppPath = sAppPath & "\" 'Проверка на местонахождение на локальном диске
sAppPath = sAppPath & App.Title & ".ini"
WritePrivateProfileString Me.Name, "Left", CStr(Me.Left), sAppPath
WritePrivateProfileString Me.Name, "Top", CStr(Me.Top), sAppPath
'A Сохранение настроек формы*****************************************************************************************************************************************************
'V Удаление дистрибутива___________________________________________________________________________________________________________________________________________________________________________________________
Call DelComponents(Empty)
'A Удаление дистрибутива___________________________________________________________________________________________________________________________________________________________________________________________
MsgBoxEx "Установка дополнительных компонентов завершена.", vbInformation + vbOKOnly, "Ход установки", ImageList1.ListImages(3).Picture
Exit Sub
Er:
MsgBox "Error " & Err.Number & ": " & Err.Description, vbOKOnly + vbCritical, "Error"
End Sub
Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
On Error GoTo Er
If KeyCode = 112 Then frmAbout.Show vbModal
If KeyCode = 27 Then Unload Me
Exit Sub
Er:
MsgBox "Error " & Err.Number & ": " & Err.Description, vbOKOnly + vbCritical, "Error"
End Sub
Private Sub Image1_Click()
On Error GoTo Er
Call Form_KeyDown(112, 0)
Exit Sub
Er:
MsgBox "Error " & Err.Number & ": " & Err.Description, vbOKOnly + vbCritical, "Error"
End Sub
Private Sub Command1_KeyDown(KeyCode As Integer, Shift As Integer)
On Error GoTo Er
Call Form_KeyDown(KeyCode, Shift)
Exit Sub
Er:
MsgBox "Error " & Err.Number & ": " & Err.Description, vbOKOnly + vbCritical, "Error"
End Sub
Private Sub Command2_KeyDown(KeyCode As Integer, Shift As Integer)
On Error GoTo Er
Call Form_KeyDown(KeyCode, Shift)
Exit Sub
Er:
MsgBox "Error " & Err.Number & ": " & Err.Description, vbOKOnly + vbCritical, "Error"
End Sub
Private Sub Command3_KeyDown(KeyCode As Integer, Shift As Integer)
On Error GoTo Er
Call Form_KeyDown(KeyCode, Shift)
Exit Sub
Er:
MsgBox "Error " & Err.Number & ": " & Err.Description, vbOKOnly + vbCritical, "Error"
End Sub
Private Sub Command3_Click()
On Error GoTo Er
Call Form_KeyDown(112, 0)
Exit Sub
Er:
MsgBox "Error " & Err.Number & ": " & Err.Description, vbOKOnly + vbCritical, "Error"
End Sub
Option Explicit
Private Declare Function SetWindowsHookEx Lib "user32" Alias "SetWindowsHookExA" (ByVal idHook As Long, ByVal lpfn As Long, ByVal hmod As Long, ByVal dwThreadId As Long) As Long
Private Declare Function CallNextHookEx Lib "user32" (ByVal hHook As Long, ByVal nCode As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
Private Declare Function UnhookWindowsHookEx Lib "user32" (ByVal hHook As Long) As Long
Private Declare Function GetClassName Lib "user32" Alias "GetClassNameA" (ByVal hWnd As Long, ByVal lpClassName As String, ByVal nMaxCount As Long) As Long
Private Declare Function GetCurrentThreadId Lib "kernel32" () As Long
Private Declare Function GetWindowRect Lib "user32" (ByVal hWnd As Long, lpRect As RECT) As Long
Private Declare Function SetWindowPos Lib "user32" (ByVal hWnd As Long, ByVal hWndInsertAfter As Long, ByVal x As Long, ByVal y As Long, ByVal cx As Long, ByVal cy As Long, ByVal wFlags As Long) As Long
Private Declare Function GetParent Lib "user32" (ByVal hWnd As Long) As Long
Private Declare Function FindWindowEx Lib "user32" Alias "FindWindowExA" (ByVal ParenthWnd As Long, ByVal ChildhWnd As Long, ByVal ClassName As String, ByVal Caption As String) As Long
Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hWnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
Private Const WH_CBT As Long = 5
Private Const HCBT_ACTIVATE As Long = 5
Private Const HWND_TOP As Long = 0
Private Const SWP_NOSIZE As Long = &H1
Private Const SWP_NOZORDER As Long = &H4
Private Const SWP_NOACTIVATE As Long = &H10
Private Const STM_SETICON As Long = &H170
Private Const SWVB_CAPTION_DEFAULT As String = "SWVB_DEFAULT_TO_APP_TITLE"
Private Type RECT
Left As Long
Top As Long
Right As Long
Bottom As Long
End Type
Private m_Hook As Long
Private m_hIcon As Long
'(((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((
Public Function MsgBoxEx(ByVal Prompt As String, Optional ByVal Buttons As VbMsgBoxStyle = vbOKOnly, _
Optional ByVal Title As String = SWVB_CAPTION_DEFAULT, _
Optional ByVal Icon As Long = 0&) As VbMsgBoxResult
Dim hInst As Long
Dim threadID As Long
Dim wndRect As RECT
hInst = App.hInstance
threadID = GetCurrentThreadId()
m_Hook = SetWindowsHookEx(WH_CBT, AddressOf MsgBoxHook, hInst, threadID)
m_hIcon = Icon
If Title = SWVB_CAPTION_DEFAULT Then
Title = App.Title
End If
If m_hIcon <> 0& Then
Buttons = Buttons Or vbInformation
End If
MsgBoxEx = MsgBox(Prompt, Buttons, Title)
End Function
'(((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((
Private Function MsgBoxHook(ByVal nCode As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
Dim height As Long
Dim width As Long
Dim nSize As Long
Dim wndRect As RECT
Dim sBuffer As String
Dim fWidth As Long
Dim fHeight As Long
Dim x As Long
Dim y As Long
Dim hIconWnd As Long
MsgBoxHook = CallNextHookEx(m_Hook, nCode, wParam, lParam)
If nCode = HCBT_ACTIVATE Then
sBuffer = Space$(32)
nSize = GetClassName(wParam, sBuffer, 32)
Call GetWindowRect(wParam, wndRect)
On Error GoTo errorTrap
height = (wndRect.Bottom - wndRect.Top) / 2
width = (wndRect.Right - wndRect.Left) / 2
Call GetWindowRect(GetParent(wParam), wndRect)
On Error GoTo errorTrap
fHeight = wndRect.Top + (wndRect.Bottom - wndRect.Top) / 2
fWidth = wndRect.Left + (wndRect.Right - wndRect.Left) / 2
x = fWidth - width
y = fHeight - height
SetWindowPos wParam, HWND_TOP, x, y, 0, 0, SWP_NOSIZE + SWP_NOZORDER + SWP_NOACTIVATE
If m_hIcon <> 0& Then
hIconWnd = FindWindowEx(wParam, 0&, "Static", vbNullString)
Call SendMessage(hIconWnd, STM_SETICON, m_hIcon, ByVal 0&)
End If
errorTrap:
UnhookWindowsHookEx m_Hook
End If
End Function
Option Explicit
Public Declare Function WritePrivateProfileString Lib "kernel32" Alias "WritePrivateProfileStringA" _
(ByVal lpApplicationName As String, _
ByVal lpKeyName As Any, _
ByVal lpString As Any, _
ByVal lpFileName As String) As Long
Public Declare Function GetPrivateProfileString Lib "kernel32" Alias "GetPrivateProfileStringA" _
(ByVal lpApplicationName As String, _
ByVal lpKeyName As Any, _
ByVal lpDefault As String, _
ByVal lpReturnedString As String, _
ByVal nSize As Long, _
ByVal lpFileName As String) As Long
Public Function ReadFromINI _
(ByVal sINIFile As String, _
ByVal sSection As String, _
ByVal sKey As String, _
Optional ByVal sDefault As String = vbNullString) As String
Dim rc&, sData$
sData$ = String$(128, Chr$(0))
If GetPrivateProfileString(sSection, sKey, sDefault, sData$, Len(sData$), sINIFile) > 0 Then
ReadFromINI = Left$(sData, InStr(sData$, Chr$(0)) - 1)
Else
ReadFromINI = sDefault
End If
End Function
'V Чтение настроек формы*****************************************************************************************************************************************************
Dim sAppPath As String
sAppPath = App.Path 'Определение местонахождения файлов с программой
If Right$(sAppPath, 1) <> "\" Then sAppPath = sAppPath & "\" 'Проверка на местонахождение на локальном диске
sAppPath = sAppPath & App.Title & ".ini"
Me.Left = ReadFromINI(sAppPath, Me.Name, "Left", CStr(Me.Left))
Me.Top = ReadFromINI(sAppPath, Me.Name, "Top", CStr(Me.Top))
Me.Width = ReadFromINI(sAppPath, Me.Name, "Width", CStr(Me.Width))
Me.Height = ReadFromINI(sAppPath, Me.Name, "Height", CStr(Me.Height))
Me.WindowState = ReadFromINI(sAppPath, Me.Name, "WindowState", CStr(Me.WindowState))
'A Чтение настроек формы*****************************************************************************************************************************************************
'V Сохранение настроек формы*****************************************************************************************************************************************************
Dim sAppPath As String
sAppPath = App.Path 'Определение местонахождения файлов с программой
If Right$(sAppPath, 1) <> "\" Then sAppPath = sAppPath & "\" 'Проверка на местонахождение на локальном диске
sAppPath = sAppPath & App.Title & ".ini"
If Me.WindowState <> vbMinimized And Me.WindowState <> vbMaximized Then
WritePrivateProfileString Me.Name, "Left", CStr(Me.Left), sAppPath
WritePrivateProfileString Me.Name, "Top", CStr(Me.Top), sAppPath
WritePrivateProfileString Me.Name, "Width", CStr(Me.Width), sAppPath
WritePrivateProfileString Me.Name, "Height", CStr(Me.Height), sAppPath
End If
WritePrivateProfileString Me.Name, "WindowState", CStr(Me.WindowState), sAppPath
'A Сохранение настроек формы*****************************************************************************************************************************************************
Private Sub DelComponents(n As Byte)
.
.
.
If i = 1 Then s = "ExpressViewerSetup.exe"
If i = 2 Then s = "DLL.bat"
If i = 3 Then s = App.Title & ".ini"
.
.
.
End Sub
[b]App.Title & ".ini"[/b] - файл с настройками программы
[b]
ExpressViewerSetup.exe; DLL.bat
[/b] - файлы, запускаемуе программой. Эти вайлы и должны удаляться после инсталляции, могут быть любыми.
[b]
Буду крайне признателен, если кто подправит мой проект и выложит.
[/b]
Сейчас этот форум просматривают: нет зарегистрированных пользователей и гости: 172