By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
431,983 Members | 1,717 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 431,983 IT Pros & Developers. It's quick & easy.

website doesn't clode using FindWindow()

P: n/a
Hello all,
I try to open and close a webpage (when timer ticks) The problem is
that it won't close ...
Can anybody see what I am doing wrong? I'll paste the code here ...
Any help very much appreciated ....
Thanks
Ronny

Declarations:
Public Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal
hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As
Long
Public Const WM_CLOSE = &H82
Public lIExplorerhWnd As Long
Public Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal
lpClassName As String, ByVal lpWindowName As String) As Long

And here the actual code:

Private Sub Form_Timer()
Call Shell("C:\Program Files\Internet Explorer\iexplore.exe",
vbMinimizedNoFocus)
DoEvents
Me!txtNumberOfTimes.Value = Me!txtNumberOfTimes.Value + 1
Me!Temphits.Value = Me!Temphits.Value + 1
IIExplorerhWnd = FindWindow("IEFrame", "Mimron's Home Page - Microsoft
Internet Explorer")
Debug.Print IIExplorerhWnd 'only to see if it gets the handle, shall be
removed afterwards ...
Call SendMessage(lIExplorerhWnd, WM_CLOSE, 0, 0)
End Sub
Nov 13 '05 #1
Share this Question
Share on Google+
5 Replies


P: n/a
Hi, Ronny.

You're trying to open an application, find its window, then close the
application within the same procedure. Using the Shell( ) function will
cause the application launch to run asynchronously with Access, so a single
call to DoEvents may not be enough to allow the application to initialize
before your procedure sends the message to close it.

I would suggest opening the application in a separate procedure, then using
the form's timer to close the application a number of seconds later.

Since your procedure isn't using the return value from the SendMessage( )
function and may not even need to wait for this function to complete
execution, you may want to use the Windows API PostMessage( ) function,
instead. For an example of the syntax using the PostMessage( ) function to
close a window, see Dev Ashish's Web page:

http://www.mvps.org/access/api/api0063.htm

HTH.

Gunny

See http://www.QBuilt.com for all your database needs.
See http://www.Access.QBuilt.com for Microsoft Access tips.

(Please remove ZERO_SPAM from my reply E-mail address, so that a message
will be forwarded to me.)
"Ronny Sigo" <roon ad skynet.be> wrote in message
news:41**********************@news.skynet.be...
Hello all,
I try to open and close a webpage (when timer ticks) The problem is
that it won't close ...
Can anybody see what I am doing wrong? I'll paste the code here ...
Any help very much appreciated ....
Thanks
Ronny

Declarations:
Public Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As
Long
Public Const WM_CLOSE = &H82
Public lIExplorerhWnd As Long
Public Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal
lpClassName As String, ByVal lpWindowName As String) As Long

And here the actual code:

Private Sub Form_Timer()
Call Shell("C:\Program Files\Internet Explorer\iexplore.exe",
vbMinimizedNoFocus)
DoEvents
Me!txtNumberOfTimes.Value = Me!txtNumberOfTimes.Value + 1
Me!Temphits.Value = Me!Temphits.Value + 1
IIExplorerhWnd = FindWindow("IEFrame", "Mimron's Home Page - Microsoft
Internet Explorer")
Debug.Print IIExplorerhWnd 'only to see if it gets the handle, shall be removed afterwards ...
Call SendMessage(lIExplorerhWnd, WM_CLOSE, 0, 0)
End Sub

Nov 13 '05 #2

P: n/a
Ronny Sigo wrote:
Hello all,
I try to open and close a webpage (when timer ticks) The problem is
that it won't close ...
Can anybody see what I am doing wrong? I'll paste the code here ...
Any help very much appreciated ....
Thanks
Ronny

Declarations:
Public Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal
hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As
Long
Public Const WM_CLOSE = &H82
Public lIExplorerhWnd As Long
Public Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal
lpClassName As String, ByVal lpWindowName As String) As Long

And here the actual code:

Private Sub Form_Timer()
Call Shell("C:\Program Files\Internet Explorer\iexplore.exe",
vbMinimizedNoFocus)
DoEvents
Me!txtNumberOfTimes.Value = Me!txtNumberOfTimes.Value + 1
Me!Temphits.Value = Me!Temphits.Value + 1
IIExplorerhWnd = FindWindow("IEFrame", "Mimron's Home Page - Microsoft
Internet Explorer")
Debug.Print IIExplorerhWnd 'only to see if it gets the handle, shall be
removed afterwards ...
Call SendMessage(lIExplorerhWnd, WM_CLOSE, 0, 0)
End Sub


I tried this and AFAICS as long as you give enough time for the homepage
to load (stepping the code will do this) it gets the window handle OK
and according to the docs, SendMessage returns 0 if the application
processed the message, in my test it returned 0 but didn't close so IE
is a big fat liar.

BTW your code has an extra space between "Internet" and "Explorer".

--

\\\\\\
\\ \\ Windows is searching
\ \ For your sig.
\ \ Please Wait.
\__\

Nov 13 '05 #3

P: n/a
Your declaration for the WM_CLOSE mesage identifier is incorrect. You
are using the value for the WM_DESTROY message id which you should not
be using! Also you sreally should be using PostMessage instead of
SendMessage.

Private Const WM_CLOSE = &H10

Finally, I do not understand, unless you have left out some code, how
you can be placing your code to open the MS Explorer app within the
form's Timer event. You must have the Timer Interval prop set to a large
value.
--

HTH
Stephen Lebans
http://www.lebans.com
Access Code, Tips and Tricks
Please respond only to the newsgroups so everyone can benefit.
"Ronny Sigo" <roon ad skynet.be> wrote in message
news:41**********************@news.skynet.be...
Hello all,
I try to open and close a webpage (when timer ticks) The problem is
that it won't close ...
Can anybody see what I am doing wrong? I'll paste the code here ...
Any help very much appreciated ....
Thanks
Ronny

Declarations:
Public Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
Public Const WM_CLOSE = &H82
Public lIExplorerhWnd As Long
Public Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long

And here the actual code:

Private Sub Form_Timer()
Call Shell("C:\Program Files\Internet Explorer\iexplore.exe",
vbMinimizedNoFocus)
DoEvents
Me!txtNumberOfTimes.Value = Me!txtNumberOfTimes.Value + 1
Me!Temphits.Value = Me!Temphits.Value + 1
IIExplorerhWnd = FindWindow("IEFrame", "Mimron's Home Page - Microsoft Internet Explorer")
Debug.Print IIExplorerhWnd 'only to see if it gets the handle, shall be removed afterwards ...
Call SendMessage(lIExplorerhWnd, WM_CLOSE, 0, 0)
End Sub


Nov 13 '05 #4

P: n/a
Thanks guys :) I used Camaro's solution ... works great !

"Ronny Sigo" <roon ad skynet.be> schreef in bericht
news:41**********************@news.skynet.be...
Hello all,
I try to open and close a webpage (when timer ticks) The problem is
that it won't close ...
Can anybody see what I am doing wrong? I'll paste the code here ...
Any help very much appreciated ....
Thanks
Ronny

Declarations:
Public Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As
Long
Public Const WM_CLOSE = &H82
Public lIExplorerhWnd As Long
Public Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal
lpClassName As String, ByVal lpWindowName As String) As Long

And here the actual code:

Private Sub Form_Timer()
Call Shell("C:\Program Files\Internet Explorer\iexplore.exe",
vbMinimizedNoFocus)
DoEvents
Me!txtNumberOfTimes.Value = Me!txtNumberOfTimes.Value + 1
Me!Temphits.Value = Me!Temphits.Value + 1
IIExplorerhWnd = FindWindow("IEFrame", "Mimron's Home Page - Microsoft
Internet Explorer")
Debug.Print IIExplorerhWnd 'only to see if it gets the handle, shall be removed afterwards ...
Call SendMessage(lIExplorerhWnd, WM_CLOSE, 0, 0)
End Sub

Nov 13 '05 #5

P: n/a
You're welcome! Glad it helped.

HTH.

Gunny

See http://www.QBuilt.com for all your database needs.
See http://www.Access.QBuilt.com for Microsoft Access tips.

(Please remove ZERO_SPAM from my reply E-mail address, so that a message
will be forwarded to me.)
"Ronny Sigo" <ro********@skynet.be> wrote in message
news:41**********************@feed0.news.be.easyne t.net...
Thanks guys :) I used Camaro's solution ... works great !

"Ronny Sigo" <roon ad skynet.be> schreef in bericht
news:41**********************@news.skynet.be...
Hello all,
I try to open and close a webpage (when timer ticks) The problem is
that it won't close ...
Can anybody see what I am doing wrong? I'll paste the code here ...
Any help very much appreciated ....
Thanks
Ronny

Declarations:
Public Declare Function SendMessage Lib "user32" Alias "SendMessageA"

(ByVal
hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
Public Const WM_CLOSE = &H82
Public lIExplorerhWnd As Long
Public Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long

And here the actual code:

Private Sub Form_Timer()
Call Shell("C:\Program Files\Internet Explorer\iexplore.exe",
vbMinimizedNoFocus)
DoEvents
Me!txtNumberOfTimes.Value = Me!txtNumberOfTimes.Value + 1
Me!Temphits.Value = Me!Temphits.Value + 1
IIExplorerhWnd = FindWindow("IEFrame", "Mimron's Home Page - Microsoft Internet Explorer")
Debug.Print IIExplorerhWnd 'only to see if it gets the handle, shall

be
removed afterwards ...
Call SendMessage(lIExplorerhWnd, WM_CLOSE, 0, 0)
End Sub


Nov 13 '05 #6

This discussion thread is closed

Replies have been disabled for this discussion.