Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/287.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 如何在VB.net中以编程方式关闭窗口?_C#_.net_Vb.net - Fatal编程技术网

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

C# 如何在VB.net中以编程方式关闭窗口?,c#,.net,vb.net,C#,.net,Vb.net,如何在VB.net中以编程方式关闭外部应用程序窗口。 我只想关闭当前窗口,而不关闭整个过程 使用FindWindow和SendMessageAPI 在C#中,转换起来应该很简单: using Microsoft.Win32; [DllImport("user32.dll")] public static extern int FindWindow(string lpClassName,string lpWindowName); [DllImport("user32.dll")] public

如何在VB.net中以编程方式关闭外部应用程序窗口。
我只想关闭当前窗口,而不关闭整个过程

使用
FindWindow
SendMessage
API

在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);
    }  
}

来源:

你所说的外部应用程序窗口是什么意思?@krammer我正试图通过我的应用程序关闭另一个应用程序的窗口。我不知道表单名。我只想关上它。