自己定义的消息在主窗口没有被激活的情况下对消息的处理函数没有被调用 怎么处理?通宵在线等待!!!
/////////////////////////////////////////////////////////////////////////
HHOOK Hook;
HWND SrvHwnd;
#define WM_KEY_LL_EVENT WM_USER+102
LRESULT CALLBACK LaunchHook(int nCode,WPARAM wParam,LPARAM lParam);
//////////////////////////////////////////////////////////////////////////
//
// Note!
//
// If this DLL is dynamically linked against the MFC
// DLLs, any functions exported from this DLL which
// call into MFC must have the AFX_MANAGE_STATE macro
// added at the very beginning of the function.
//
// For example:
//
// extern "C" BOOL PASCAL EXPORT ExportedFunction()
// {
// AFX_MANAGE_STATE(AfxGetStaticModuleState());
// // normal function body here
// }
//
// It is very important that this macro appear in each
// function, prior to any calls into MFC. This means that
// it must appear as the first statement within the
// function, even before any object variable declarations
// as their constructors may generate calls into the MFC
// DLL.
//
// Please see MFC Technical Notes 33 and 58 for additional
// details.
//
/////////////////////////////////////////////////////////////////////////////
// CKeyBoardDllApp
BEGIN_MESSAGE_MAP(CKeyBoardDllApp, CWinApp)
//{{AFX_MSG_MAP(CKeyBoardDllApp)
// NOTE - the ClassWizard will add and remove mapping macros here.
// DO NOT EDIT what you see in these blocks of generated code!
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CKeyBoardDllApp construction
CKeyBoardDllApp::CKeyBoardDllApp()
{
// TODO: add construction code here,
// Place all significant initialization in InitInstance
}
/////////////////////////////////////////////////////////////////////////////
// The one and only CKeyBoardDllApp object
CKeyBoardDllApp theApp;
///////////////////////////////////////////////
DllExport void WINAPI InstallKeyBoardHook(HWND hWnd,DWORD dwThreadId){
//设置服务句柄
//公用句柄用于通讯
SrvHwnd=hWnd;
Hook=(HHOOK)SetWindowsHookEx(WH_KEYBOARD,(HOOKPROC)LaunchHook,theApp.m_hInstance,dwThreadId);
}
/////////////////////////////////////////////////////////////
DllExport void WINAPI UninstallKeyHook(){
UnhookWindowsHookEx(Hook);
}
//////////////////////////////////////////////
LRESULT CALLBACK LaunchHook(int nCode,WPARAM wParam,LPARAM lParam){
//简单的传入钩子和释放钩子
//发送程序到服务端触发键盘击键消息
if(nCode==HC_ACTION){
if(lParam&0x80000000){
::SendMessage(SrvHwnd,WM_KEY_LL_EVENT,wParam,lParam);
}
}
LRESULT lResult=CallNextHookEx(Hook,nCode,wParam,lParam);
return lResult;
}
////////////////////////////////////////////////////////////////////////////
::SendMessage(SrvHwnd,WM_KEY_LL_EVENT,wParam,lParam);向主窗体发送了
WM_KEY_LL_EVENT消息
/////////////////////////////////////////////
afx_msg LRESULT Play();
////////////////////////////////////////
ON_MESSAGE(WM_KEY_LL_EVENT, Play)
//////////////////////////////////////////////
Play函数是一个发出声音的函数,当把窗口最小化的时候程序没有作用.
我想在运行程序后,不管是什么时候,只要有按键就播放声音,应该怎么做.