Thread: RegisterHotKey throwing tantrum

  1. #1
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654

    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,981
    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をこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    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, 12:15 PM
  3. Strange, crysis game disables RegisterHotkey functionality
    By elmutt in forum Windows Programming
    Replies: 0
    Last Post: 11-24-2007, 05: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