简体   繁体   English

如何在VB.net中以编程方式关闭窗口?

[英]How to close a window programmatically in VB.net?

How can I close a window of external application programmatically in VB.net. 如何在VB.net中以编程方式关闭外部应用程序的窗口。 I just want to close the current window without closing the whole process. 我只想关闭当前窗口而不关闭整个过程。

use FindWindow and SendMessage APIs 使用FindWindowSendMessage API

here in C#, should be trivial to convert: 这里用C#,应该是微不足道的转换:

using Microsoft.Win32;

[DllImport("user32.dll")]
public static extern int FindWindow(string lpClassName,string lpWindowName);
[DllImport("user32.dll")]
public static extern int SendMessage(int hWnd, uint Msg, int wParam, int lParam);

public const int WM_SYSCOMMAND = 0x0112;
public const int SC_CLOSE = 0xF060;

private void closeWindow()
{
    // retrieve the handler of the window  
    int iHandle = FindWindow("Notepad", "Untitled - Notepad");
    if (iHandle > 0)
    {
        // close the window using API        
        SendMessage(iHandle, WM_SYSCOMMAND, SC_CLOSE, 0);
    }  
}

source: http://www.codeproject.com/KB/dialog/closewindow.aspx 来源: http//www.codeproject.com/KB/dialog/closewindow.aspx

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何使用VB.Net或C#.Net关闭回收站 - How to close the Recycle Bin using VB.Net or C#.Net 如何在VB.NET中执行此操作? - How to do this in VB.NET? vb.net:怎么样? 要么 ?? vb.net在C#中有条件吗? - vb.net: How is it ? or ?? conditional in c# for vb.net? 如何在 C#/Vb.net 中将数组字节写入 PDF/A-3 和附件 [关闭] - How to write byte of array to PDF/A-3 and attachment in C# / Vb.net [Close] 如何以编程方式使用 C#/VB.Net 以 MB 为单位测量网站带宽(上传+下载)? - How to measure a Website Bandwidth (Upload+Download) in MB using C#/VB.Net programmatically? 如何以编程方式提供凭据以在 c# 或 vb.net 中使用 google drive api? - How to provide Credentials programmatically to use google drive api in c# or vb.net? 如何在不使用Java脚本的情况下在c#和vb.net中注册(以编程方式使用)鼠标悬停事件 - how to register( programmatically use) a mouse over event in c# and vb.net without using java script 如何以编程方式训练SpeechRecognitionEngine并将音频文件转换为C#或vb.net中的文本 - How to programmatically train the SpeechRecognitionEngine and convert audio file to text in C# or vb.net Vb.Net关闭Winforms窗体的句柄 - Vb.Net Close Winforms Form by its handle 以编程方式注册C#/ VB.NET COM DLL - Register a C#/VB.NET COM dll programmatically
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM