Click here to Skip to main content
14,737,146 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:

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.

Amit Jadli 21-Dec-15 7:47am
Not Clear..

1 solution

Try this:

using Microsoft.Win32;
public static extern int FindWindow(string lpClassName,string lpWindowName);
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);
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