Solved

RegisterHotKey examples ?

Posted on 2000-03-07
7
889 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 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
DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

 
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

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

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

Unlike C#, C++ doesn't have native support for sealing classes (so they cannot be sub-classed). At the cost of a virtual base class pointer it is possible to implement a pseudo sealing mechanism The trick is to virtually inherit from a base class…
Many modern programming languages support the concept of a property -- a class member that combines characteristics of both a data member and a method.  These are sometimes called "smart fields" because you can add logic that is applied automaticall…
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.

809 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