无悔今生
2010-04-22, 21:12:10
帮看看下边的DLL程序,我只想禁止打开指定的窗口,而不是全部的,但使用下边的程序后,全部的窗口打不开,要怎样改呢?
#include<windows.h>
extern "C"__declspec(dllexport) void sethook(char *s);//s指要禁止打开的窗口名字
extern "C"__declspec(dllexport) void stophook();
HHOOK hook=NULL;
char title[255];
LRESULT CALLBACK CBTproc(int nCode,WPARAM wparam,LPARAM lparam)
{
if(nCode<0)
return CallNextHookEx(hook,nCode,wparam,lparam);
if(nCode==HCBT_CREATEWND)
{
HWND hwnd;
char _title[255];
hwnd=(HWND)wparam;
GetWindowText(hwnd,_title,sizeof(_title));
if(strcmp(title,_title)==0)
{
MessageBox(NULL,"不能打开该应用程序!","错误",0);
return 1;
}
return CallNextHookEx(hook,nCode,wparam,lparam);
}
return CallNextHookEx(hook,nCode,wparam,lparam);
}
void sethook(char *s)
{
if(strlen(s)==0)
return;
else
{
strcpy(title,s);
if(hook==NULL)
hook=SetWindowsHookEx(WH_CBT,CBTproc,GetModuleHandle("STOPCREATE.dll"),0);
}
}
void stophook()
{
if(hook!=NULL)
UnhookWindowsHookEx(hook);
hook=NULL;
}
#include<windows.h>
extern "C"__declspec(dllexport) void sethook(char *s);//s指要禁止打开的窗口名字
extern "C"__declspec(dllexport) void stophook();
HHOOK hook=NULL;
char title[255];
LRESULT CALLBACK CBTproc(int nCode,WPARAM wparam,LPARAM lparam)
{
if(nCode<0)
return CallNextHookEx(hook,nCode,wparam,lparam);
if(nCode==HCBT_CREATEWND)
{
HWND hwnd;
char _title[255];
hwnd=(HWND)wparam;
GetWindowText(hwnd,_title,sizeof(_title));
if(strcmp(title,_title)==0)
{
MessageBox(NULL,"不能打开该应用程序!","错误",0);
return 1;
}
return CallNextHookEx(hook,nCode,wparam,lparam);
}
return CallNextHookEx(hook,nCode,wparam,lparam);
}
void sethook(char *s)
{
if(strlen(s)==0)
return;
else
{
strcpy(title,s);
if(hook==NULL)
hook=SetWindowsHookEx(WH_CBT,CBTproc,GetModuleHandle("STOPCREATE.dll"),0);
}
}
void stophook()
{
if(hook!=NULL)
UnhookWindowsHookEx(hook);
hook=NULL;
}