Pop-up killer (bottom)

Source: Internet
Author: User

Registration System hotkey
System hotkeys are very useful for applications such as pop-up killer. Ctrl + Shift + J is the default hotkey.
 
Speaking of implementation, we continue to use RegisterHotkey (HWND hWnd, int id, UINT fsModifiers, UINT vkey). The Code is as follows:

Public void SetHotKey (Keys c, bool bCtrl, bool bShift, bool bAlt, bool bWindows)
{
M_hotkey = c;
M_ctrlhotkey = bCtrl;
M_shifthotkey = bShift;
M_althotkey = bAlt;
M_winhotkey = bWindows;
 
// Update hotkey
NativeWIN32.KeyModifiers modifiers = NativeWIN32.KeyModifiers. None;
If (m_ctrlhotkey)
Modifiers | = NativeWIN32.KeyModifiers. Control;
If (m_shifthotkey)
Modifiers | = NativeWIN32.KeyModifiers. Shift;
If (m_althotkey)
Modifiers | = NativeWIN32.KeyModifiers. Alt;
If (m_winhotkey)
Modifiers | = NativeWIN32.KeyModifiers. Windows;
 
NativeWIN32.RegisterHotKey (Handle, 100, modifiers, m_hotkey); // Keys. J );
}
Generally, it takes a few steps to register the hotkey.

/* ------- Using HOTKEYs in a C # application -------
 
-- Code snippet by James J Thompson --
 
In Form load: Ctrl + Shift + J
 
Bool success = RegisterHotKey (Handle,
100,
KeyModifiers. Control | KeyModifiers. Shift,
Keys. J );
 
 
In form closing:
 
UnregisterHotKey (Handle, 100 );
 
 
How to handle hotkeys:
 
Protected override void WndProc (ref Message m)
{
Const int WM_HOTKEY = 0x0312;

Switch (m. Msg)
{
Case WM_HOTKEY:

MessageBox. Show ("Hotkey pressed ");
 
ProcessHotkey ();
 
Break;
}
Base. WndProc (ref m );
}
 
 
Public class NativeWIN32
{
[DllImport ("user32.dll", SetLastError = true)]
Public static extern bool RegisterHotKey (IntPtr hWnd, // handle to window
Int id, // hot key identifier
KeyModifiers fsModifiers, // key-modifier options
Keys vk // virtual-key code
);

[DllImport ("user32.dll", SetLastError = true)]
Public static extern bool UnregisterHotKey (IntPtr hWnd, // handle to window
Int id // hot key identifier
);
 
[Flags ()]
Public enum KeyModifiers
{
None = 0,
Alt = 1,
Control = 2,
Shift = 4,
Windows = 8
}
 
}
 
------- Using HOTKEYs in a C # application -------*/
 
After pressing the hot key, the process is as follows: first, use HWND GetForegroundWindow () to obtain the form, and then capture the Form title, GetWindowText (HWND hwnd,/* out */LPTSTR lpString, int nMaxCount ). the details are as follows:

 

Protected void ProcessHotkey ()
{
IntPtr hwnd = NativeWIN32.GetForegroundWindow ();
If (! Hwnd. Equals (IntPtr. Zero ))
{
NativeWIN32.STRINGBUFFER sWindowTitle;
NativeWIN32.GetWindowText (hwnd, out sWindowTitle, 256 );
 
If (sWindowTitle. szText. Length> 0)
AddWindowTitle (sWindowTitle. szText); // add to the ListView (Form)
}
}
 

Code download: http://www.codeproject.com/useritems/popupkiller/popupkiller_src_update.zip

Demo: http://www.codeproject.com/useritems/popupkiller/popupkiller_demo_update.zip

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.