Option Explicit
Private Declare Function ShellExecute _
Lib "shell32.dll" Alias "ShellExecuteA" ( _
ByVal hwnd As Long, _
ByVal lpOperation As String, _
ByVal lpFile As String, _
ByVal lpParameters As String, _
ByVal lpDirectory As String, _
ByVal nShowCmd As Long) As Long
Public Sub SetMeOnTop()
SetWindowPos Me.hwnd, HWND_TOPMOST, 0&, 0&, 0&, 0&, SWP_FLAGS
End Sub
Private Sub Form_Load()
Me.Top = GetSetting(App.EXEName, "StartPosition", "Top", Me.Top)
Me.Left = GetSetting(App.EXEName, "StartPosition", "Left", Me.Left)
SetMeOnTop
End Sub
Private Sub Form_Unload(Cancel As Integer)
Me.WindowState = vbNormal
SaveSetting App.EXEName, "StartPosition", "Top", Me.Top
SaveSetting App.EXEName, "StartPosition", "Left", Me.Left
End
End Sub
Private Sub Timer1_Timer()
Toolbar1.Buttons("Copy").Enabled = frmScreen.shpSelect.Visible And frmScreen.Visible
Toolbar1.Buttons("Minimize").Enabled = Not frmScreen.Visible
If Toolbar1.Buttons("Copy").Enabled Then
With frmScreen.shpSelect
lblSelPos = .Left & ", " & .Top
lblSelSize = .Width & " x " & .Height
End With
Else
lblSelPos = "0, 0"
lblSelSize = "0 x 0"
End If
End Sub
Private Sub Toolbar1_ButtonClick(ByVal Button As MSComCtlLib.Button)
On Error Resume Next
Select Case Button.Key
Case "Select"
If Button.Value = tbrPressed Then
SetWindowPos Me.hwnd, HWND_NOTOPMOST, 0&, 0&, 0&, 0&, SWP_FLAGS
Me.Hide
DoEvents
frmScreen.ShowMe
frmCapture.SetMeOnTop
Else
frmScreen.Hide
End If
Case "Copy"
frmScreen.CopySelection
frmScreen.Hide
Toolbar1.Buttons("Select").Value = tbrUnpressed
Case "Edit"
ShellExecute Me.hwnd, "Open", frmScreen.Filename, "", "", vbNormalFocus
Case "Minimize"
Me.WindowState = vbMinimized
Case "Close"
Unload Me
End Select
End Sub
module:
Option Explicit
Public 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 Const SWP_NOMOVE = &H2
Public Const SWP_NOSIZE = &H1
Public Const SWP_FLAGS = (SWP_NOMOVE Or SWP_NOSIZE)
Public Const HWND_TOPMOST = -1
Public Const HWND_NOTOPMOST = -2