Статьи

Листинг к статье

"DLL – это просто"

Класс MyLib

Option Explicit

Private m_FormFunction As FrmFunct

Private m_IniFunction As IniFunct

Public Property Get FormFunction() As FrmFunct

    Set FormFunction = m_FormFunction

End Property

Public Property Get IniFunction() As IniFunct

    Set IniFunction = m_IniFunction

End Property

Private Sub Class_Initialize()

  Set m_FormFunction = New FrmFunct

  Set m_IniFunction = New IniFunct

End Sub

Private Sub Class_Terminate()

  Set m_FormFunction = Nothing

  Set m_IniFunction = Nothing

End Sub

Класс FrmFunct

Option Explicit

Private Const HWND_TOPMOST = -1

Private Const HWND_NOTOPMOST = -2

Private Const SWP_NOMOVE = &H2

Private Const SWP_NOSIZE = &H1

Private Const SWP_NOACTIVATE = &H10

Private Const SWP_SHOWWINDOW = &H40

Private Const TOPMOST_FLAGS = SWP_NOMOVE Or SWP_NOSIZE

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

Public Sub MakeNormal(Handle As Long)

  SetWindowPos Handle, HWND_NOTOPMOST, 0, 0, 0, 0, TOPMOST_FLAGS

End Sub

Public Sub MakeTopMost(Handle As Long)

  SetWindowPos Handle, HWND_TOPMOST, 0, 0, 0, 0, TOPMOST_FLAGS

End Sub

Класс IniFunct

Option Explicit

Private 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

Private 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

'Читаем данные из ini

Public Function ReadINIKey(Section As String, KeyName As String, _
  FileName As String) As String

    Dim RetVal As String

    RetVal = String(255, Chr(0))

    ReadINIKey = Left(RetVal, GetPrivateProfileString(Section, KeyName, _
      "", RetVal, Len(RetVal), FileName))

End Function

'Записываем данные в ini

Public Function WriteInIKey(Section As String, KeyName As String, _
  KeyValue As String, FileName As String)

    WritePrivateProfileString Section, KeyName, KeyValue, FileName

End Function

Тестировочный проект. Форма.

Option Explicit

Private ML As MyLib

Private Sub Command1_Click()

  ML.FormFunction.MakeTopMost Me.hWnd

End Sub

Private Sub Command2_Click()

  ML.FormFunction.MakeNormal Me.hWnd

End Sub

Private Sub Form_Load()

  Set ML = New MyLib

End Sub

Private Sub Form_Unload(Cancel As Integer)

  Set ML = Nothing

End Sub

К статье

Hosted by uCoz