检查窗口是否打开(按名称) [英] check window is open or not (by name)
本文介绍了检查窗口是否打开(按名称)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
你好,
我用javascript打开一个窗口并给出窗口名称。
但如果会话超时我需要关闭这个窗口。
所以如果打开然后关闭它我怎么能找到窗口打开。
谢谢。
Hello,
I am open a window by javascript and give window name.
But if session time out i need to close this window.
so how i can find window open or not if open then close it.
Thanks.
推荐答案
试试这个:
Try this:
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);
}
}
这篇关于检查窗口是否打开(按名称)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文