From: RB Smissaert on
Thanks, but I know the IsIconic API.
The problem is that the OP need to know this in Excel, so he will need to
run something (?ActiveX exe
as I am not sure an ActiveX dll can do this) that monitors the Excel window
and notifies Excel of any changes.
Getting the hWnd of the Excel application window is no problem. Ideally,
Excel should pass that handle to
the VB6 exe or dll and I don't think the exe or dll needs a reference to
Excel.

RBS


"Nobody" <nobody(a)nobody.com> wrote in message
news:ui8wVCNeKHA.2624(a)TK2MSFTNGP04.phx.gbl...
> "Robert Crandal" <nobody(a)gmail.com> wrote in message
> news:ZWITm.49702$ky1.19872(a)newsfe14.iad...
>>I need to be able to detect the event when someone
>> minimizes or restores the Excel application, or
>> switches to another application.
>>
>> How can I do these?? (if it's even possible)
>
> The sample code below was tested with Excel 2002. It uses
> Application.hWnd, which seems to be new in Excel 2002. For Excel 2000 and
> below, there are various API ways. If you have any hWnd for any window in
> Excel, you can use GetAncestor(GA_ROOT) to get hWnd for the main window.
> Also, rather than using WindowState property below, you can use the API
> function IsIconic() to see if a window is minimized.
>
> To try this sample, add Timer1 to Form1, and a reference to " Microsoft
> Excel X.X Object Library", then use the following code:
>
> Option Explicit
>
> Private Declare Function GetForegroundWindow Lib "user32" () As Long
> Private Declare Function IsIconic Lib "user32" (ByVal hwnd As Long) As
> Long
>
> Dim oExcelApp As Excel.Application
>
> Private Sub Form_Load()
> Set oExcelApp = New Excel.Application
>
> oExcelApp.Visible = True
>
> Timer1.Interval = 500
>
> End Sub
>
> Private Sub Form_Unload(Cancel As Integer)
> oExcelApp.Quit
> Set oExcelApp = Nothing
> End Sub
>
> Private Sub Timer1_Timer()
> Debug.Print "IsIconic = " & (IsIconic(oExcelApp.hwnd) <> 0);
> Debug.Print ", Minimized = " & (oExcelApp.WindowState = xlMinimized);
> Debug.Print ", ForegroundWindow = " & (GetForegroundWindow() = _
> oExcelApp.hwnd)
> End Sub
>
>

From: Ralph on

"Robert Crandal" <nobody(a)gmail.com> wrote in message
news:_jKTm.78597$W77.41608(a)newsfe11.iad...
> But they told me to come and ask here! 8(
>

As Robert noted there doesn't appear to be a simple way to handle this for
any application.

It might be possible to install some kind of system hook to catch an event,
or device that polls for Window states (as there is nothing in programming
that is truly impossible), but I wouldn't have a clue where to start.

Once you find a starting point come back for more help with the details.

-ralph


From: Karl E. Peterson on
RB Smissaert pretended :
> The problem is that the OP need to know this in Excel, so he will need to run
> something (?ActiveX exe

So they just need a timer in VBA? http://vb.mvps.org/samples/TimerObj

--
[.NET: It's About Trust!]


From: RB Smissaert on
Ah, good thought that and will try that out!

RBS


"Karl E. Peterson" <karl(a)exmvps.org> wrote in message
news:uMg3ZkQeKHA.3792(a)TK2MSFTNGP02.phx.gbl...
> RB Smissaert pretended :
>> The problem is that the OP need to know this in Excel, so he will need to
>> run something (?ActiveX exe
>
> So they just need a timer in VBA? http://vb.mvps.org/samples/TimerObj
>
> --
> [.NET: It's About Trust!]
>
>

From: RB Smissaert on
Had a quick look and it looks all very good.
Just one problem I noticed is that when I showed the VBA form modeless and
then
minimized Excel the form was gone, I suppose it crashed. Can it work with a
modeless form?

RBS


"RB Smissaert" <bartsmissaert(a)blueyonder.co.uk> wrote in message
news:%23QYVLtQeKHA.2184(a)TK2MSFTNGP04.phx.gbl...
> Ah, good thought that and will try that out!
>
> RBS
>
>
> "Karl E. Peterson" <karl(a)exmvps.org> wrote in message
> news:uMg3ZkQeKHA.3792(a)TK2MSFTNGP02.phx.gbl...
>> RB Smissaert pretended :
>>> The problem is that the OP need to know this in Excel, so he will need
>>> to run something (?ActiveX exe
>>
>> So they just need a timer in VBA? http://vb.mvps.org/samples/TimerObj
>>
>> --
>> [.NET: It's About Trust!]
>>
>>
>