RegisterHotKey throwing tantrum

This is a discussion on RegisterHotKey throwing tantrum within the Windows Programming forums, part of the Platform Specific Boards category; I'm looking for advance here with RegisterHotKey. It's a general function call that looks like this: Code: if (! ::RegisterHotKey(MsgDlg.m_hWnd, ...

  1. #1
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,428

    RegisterHotKey throwing tantrum

    I'm looking for advance here with RegisterHotKey. It's a general function call that looks like this:

    Code:
    if (! ::RegisterHotKey(MsgDlg.m_hWnd, m_nId, sModifier, sKey) )
    However, MsgDlg was created and on a different thread simply because that thread is running the message loop. RegisterHotKey won't let me register a hotkey for a dialog that was created on a different thread (which is a pretty stupid thing to restrict).
    So I'm looking for advance on how to make this doable. Do I have to go around by sending an event to the dialog and calling RegisterHotKey from there?
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  2. #2
    Registered User Codeplug's Avatar
    Join Date
    Mar 2003
    Posts
    4,648
    Since the hotkey is for MsgDlg, then wouldn't it make sense for that dialog code to handle registration? And to ensure it's done on the creating/message-loop thread, you could add a public member function that simply posts a message to itself.

    gg

  3. #3
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,428
    The MsgDlg is just a window running in the background to accept events such as messages from Shell_NotifyIcon.
    It's a window in a utility DLL used to build a framework around API functions, so it isn't really possible to do it that way...

    Code:
    void AddTrayIcon(const CString& strToolTip, const CString& strBalloonTip, const CString& strBalloonTitle, HICON hIcon, UINT nTimeOut, CTrayCallbacks Callbacks)
    {
    	// ...
    	traydata.hWnd = MsgDlg.m_hWnd; // hOwner;
    	// ...
    	MsgDlg.m_TrayCallbacks = Callbacks;
    	Shell_NotifyIcon(NIM_ADD, &traydata);
    	Shell_NotifyIcon(NIM_SETVERSION, &traydata);
    }
    Code:
    CHotKey::CHotKey(int nId, uint32_t sModifier, uint32_t sKey, pp<CCallback> HotkeyCallback): m_nId(nId)
    {
    	if (! ::RegisterHotKey(MsgDlg.m_hWnd, m_nId, sModifier, sKey) )
    	{
    		TRACE("WARNING! RegisterHotKey failed with:\nError: 0x%X\nDescription: %s", GetLastError(), ErrDescFromHRESULT( GetLastError() ));
    		DebugBreak();
    	}
    	MsgDlg.m_HotkeyCallback = HotkeyCallback;
    }
    Code:
    class AFX_EXT_CLASS CHotKey
    Last edited by Elysia; 03-14-2008 at 11:45 AM.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 11
    Last Post: 07-10-2008, 04:09 PM
  2. CRecordset::Open() is throwing an exception
    By cpjust in forum Windows Programming
    Replies: 1
    Last Post: 02-13-2008, 11:15 AM
  3. Strange, crysis game disables RegisterHotkey functionality
    By elmutt in forum Windows Programming
    Replies: 0
    Last Post: 11-24-2007, 04:38 PM
  4. throwing structures
    By subdene in forum C++ Programming
    Replies: 7
    Last Post: 08-08-2004, 04:26 PM
  5. help, throwing exception from constructor
    By terracota in forum C++ Programming
    Replies: 5
    Last Post: 07-02-2004, 05:44 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21