在CAboutDlg::OnInitDialog()中用RegisterHotKey(GetSafeHwn(),WM_SHOWHOTKEY,MOD_ALT|MOD_CONTROL,VK+F3)注册热键,然后在
CAboutDlg中增加函数
LRESULT CAboutDlg::OnHotKey(WPARAM wParam,LPARAM lParam)
{
....;
}
但运行时按下热键没有反应,调试时发现OnHotKey()没有被被调用,同时发现
int CWnd::GetDlgCtrlID() const
{
ASSERT(::IsWindow(m_hWnd));//此处报出“访问越界“的错误
     ......
}
而我在加入这些语句之前程序运行很正常
请问这是什么原因????

解决方案 »

  1.   

    你的程序中 RegisterHotKey 中 int id 参数不对,看看 msdn 这个 id 应该使用 GlobalAddAtom 分配。
      

  2.   

    添加消息映射
    ON_MESSAGE(WM_HOTKEY,OnHotkey)
      

  3.   

    1、第二个参数 id, 应该使用 GlobalAddAtom 分配
    2、原因应该是你的窗口还没有创建。
      

  4.   

    // 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...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 the helps.
      

  5.   

    谢谢大家了。
    我忘了添加消息映射,不过还有一个问题搞不懂,
    为何不添加消息映射会有如下的错误:
    int CWnd::GetDlgCtrlID() const
    {
    ASSERT(::IsWindow(m_hWnd));//此处报出“访问越界“的错误
         ......
    }
    望各位大虾不惜赐教。