Go Back  Xtreme Visual Basic Talk > Legacy Visual Basic (VB 4/5/6) > API > how to close a window by giving hwnd


Reply
 
Thread Tools Display Modes
  #1  
Old 10-11-2003, 10:32 AM
tombrum tombrum is offline
Newcomer
 
Join Date: Sep 2003
Location: Birmingham UK
Posts: 10
Unhappy how to close a window by giving hwnd


Hi all, i wonder if someone can give me an example of a working WM_SYSCOMMAND in action closing down internet explorer. If you can i would be very very gratefull

Quote:
Originally Posted by MathImagics
I believe that, in the general case of closing other application windows, it's possible that the target application might not do all its normal shutdown processing if you simply post a WM_CLOSE.

The best method, I think, is to post a WM_SYSCOMMAND with the SC_CLOSE parameter - this is the closest you can get to a simulation of the user clicking on the X (Close) button of the window.

And whichever way you do it, as Red Bull has noted, it should be Posted, not Sent.


Dr Memory

Reply With Quote
  #2  
Old 10-11-2003, 10:45 AM
Mathimagics's Avatar
Mathimagics Mathimagics is offline
Algorithms 'R' Us

Forum Leader
* Guru *
 
Join Date: Jun 2002
Location: Canberra
Posts: 4,123
Default

Code:
Public Const WM_SYSCOMMAND = &H112 Public Const SC_CLOSE = &HF060& PostMessage tWindow, WM_SYSCOMMAND, SC_CLOSE, ByVal 0

Works fine for IExplore windows
__________________
Sept, 2006: 2 ^ 232,582,657 - 1 is prime!

At first, I was iridescent. Then, I became transparent. Finally, I was absent.
Reply With Quote
  #3  
Old 10-11-2003, 11:01 AM
tombrum tombrum is offline
Newcomer
 
Join Date: Sep 2003
Location: Birmingham UK
Posts: 10
Unhappy help!

cheers mathimagics,

could you please give me a full example cus im a newbie

cheer, tom
Quote:
Originally Posted by MathImagics
Code:
Public Const WM_SYSCOMMAND = &H112 Public Const SC_CLOSE = &HF060& PostMessage tWindow, WM_SYSCOMMAND, SC_CLOSE, ByVal 0

Works fine for IExplore windows

Reply With Quote
  #4  
Old 10-11-2003, 12:12 PM
Mathimagics's Avatar
Mathimagics Mathimagics is offline
Algorithms 'R' Us

Forum Leader
* Guru *
 
Join Date: Jun 2002
Location: Canberra
Posts: 4,123
Default

The code I gave you has only 2 things missing - the API declaration for PostMessage, which is
Code:
Declare Function PostMessage Lib "user32" Alias "PostMessageA" _ (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, _ lParam As Any) As Long

and tWindow.

You need to set this to the handle of the window you want to close.

Search for FindWindow - heaps of examples. And it looks like the poster of this thread was looking for IExplore windows so you could send him a PM maybe
__________________
Sept, 2006: 2 ^ 232,582,657 - 1 is prime!

At first, I was iridescent. Then, I became transparent. Finally, I was absent.
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump

Advertisement:





Free Publications
The ASP.NET 2.0 Anthology
101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET.
subscribe
Programmers Heaven C# School Book -Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
subscribe
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
This comprehensive step-by-step guide will help get your database-driven ASP.NET web site up and running in no time..
subscribe
 
 
-->