Solved

RegisterHotKey examples ?

Posted on 2000-03-07
7
881 Views
Last Modified: 2008-02-20
Anyone know where there are any full RegisterHotKey example's ??

Thanks !
0
Comment
Question by:KAbbott
  • 4
  • 3
7 Comments
 
LVL 30

Expert Comment

by:Zoppo
ID: 2595234
Hi KAbbott,

Do not know where you can find examples, but it's use is easy, i.e.:

// registering a hotkey, i.e. ALT-F6 as hot key
ATOM hotKeyAtom = AddGlobalAtom( "MyApp_Hotkey_F6" ); // MSDN suggest using of this to avoid conflicts with hot-key identifiers defined by other shared DLLs
if ( !RegisterHotKey( m_hWnd, hotKeyAtom, MOD_ALT, VK_F6 ) )
{
 TRACE( "Error occured with RegisterHotKey: %i\n", GetLastError() );
}


then you just have to handle the WM_HOTKEY message within you application and do there what you need...

hope that helps,

ZOPPO
0
 
LVL 2

Author Comment

by:KAbbott
ID: 2599713
Is it safe just to handle the message like this:

ON_MESSAGE(WM_HOTKEY, OnHotKey)

then in OnHotKey:

OnHotKey()
{
MessaageBox("HotKey Working...")
}

Is this the right why of doing this ?
0
 
LVL 30

Accepted Solution

by:
Zoppo earned 10 total points
ID: 2599778
Hi KAbbott,

you should pass the message's lParam and wParam to your function somehow like this:


// in class declaration (.h)
BEGIN_MESAGE_MAP(...)
....
afx_msg void OnHotKey( WPARAM wParam, LPARAM lParam );
//}}AFX_MSG
DECLARE_MESSAGE_MAP()

// in implementation (.cpp)
BEGIN_MESSAGE_MAP(...)
....
ON_MESSAGE( WM_HOTKEY, OnHotKey )
END_MESSAGE_MAP()

void
CAboutDlg::OnHotKey( WPARAM wParam, LPARAM lParam )
{
 UINT iHotKeyId = (UINT)wParam;
 UINT iOptions = (UINT)HIWORD( lParam );
 UINT iVKeyCode = (UINT)LOWORD( lParam );

 CString t;
 t.Format( "HotKey #%i pressed, (%i+%i)", iHotKeyId, iOptions, iVKeyCode );
 AfxMessageBox( t );
}


hope that helps,

ZOPPO
0
Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

 
LVL 2

Author Comment

by:KAbbott
ID: 2604424
Adjusted points to 10
0
 
LVL 2

Author Comment

by:KAbbott
ID: 2604425
Thanks for your help ZOPPO, and as I am called Zippy in the Half-Clan world, nice mame too.
0
 
LVL 30

Expert Comment

by:Zoppo
ID: 2604441
no problem      :)

what's a 'half-clan world'? Never heard that...

ZOPPO
0
 
LVL 2

Author Comment

by:KAbbott
ID: 2605721
Oops' I meant Half-Life (game) clan
0

Featured Post

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

When writing generic code, using template meta-programming techniques, it is sometimes useful to know if a type is convertible to another type. A good example of when this might be is if you are writing diagnostic instrumentation for code to generat…
IntroductionThis article is the second in a three part article series on the Visual Studio 2008 Debugger.  It provides tips in setting and using breakpoints. If not familiar with this debugger, you can find a basic introduction in the EE article loc…
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.

747 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now