• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1404
  • Last Modified:

appactivate with minimized or hidden window

if the window you're activating isn't minizized or visible, appactivate doesn't work..
How do I solve this (not by shell "app", vbnormalfocus) the app is already running !*in the system tray*!
0
Smout
Asked:
Smout
  • 2
1 Solution
 
MirkwoodCommented:
From the EE FAQ:

"It is up to you to assign points to the question based on its difficulty. As a guide, a basic question is worth 50 points, an intermediate question 100 points, and an advanced question 200 points. The more points assigned to a question, the more likely it will be answered."

0
 
DavidMartinCommented:
Option Explicit
Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) 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 Const HWND_TOP = 0
Private Const SWP_SHOWWINDOW = &H40

Private Declare Function GetLastError Lib "kernel32" () As Long


Private Sub Command1_Click()

    Dim lHwnd As Long

    lHwnd = FindWindow(vbNullString, "Yahoo! Messenger")
    Debug.Print "FindWindow : " & GetLastError()
   
    SetWindowPos lHwnd, HWND_TOP, 0, 0, 0, 0, SWP_SHOWWINDOW
    Debug.Print "SetWindowPos : " & GetLastError()


End Sub

0
 
SmoutAuthor Commented:
Thank you
only now I see my program minimized
can you send me the constants plz
0
 
DavidMartinCommented:
Option Explicit
Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) 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 ShowWindow Lib "user32" (ByVal hwnd As Long, ByVal nCmdShow As Long) As Long
Private Declare Function GetLastError Lib "kernel32" () As Long

Private Const HWND_TOP = 0
Private Const SWP_SHOWWINDOW = &H40
Private Const SWP_NOMOVE = &H2
Private Const SWP_NOSIZE = &H1
Private Const SW_RESTORE = 9



Private Sub Command1_Click()

    Dim lHwnd As Long

    lHwnd = FindWindow(vbNullString, "Yahoo! Messenger")
    Debug.Print "FindWindow : " & GetLastError()
   
    'SetWindowPos lHwnd, HWND_TOP, 0, 0, 0, 0, SWP_SHOWWINDOW Or SWP_NOMOVE Or SWP_NOSIZE
    'Debug.Print "SetWindowPos : " & GetLastError()

    ShowWindow lHwnd, SW_RESTORE
    Debug.Print "ShowWindow : " & GetLastError()


End Sub
0

Featured Post

2018 Annual Membership Survey

Here at Experts Exchange, we strive to give members the best experience. Help us improve the site by taking this survey today! (Bonus: Be entered to win a great tech prize for participating!)

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now