Register shortcuts-display and hide windows

Source: Internet
Author: User
Register shortcuts-display and hide windows

// Register the hotkey API

[Dllimport ("USER32")]

Public static extern bool registerhotkey (intptr hwnd, int ID, uint control, keys VK );

// API for removing the registration hotkey
[Dllimport ("USER32")]
Public static extern bool unregisterhotkey (intptr hwnd, int ID );

Private void form1_load (Object sender, system. eventargs E)
{
Registerhotkey (this. Handle, 11, 2, keys. Q); // register the hotkey
Registerhotkey (this. Handle, 22, 2, keys. );
}

Private void form=formclosed (Object sender, formclosedeventargs E)
{
Unregisterhotkey (this. Handle, 11); // unregister the hotkey
Unregisterhotkey (this. Handle, 22 );
}

Protected override void wndproc (ref message m)
{
Switch (M. msg)
{
Case 0x0312: // hotkey message
If (M. wparam. tostring () = "11") // press Ctrl + Q to hide the window.
{
This. Hide ();
}
Else if (M. wparam. tostring () = "22") // press Ctrl + A to display the window
{
This. Visible = true;
}
Break;
}
Base. wndproc (ref m );
}

Related Article

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.