Solved

RegisterHotKey examples ?

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

Thanks !
0
Comment
Question by:KAbbott
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
7 Comments
 
LVL 31

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 31

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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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 31

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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In days of old, returning something by value from a function in C++ was necessarily avoided because it would, invariably, involve one or even two copies of the object being created and potentially costly calls to a copy-constructor and destructor. A…
  Included as part of the C++ Standard Template Library (STL) is a collection of generic containers. Each of these containers serves a different purpose and has different pros and cons. It is often difficult to decide which container to use and …
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.

632 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