Click here to Skip to main content
15,890,690 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hello Everyone again!
i had an idea to minimize or close my app when i press a key combo(like CTRL+E or something). Now i know how to minimize and close the app, i can do that either using the win api using the DestroyWindow method or the CloseWindow(this is to minimize the app) method
i also want to be able to press CTRl+B or some sort of key combo and bring the app to the front of the window stack(or window chain or whatever its called) i can do this by calling the BringWindowToTop method in the windows api
what i don't know how to do is how do i tell my app to execute those functions when a keyboard combo is pressed globally, or i should say when my app has focus or not.
i have a felling i will be referring to the win api and the User32.dll method list for this job right?(Gosh i hate using P/Invoke, its so complicated to use unmanned C++)
For the functions i want to do(like minimizing the window and bringing it to the front) i have imported the following methods:
C#
[DllImport("user32.dll")]
using System.Runtime.InteropServices;
public static extern void DestroyWindow(IntPtr hWnd);

[DllImport("user32.dll")]
public static extern void CloseWindow(IntPtr hWnd);

[DllImport("user32.dll")]
public static extern void BringWindowToTop(IntPtr hWnd);

thanks for all of your help in advance,
MasterCodeon
Posted
Updated 17-Dec-14 7:36am
v2
Comments
PIEBALDconsult 17-Dec-14 12:05pm    
Alt-F4 is standard. Simply set it as the shortcut of the Exit/Close/Whatever menu item.
MasterCodeon 17-Dec-14 12:13pm    
True but what about minimizing the app or Bringing it to the front with a keyboard shortcut?
Reply to the message. If you add new comment, user won't be notified.
MasterCodeon 17-Dec-14 13:53pm    
huh? what do you mean? i have setup my profile to not send me notifications.
Dude, I am asking you to reply to the message by PIEBALDconsult. :)

If you will add comment, he won't be notified. And I guess you are trying to reply him.

1 solution

 
Share this answer
 
Comments
Maciej Los 17-Dec-14 15:12pm    
Sergey, does OP really needs to use anything else than ALT+F4?
MasterCodeon 17-Dec-14 15:35pm    
ok why does everyone keep calling me OP?
what does that mean?
Maciej Los 17-Dec-14 15:38pm    
OP = Opponent ;)
MasterCodeon 17-Dec-14 15:47pm    
why is the term Opponent used here anyway?
Maciej Los 17-Dec-14 15:48pm    
Just kidding ;)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900