Gets the handle of the popup box, closes the popup box

Source: Internet
Author: User

You may have had such a demand, some pop-up boxes may need to be manually closed, so very troublesome, I refer to the relevant information, the C # program to automatically close the popup box for your reference

1 //gets the handle to the popup box and hides the function. 2 usingSystem.Runtime.InteropServices;//This is a required namespace. 3 classSearchwindow4     {5 6         Private Const intWm_close =0x0010;7[DllImport ("User32.dll", EntryPoint ="FindWindow")]8         Private Static externIntPtr FindWindow (stringLpclassname,9         stringlpwindowname);Ten[DllImport ("user32.dll", EntryPoint ="SendMessageA")] One         Private Static extern intSendMessage (INTPTR hwnd,intWmsg, IntPtr WParam,stringlParam); A          PublicSearchwindow () -         { -                  the         } -          Public voidCloseWindow (stringLpclassname,stringlpwindowname) -         { -              +IntPtr mhandle= FindWindow (NULL, lpwindowname); -            if(Mhandle! =IntPtr.Zero) +SendMessage (Mhandle, Wm_close, IntPtr.Zero,NULL); A            Else at            { -                return; -            } -         } -     } - ////Hide the console in  - usingSystem.Runtime.InteropServices;//This is a required namespace.  to  +  - classShadeconsole the     { *[DllImport ("user32.dll", EntryPoint ="ShowWindow", SetLastError =true)] $         Static extern BOOLShowWindow (IntPtr hWnd,UINTncmdshow);Panax Notoginseng[DllImport ("user32.dll", EntryPoint ="FindWindow", SetLastError =true)] -          Public Static externIntPtr FindWindow (stringLpclassname,stringlpwindowname); the          Public voidShade () +         { AConsole.title ="Consolewin"; theIntPtr cwinptr = FindWindow ("Consolewindowclass","Consolewin"); +             if(Cwinptr! =IntPtr.Zero) -             { $ShowWindow (Cwinptr,0); $             } -         } -     } the  - ///multi-threaded implementations, closed to the MessageBox or other forms;Wuyi  the usingSystem.Threading;//multithreading is necessary.  -  Wu  Public Static classmultithread -     { About          Public Static voidDoWork () $         {    -             -ThreadPool.QueueUserWorkItem (NewWaitCallback (s = = { -                  while(true) A                 { +Searchwindow SSS =NewSearchwindow (); the                     //Thread.Sleep ($); -s =NULL; $Sss.closewindow ("DidiSoft.Pgp.PGPLib","Didisoft OpenPGP Library for. NET");  the                 } the             })); the         } the}
View Code

Introduction to Usage:

1 "Call multithread. Dowork ();

2 "This popup box before calling MessageBox.Show (" message "," title "));

3 "Because the popup box blocks the main thread. So the other thread calls to be started before the main thread, so that he has been inquiring the main thread. To get a handle.

Tip: This is the use of Open source PGP encryption file, it has a time to verify, particularly troublesome, so just think about it, a draw off the popup box. Thank you!

Gets the handle of the popup box, closes the popup box

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.