Link to home
Start Free TrialLog in
Avatar of ttobin333
ttobin333

asked on

vb6 Subclassing Restore Minimized Program From Taskbar

Dear Experts,

How can I subclass the action of restoring a minimized program from the taskbar, both by clicking the minimized program and by right-click then restore?

Thanks.
Avatar of Antagony1960
Antagony1960

Are you sure you mean subclassing?

If you're asking how to restore your own program, you can use: MyForm.WindowState = vbNormal

If you want to restore an external application you can do it with API calls if you know the exact title (caption) of the application to be restored. Something like this will do it:

      Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, _
                                                                                                              ByVal lpWindowName As String) As Long
      Private Declare Function ShowWindow Lib "user32" (ByVal hwnd As Long, _
                                                                                 ByVal nCmdShow As Long) As Long
      Private Const SW_SHOWNORMAL As Long = 1
      Public Sub RestoreExternal(ByVal szWindowTitle As String)
      Dim hWnd As Long
           hWnd = FindWindow(vbNullString, szWindowTitle)
           ShowWindow hWnd, SW_SHOWNORMAL
      End Sub
ASKER CERTIFIED SOLUTION
Avatar of Mike Tomlinson
Mike Tomlinson
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
If, as Idle_Mind's solution suggests, you really are asking how to subclass the restore event, I'd be interested to know why you would want to do that (in the knowledge that subclassing is inherently problematic) rather than using simple boolean logic in the Form_Resize event. Something like this:

Private Sub Form_Resize()
Static bMinimized As Boolean
    If Me.WindowState = vbMinimized Then
        bMinimized = True
    ElseIf bMinimized Then 'Form is being restored or maximized
        bMinimized = False
        MsgBox "leaving minimized state!"
    End If
End Sub
Avatar of ttobin333

ASKER

Thanks again, Idle Mind!
Antagony1960, I needed to subclass the restore event so that my window could be resized to the original size when restored, even if it was "rolled up" to show only the title bar at the time it was minimized to the task bar. I see your point, but since I am forced to use subclassing for other actions in this program, I wanted to lump these similar actions into the same function.
Ah, understood. I was just curious is all. :-)
No problem, thanks for your interest!