Click here to Skip to main content
15,895,084 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
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.
Posted
Comments
Amit Jadli 21-Dec-15 7:47am    
Not Clear..

1 solution

Try this:

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);
    }
}
 
Share this answer
 
v4
Comments
SmokeHead 21-Dec-15 10:05am    
+5 :)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900