Registering hot-keys for your Winform

  • Thread starter Thread starter Water Cooler v2
  • Start date Start date
W

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?
 
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
 
Simon Verona said:
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.
 
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.
 
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]
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Back
Top