Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. How to close the window using its Window Handle.

How to close the window using its Window Handle.

Scheduled Pinned Locked Moved C#
csharpwinformscomtutorialquestion
3 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • E Offline
    E Offline
    engsrini
    wrote on last edited by
    #1

    Hi I am developing a windows application which is having login and other pages as winforms. In the login page I having an option for the user to change his password. If i click that change password button Im openning the change password URL in a webbrowser control. In that user will be asked to first login, and after login user will directed to change Password screen. But when the user logged in and closed that window and if the user clicks again the changepassword button then webbrowser control directing hime to change password screen instead of Login page. (is like kinda cached page). but i tried of clearing cache, used Activex control nothing works out. Finally i saw the everytime i open the URL usign webbrowser control it is creating a Hidden IE window. (usign spy++). so that webbrowser is directing to the alredy opened page. How to close that hidden window? can i use its handle to close that one or any other solution here? Thanks in Advacne Srini

    L 1 Reply Last reply
    0
    • E engsrini

      Hi I am developing a windows application which is having login and other pages as winforms. In the login page I having an option for the user to change his password. If i click that change password button Im openning the change password URL in a webbrowser control. In that user will be asked to first login, and after login user will directed to change Password screen. But when the user logged in and closed that window and if the user clicks again the changepassword button then webbrowser control directing hime to change password screen instead of Login page. (is like kinda cached page). but i tried of clearing cache, used Activex control nothing works out. Finally i saw the everytime i open the URL usign webbrowser control it is creating a Hidden IE window. (usign spy++). so that webbrowser is directing to the alredy opened page. How to close that hidden window? can i use its handle to close that one or any other solution here? Thanks in Advacne Srini

      L Offline
      L Offline
      Lost User
      wrote on last edited by
      #2

      [DllImport("user32.dll")]
      static extern bool CloseWindow(IntPtr hWnd);

      [DllImport("user32.dll")]
      static extern System.IntPtr FindWindow(string lpClassName, string lpWindowName);

      private void button1_Click(object sender, EventArgs e)
      {
      string lpClassName = "WindowClass1";
      string lpWindowName = "MyWindow1";

      IntPtr hWnd = FindWindow(lpClassName, lpWindowName);
      CloseWindow(hWnd);
      }

      E 1 Reply Last reply
      0
      • L Lost User

        [DllImport("user32.dll")]
        static extern bool CloseWindow(IntPtr hWnd);

        [DllImport("user32.dll")]
        static extern System.IntPtr FindWindow(string lpClassName, string lpWindowName);

        private void button1_Click(object sender, EventArgs e)
        {
        string lpClassName = "WindowClass1";
        string lpWindowName = "MyWindow1";

        IntPtr hWnd = FindWindow(lpClassName, lpWindowName);
        CloseWindow(hWnd);
        }

        E Offline
        E Offline
        engsrini
        wrote on last edited by
        #3

        Thanks for the reply, But this doesn't help, Still the Browser directing URL to logged in page instead of Login page. I am using the code like this CloseWindow(frmChange.axWebBrowser.Handle);

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups