VBGood网站全文搜索 Google

搜索VBGood全站网页(全文搜索)
首页 - 经验之谈 - 请问在VB中如何关闭别的应用程序窗口?我用API的FindWindow函数找到IE4的窗口,但用API的CloseWindow函数只使该窗口最小化,而不能关闭,应该怎样做?
发表评论(0)作者:, 平台:, 阅读:14210, 日期:2000-03-12


  答:首先,建立一个类模块,利用 API察看器程序,将需要用到的常量定义和API函数粘贴过来,如:

  Public ConstWM_CLOSE = &H10

  Public Const WM_QUIT = &H12

  Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long

  Declare Function PostMessage Lib "user32" Alias "PostMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long

  接下来,就可以利用 FindWindow 函数获取窗口句柄,然后向这个窗口发送 WM_CLOSE 或 WM_QUIT 信息让窗口自行关闭:

  Handle = FindWindow("IEFrame", vbNullString)

  PostMessage Handle,WM_CLOSE,0,0 或 PostMessage Handle,WM_QUIT,0,0 均可。