Home All Groups Group Topic Archive Search About

Registering hot-keys for your Winform

Author
27 Jun 2006 8:58 AM
Water Cooler v2
I want to register a hotkey for my WinForm so that when I hold the,
say, Alt+M keys, it minimizes. How do I do that?

Author
27 Jun 2006 10:20 AM
Simon Verona
I found the easiest way is to create a menu item to do this and then link
the "hot key" to the menu item.

HTH
Simon

--
================================
Simon Verona
Dealer Management Service Ltd
Stewart House
Centurion Business Park
Julian Way
Sheffield
S9 1GD

Tel: 0870 080 2300
Fax: 0870 735 0011

Show quoteHide quote
"Water Cooler v2" <wtr_***@yahoo.com> wrote in message
news:1151398725.694494.211400@75g2000cwc.googlegroups.com...
>I want to register a hotkey for my WinForm so that when I hold the,
> say, Alt+M keys, it minimizes. How do I do that?
>
Author
27 Jun 2006 10:36 AM
Herfried K. Wagner [MVP]
"Simon Verona" <nom***@nomail.zzz> schrieb:
>I found the easiest way is to create a menu item to do this and then link
> the "hot key" to the menu item.

ACK.  Note that the menu item doesn't necessarily need to be visible.

--
M S   Herfried K. Wagner
M V P  <URL:http://dotnet.mvps.org/>
V B   <URL:http://classicvb.org/petition/>
Author
27 Jun 2006 10:57 AM
Water Cooler v2
Thanks! That is a nice tip I will surely use in the future. For now,
I'll be using the Win32 API to register the hotkey that is system-wide
because this menu-item solution, I believe:

1. Will not be system-wide; and
2. Will not be able to restore the form once minimized.

But a great tip I never thought of, really. Thanks a lot.



Another related question:

I've seen examples that use RegisterHotKey API without a global atom
and some that do add a global atom for the key in the Global Atom
database. Would someone tell me whether it is absolutely necessary to
have a global atom for the hotkey? If not, what is the difference
between the two approaches.
Author
28 Jun 2006 7:34 AM
M. Posseth
Look at Francesco`s article regrding this
http://www.dotnet2themax.com/ShowContent.aspx?ID=103cca7a-0323-47eb-b210-c2bb7075ba78


the attom thingy well he tells it here :

"you need to install the hotkey, which you do by calling the RegisterHotKey
API function: this function takes a unique id, and MSDN docs explain that you
should call GlobalAddAtom to get such an id. Besides, you must store this id
in a form variable, because you need it later, to unregister the class and
delete the global atom you created"

so someone using the   RegisterHotKey API function without the use of a
doesn`t follow the MSDN rule for getting the unique id  or doesn`t care about
a good cleanup routine  ( or isn`t aware that he should call GlobalAddAtom to
get such an id )


regards

Michel Posseth [MCP]





Show quoteHide quote
"Water Cooler v2" wrote:

> Thanks! That is a nice tip I will surely use in the future. For now,
> I'll be using the Win32 API to register the hotkey that is system-wide
> because this menu-item solution, I believe:
>
> 1. Will not be system-wide; and
> 2. Will not be able to restore the form once minimized.
>
> But a great tip I never thought of, really. Thanks a lot.
>
>
>
> Another related question:
>
> I've seen examples that use RegisterHotKey API without a global atom
> and some that do add a global atom for the key in the Global Atom
> database. Would someone tell me whether it is absolutely necessary to
> have a global atom for the hotkey? If not, what is the difference
> between the two approaches.
>
>