关于hook
我用hook做的 屏保程序
我CreateEx了一个窗口和桌面一样大 然后设了一个计时器 计时器一到就往这个窗口装个图片 前提是我这个窗口是最顶层的 然后我用钩子钩鼠标和键盘消息 钩到之后 杀死计时器 重新设直 可是在计时器没到的这段时间 我的鼠标不显示 就是不能做其他的操作
我想做其他的操作 代码如下:
BOOL CMyWnd::Create()
{
if(lpszClassName==NULL)
{
lpszClassName=AfxRegisterWndClass(CS_HREDRAW|CS_VREDRAW,
::LoadCursor(AfxGetResourceHandle(),MAKEINTRESOURCE(IDC_NOCURSOR)));
//注册类;IDC_NOCURSOR为新建光标的ID,这个光标没有任何图案
}
CRect rect(0, 0, ::GetSystemMetrics(SM_CXSCREEN),
::GetSystemMetrics(SM_CYSCREEN));
CreateEx(WS_EX_TOPMOST, lpszClassName, _T(""), WS_VISIBLE|WS_POPUP,
rect.left,rect.top,rect.right - rect.left, rect.bottom - rect.top,
GetSafeHwnd(), NULL, NULL); //创建一个全屏窗口
hw = GetSafeHwnd();
SetTimer(ID_TIMER, 5000, NULL);//计时器,ID_TIMER别忘了定义
return TRUE;
}
//为了防止同时运行两个相同的程序,下面两个函数是必需的
void CMyWnd::OnActivate(UINT nState, CWnd* pWndOther, BOOL bMinimized)
{
CWnd::OnActivate(nState,pWndOther,bMinimized);
if(nState==WA_INACTIVE)
PostMessage(WM_CLOSE);
}
void CMyWnd::OnActivateApp(BOOL bActive, HTASK hTask)
{
CWnd::OnActivateApp(bActive, hTask);
if(!bActive) //is being deactivated
PostMessage(WM_CLOSE);
}
void CMyWnd::DrawBitmap(CDC& dc)
{
CDC dcmem;
dcmem.CreateCompatibleDC(&dc);
CBitmap m_Bitmap;
m_Bitmap.LoadBitmap(IDB_BITMAP1);
dcmem.SelectObject(m_Bitmap);
dc.BitBlt(0,0,1024,768,&dcmem,0,0,SRCCOPY);
bshowwindow=FALSE;
}
void CMyWnd::OnTimer(UINT nIDEvent)
{
CClientDC dc(this);
DrawBitmap(dc);
}
int CMyWnd::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
if (CWnd::OnCreate(lpCreateStruct) == -1)
return -1;
// TODO: Add your specialized creation code here
hook=SetWindowsHookEx(WH_KEYBOARD , KeyProc , NULL , GetCurrentThreadId());
hookmouse=SetWindowsHookEx(WH_MOUSE , MouseProc , NULL , GetCurrentThreadId());
return 0;
}
LRESULT CALLBACK MouseProc(int nCode , WPARAM wParam , LPARAM lParam)
{
if(bshowwindow==FALSE)
{
SendMessage(hw , WM_CLOSE , 0 , 0 );
UnhookWindowsHookEx(hookmouse);
}
else
{
KillTimer(hw , ID_TIMER);
SetTimer(hw , ID_TIMER , 5000 , NULL);
}
return CallNextHookEx(hookmouse , nCode , wParam , lParam);
}
LRESULT CALLBACK KeyProc(int nCode , WPARAM wParam , LPARAM lParam)
{
if(wParam==VK_SPACE||bshowwindow==false)
{
SendMessage(hw , WM_CLOSE , 0 , 0 );
UnhookWindowsHookEx(hook);
}
else
{
KillTimer(hw , ID_TIMER);
SetTimer(hw , ID_TIMER , 5000 , NULL);
}
return 1;
}
请问我的Hook代码有什么问题啊?
CMyScreensaverApp::CMyScreensaverApp()
{
// TODO: add construction code here,
// Place all significant initialization in InitInstance
}
/////////////////////////////////////////////////////////////////////////////
// The one and only CMyScreensaverApp object
CMyScreensaverApp theApp;
/////////////////////////////////////////////////////////////////////////////
// CMyScreensaverApp initialization
BOOL CMyScreensaverApp::InitInstance()
{
AfxEnableControlContainer();
// Standard initialization
// If you are not using these features and wish to reduce the size
// of your final executable, you should remove from the following
// the specific initialization routines you do not need.
#ifdef _AFXDLL
Enable3dControls(); // Call this when using MFC in a shared DLL
#else
Enable3dControlsStatic(); // Call this when linking to MFC statically
#endif
//显示屏保窗口
CMyWnd* pWnd = new CMyWnd;
pWnd->Create();
m_pMainWnd = pWnd;
// Since the dialog has been closed, return FALSE so that we exit the
// application, rather than start the application's message pump.
return TRUE;
}
请高手帮忙 谢谢 在线等