Shuffeling application windows

Shuffeling application windows

Anonymous
Not applicable
471 Views
7 Replies
Message 1 of 8

Shuffeling application windows

Anonymous
Not applicable
Hi,

I am writing a procedure in AutoCAD that uses Excel. I am using the excel
file open dialog to opening an Excel file. When I use the GetOpenFilename to
select the file I had to get the Excel application on top and used
"apExcel.Application.Visible = True" where apExcel is my excel application
object. Now when I have Then when I have finished working in Excel, control
reverts back to AutoCAD. Any subsequent dialogs or forms are not visible as
they are hidden behind the Excel application window. I tried setting
"ThisDrawing.Application.Visible = True" but this did not put the AutoCAD
application object on top. I am a bit reluctant to set
"apExcel.Application.Visible = False" as if I crash out of my routine Excel
will be invisible. Is there a way to put various applications on "top"?

I will be having this problem a lot as I will be jumping between AutoCAD and
Excel a lot as my form where I set the ranges is in AutoCAD and my data is
in Excel.

Any assistance will be appreciated.

Regards

Sean
0 Likes
472 Views
7 Replies
Replies (7)
Message 2 of 8

Ed__Jobe
Mentor
Mentor
How about the AppActivate statement?

Ed


Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.
How to post your code.

EESignature

0 Likes
Message 3 of 8

Anonymous
Not applicable
try this:
(excel or autocad app).Parent.Windows(1).Visible = True

I'm not sure if it will work, I've battled the same thing you are now
though. My app leaves Excel on top last, as that is where the finished work
is being done. Another suggestion is to put a msgbox up on screen (say
something like 'Done'), this should bring back autocad.

PS: I'd like to hear if you are able to fix it with either one of these...

--
Kevin


"Sean Bartleet" wrote in message
news:A383CA64CEE15334E3B579ABA37D3DC2@in.WebX.maYIadrTaRb...
> Hi,
>
> I am writing a procedure in AutoCAD that uses Excel. I am using the excel
> file open dialog to opening an Excel file. When I use the GetOpenFilename
to
> select the file I had to get the Excel application on top and used
> "apExcel.Application.Visible = True" where apExcel is my excel application
> object. Now when I have Then when I have finished working in Excel,
control
> reverts back to AutoCAD. Any subsequent dialogs or forms are not visible
as
> they are hidden behind the Excel application window. I tried setting
> "ThisDrawing.Application.Visible = True" but this did not put the AutoCAD
> application object on top. I am a bit reluctant to set
> "apExcel.Application.Visible = False" as if I crash out of my routine
Excel
> will be invisible. Is there a way to put various applications on "top"?
>
> I will be having this problem a lot as I will be jumping between AutoCAD
and
> Excel a lot as my form where I set the ranges is in AutoCAD and my data is
> in Excel.
>
> Any assistance will be appreciated.
>
> Regards
>
> Sean
>
>
0 Likes
Message 4 of 8

Anonymous
Not applicable
I had hoped the following would work. It finds the hWnd of the Autocad
window by its caption, and then uses the API to bring the window to top.
When I run it from the IDE, however, with AutoCAD behind other programs,
Autocad pops *almost* to the top, just behind the IDE.
warning: with API development I've always heard that you should save your
work often, in case it locks up your machine.
warning2: I'm not sure what this code would do if the Autocad window were
minimized when the code gets to BringToTop...

Hope this helps


with help from:
http://groups.google.com/groups?q=BringWindowToTop+group:microsoft.public.vb
.winapi.*&hl=en&lr=&ie=UTF-8&oe=UTF-8&selm=e%24Z29fWFBHA.1940%40tkmsftngp04&
rnum=6

Option Explicit
Private Declare Function BringWindowToTop Lib "USER32" (ByVal hwnd As Long)
As Long
Private Declare Function FindWindow Lib "USER32" Alias "FindWindowA" ( _
ByVal lpszClassName As String, ByVal lpszWindow As String) As Long

Sub test_window_top()
Dim hwnd As Long
hwnd = FindWindow(vbNullString, ThisDrawing.Application.Caption)
BringWindowToTop hwnd
End Sub
0 Likes
Message 5 of 8

Anonymous
Not applicable
1. When running the code without the ide visible (i.e.. normal users), that
shouldn't be a problem

2. You could set xlApp.WindowState = xlNormal to make it normal first, that
would eliminate that problem (where xlApp would be Autocad.application in
this case)

--
Kevin


"James Belshan" wrote in message
news:261B31CD81AF844B6175689F6565C7B9@in.WebX.maYIadrTaRb...
> I had hoped the following would work. It finds the hWnd of the Autocad
> window by its caption, and then uses the API to bring the window to top.
> When I run it from the IDE, however, with AutoCAD behind other programs,
> Autocad pops *almost* to the top, just behind the IDE.
> warning: with API development I've always heard that you should save your
> work often, in case it locks up your machine.
> warning2: I'm not sure what this code would do if the Autocad window were
> minimized when the code gets to BringToTop...
>
> Hope this helps
>
>
> with help from:
>
http://groups.google.com/groups?q=BringWindowToTop+group:microsoft.public.vb
>
.winapi.*&hl=en&lr=&ie=UTF-8&oe=UTF-8&selm=e%24Z29fWFBHA.1940%40tkmsftngp04&
> rnum=6
>
> Option Explicit
> Private Declare Function BringWindowToTop Lib "USER32" (ByVal hwnd As
Long)
> As Long
> Private Declare Function FindWindow Lib "USER32" Alias "FindWindowA" ( _
> ByVal lpszClassName As String, ByVal lpszWindow As String) As Long
>
> Sub test_window_top()
> Dim hwnd As Long
> hwnd = FindWindow(vbNullString, ThisDrawing.Application.Caption)
> BringWindowToTop hwnd
> End Sub
>
>
>
0 Likes
Message 6 of 8

Anonymous
Not applicable
Hi,

Thanks but this is an event not a statement. Unless I am missing something.
See my other post below for the solution I found.

Thanks for the help.

Sean

"Ed_Jobe" wrote in message news:f12d41b.0@WebX.maYIadrTaRb...
> How about the AppActivate statement?
>
0 Likes
Message 7 of 8

Anonymous
Not applicable
Hi,

Thanks, Unfortunately I could not get this to work, I am not sure what
happened but AutoCAD did not get back to the top. Unless I am missing
something.

FYI, I found the code below on the Excel VBA NG.

Thanks for the help.

Sean.

Posted previously by Jim Rech:

http://groups.google.com/groups?q=journal+group:microsoft.public.excel.progr
amming+author:Rech&hl=en&lr=&ie=UTF-8&oe=UTF-8&safe=off&selm=OgCCVl4vBHA.159
2%40tkmsftngp07&rnum=1

From: "Jim Rech"
References:
Subject: Re: Switch Back to Excel
Date: Wed, 27 Feb 2002 07:22:21 -0500
Message-ID:
Newsgroups: microsoft.public.excel.programming
NNTP-Posting-Host: p0016c72ea.us.kpmg.com 199.207.253.96


Windows doesn't approve of inactive applications switching the focus back to
themselves.

Try this:

Public Declare Function GetWindowThreadProcessId Lib _
"user32" (ByVal hWnd As Long, lpdwProcessId As Long) As Long
Public Declare Function AttachThreadInput Lib "user32" _
(ByVal idAttach As Long, ByVal idAttachTo As Long, _
ByVal fAttach As Long) As Long
Public Declare Function GetForegroundWindow Lib "user32" () As Long
Public Declare Function SetForegroundWindow Lib "user32" _
(ByVal hWnd As Long) As Long
Public Declare Function IsIconic Lib "user32" _
(ByVal hWnd As Long) As Long
Public Declare Function ShowWindow Lib "user32" _
(ByVal hWnd As Long, ByVal nCmdShow As Long) As Long
Declare Function FindWindowA Lib "user32" (ByVal lpClassName _
As Long, ByVal lpWindowName As String) As Long

Const SW_SHOW = 5
Const SW_RESTORE = 9

''Run this an then switch to another application.
Sub Test()
Application.OnTime Now + TimeValue("00:00:05"), "BringTotop"
End Sub

Sub BringToTop()
ForceForegroundWindow FindWindowA(0, Application.Caption)
End Sub


''All this is necessary in Windows 98/NT5 because MS disabled
'' SetForegroundWindow unless
'' the caller is itself the foreground window.
'' From Visual Basic Programmers Journal Feb 1999 pg 94
Function ForceForegroundWindow(ByVal hWnd As Long) As Boolean
Dim ThreadID1 As Long
Dim ThreadID2 As Long
Dim nRet As Long

If hWnd = GetForegroundWindow Then
ForceForegroundWindow = True
Else
ThreadID1 = GetWindowThreadProcessId( _
GetForegroundWindow, ByVal 0&)
ThreadID2 = GetWindowThreadProcessId(hWnd, ByVal 0&)
If ThreadID1 <> ThreadID2 Then
AttachThreadInput ThreadID1, ThreadID2, True
nRet = SetForegroundWindow(hWnd)
AttachThreadInput ThreadID1, ThreadID2, False
Else
nRet = SetForegroundWindow(hWnd)
End If
If IsIconic(hWnd) Then
ShowWindow hWnd, SW_RESTORE
Else
ShowWindow hWnd, SW_SHOW
End If
ForceForegroundWindow = CBool(nRet)
End If
End Function

--
Jim Rech
Excel MVP
0 Likes
Message 8 of 8

Ed__Jobe
Mentor
Mentor
AppActivate is a statement of the form AppAcivate title [wait]. Pass it the title of the desired app to activate (bring to front).

Ed


Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.
How to post your code.

EESignature

0 Likes