求大神帮忙看下这样写的钩子是不是有问题

阿两sama 2013-05-07 02:31:47
LRESULT CALLBACK ShellHookProc(int nCode,WPARAM wParam,LPARAM lParam)
{
if (nCode>=0)// Windows Created
{
HWND hLastWins =FindWindow("#32770","询问");
HWND hLastWinss = FindWindowEx(hLastWins, 0,
"Static", NULL);
char title[200];
GetWindowText(hLastWinss, title, 200);
char *t=title;
char *pattern="小于成本";
char *patter="小于最低销售价";
char *isMatch1= strstr(t,pattern);
char *isMatch2= strstr(t,patter);
if(hLastWinss!=NULL)
{
if (isMatch1!=NULL||isMatch2!=NULL)
{
HWND hLastWin = FindWindowEx(hLastWins, 0,
"Button", "是(&Y)");
EnableWindow(hLastWin, false);
}
}

/*EnumWindows(EnumWindowsProc,0); */
}

return CallNextHookEx(g_hHookShell,nCode,wParam,lParam);
}

BOOL CQJHook1::SetHook()
{

g_hHookShell = SetWindowsHookEx(WH_CALLWNDPROC, ShellHookProc,glhInstance,0);

return g_hHookShell ? TRUE : FALSE;

}

BOOL CQJHook1::DestroyHook()
{
if (g_hHookShell == NULL)
{
return FALSE;
}

UnhookWindowsHookEx(g_hHookShell);
return TRUE;
}
CQJHook1::CQJHook1() //类构造函数
{
}

CQJHook1::~CQJHook1()
{
DestroyHook();
}

我这么写的可是不能实现找到相印的控件并禁用掉他,因为同一个程序中有很多名称相同的这个控件所以我先进行了判断,不判断是可以实现,但是所有的控件都被禁了,我只是想禁用掉特定的
...全文
160 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
赵4老师 2013-05-13
  • 打赏
  • 举报
回复
对DLL里的代码帖主没法进行调试?!那是帖主不会,到学习的时候啦: Methods for Debugging DLLs If you have the source for both the DLL and the calling program, open the project for the calling executable file and debug the DLL from there. If you load a DLL dynamically, you must specify it in the Additional DLLs category of the Debug tab in the Project Settings dialog box. If you have the source for the DLL only, open the project that builds the DLL. Use the Debug tab in the Project Settings dialog box to specify the executable file that calls the DLL. You can also debug a DLL without a project. For example, maybe you just picked up a DLL and source code but you don’t have an associated project or workspace. You can use the Open command on the File menu to select the .DLL file you want to debug. The debug information should be in either the .DLL or the related .PDB file. After Visual C++ opens the file, on the Build menu click Start Debug and Go to begin debugging. To debug a DLL using the project for the executable file 1. From the Project menu, click Settings. The Project Settings dialog box appears. 2. Choose the Debug tab. 3. In the Category drop-down list box, select General. 4. In the Program Arguments text box, type any command-line arguments required by the executable file. 5. In the Category drop-down list box, select Additional DLLs. 6. In the Local Name column, type the names of DLLs to debug. If you are debugging remotely, the Remote Name column appears. In this column, type the complete path for the remote module to map to the local module name. 7. In the Preload column, select the check box if you want to load the module before debugging begins. 8. Click OK to store the information in your project. 9. From the Build menu, click Start Debug and Go to start the debugger. You can set breakpoints in the DLL or the calling program. You can open a source file for the DLL and set breakpoints in that file, even though it is not a part of the executable file’s project. To debug a DLL using the project for the DLL 1. From the Project menu, click Settings. The Project Settings dialog box appears. 2. Choose the Debug tab. 3. In the Category drop-down list box, select General. 4. In the Executable For Debug Session text box, type the name of the executable file that calls the DLL. 5. In the Category list box, select Additional DLLs. 6. In the Local Module Name column, type the name of the DLLs you want to debug. 7. Click OK to store the information in your project. 8. Set breakpoints as required in your DLL source files or on function symbols in the DLL. 9. From the Build menu, click Start Debug and Go to start the debugger. To debug a DLL created with an external project 1. From the Project menu, click Settings. The Project Settings dialog box appears. 2. Choose the Debug tab. 3. In the Category drop-down list box, select General. 4. In the Executable For Debug Session text box, type the name of the DLL that your external makefile builds. 5. Click OK to store the information in your project. 6. Build a debug version of the DLL with symbolic debugging information, if you don’t already have one. 7. Follow one of the two procedures immediately preceding this one to debug the DLL.
阿两sama 2013-05-08
  • 打赏
  • 举报
回复
来顶顶别沉了
阿两sama 2013-05-08
  • 打赏
  • 举报
回复
引用 3 楼 zhao4zhong1 的回复:
单步调试和设断点调试是程序员必须掌握的技能之一。
事情是这样的,因为这是DLL里的代码我没法进行调试,我昨天用了一句一句注释的方法,发现当程序运行到GetWindowText(hLastWinss, title, 200);时也就是获取控件标题是就会死机,有没有办法解决,而且貌似我这样写也获取不到控件的标题,我要获取的是另外一个程序中某一窗口控件的标题。我这么写是不是有问题,因为我没学过C++所以请大家多多指教
赵4老师 2013-05-07
  • 打赏
  • 举报
回复
单步调试和设断点调试是程序员必须掌握的技能之一。
阿两sama 2013-05-07
  • 打赏
  • 举报
回复
在顶顶看有人来没
阿两sama 2013-05-07
  • 打赏
  • 举报
回复
来个人帮我看看啊
内容概要:本文提出了一种基于非合作博弈理论的居民负荷分层调度模型,并结合双层鲸鱼优化算法(Two-level Whale Optimization Algorithm)进行高效解,模型与算法均通过Matlab代码实现。研究针对电力系统中居民侧用电负荷的复杂调度问题,引入非合作博弈机制刻画各用户之间的利益竞争关系,实现负荷的分层优化分配;同时设计双层优化架构,上层优化资源配置,下层模拟用户自主决策行为,提升了模型的实用性与合理性。通过智能优化算法解多层级、非凸非线性的博弈模型,有效提高了调度方案的收敛性与全局寻优能力,适用于现代智能电网中的需侧管理与能源优化场景。; 适合人群:具备电力系统基础理论知识和Matlab编程能力,从事智能电网、能源优化调度、需侧管理、博弈论应用等方向的科研人员、高校研究生及工程技术人员。; 使用场景及目标:①应用于居民区电力负荷的分层优化调度系统设计与仿真分析;②为非合作博弈在多主体能源系统建模中的应用提供方法论支持;③利用双层鲸鱼算法解决具有嵌套结构的复杂双层优化问题,提升解效率与调度方案的可行性。; 阅读建议:建议读者结合提供的Matlab代码深入理解模型构建逻辑与算法实现流程,重点关注博弈模型的效用函数设计、纳什均衡解思路以及双层优化结构的迭代机制,宜配合实际用电数据开展复现实验以验证模型有效性与鲁棒性。
内容概要:本文围绕基于自适应神经模糊推理系统(ANFIS)智能控制器的可再生能源微电网功率管理系统展开研究,结合Simulink仿真实现,深入探讨了微电网中功率的智能调控与经济机组组合调度问题。通过引入ANFIS控制器,有效应对风能、光伏等可再生能源出力的波动性与不确定性,提升系统运行的稳定性与电能质量。研究内容涵盖微电网多源协调控制策略、功率平衡管理、优化调度模型构建及仿真验证,实现了对分布式电源、储能系统和负荷的协同优化,兼顾经济性与可靠性目标,并通过仿真平台验证了所提方法的有效性与优越性。; 适合人群:具备电力系统、自动化或新能源相关专业背景,熟悉Matlab/Simulink仿真环境,从事微电网能量管理、智能控制、能源优化等领域研究的研究生、科研人员及工程技术人员。; 使用场景及目标:①用于高比例可再生能源接入场景下的微电网能量管理系统研发与教学实践;②为实现微电网功率稳定控制与经济高效运行提供先进的智能控制解决方案;③支撑高水平学术论文复现、科研课题攻关及实际工程项目的仿真验证与方案优化。; 阅读建议:建议结合提供的Simulink模型与相关代码进行动手实践,重点关注ANFIS控制器的设计流程、规则库构建与参数调优方法,并通过与传统PID或MPC控制策略的对比实验,深入理解其在动态响应与鲁棒性方面的优势。同时可进一步拓展文中提出的优化调度逻辑,应用于多目标、多约束的复杂实际应用场景中。

65,210

社区成员

发帖
与我相关
我的任务
社区描述
C++ 语言相关问题讨论,技术干货分享,前沿动态等
c++ 技术论坛(原bbs)
社区管理员
  • C++ 语言社区
  • encoderlee
  • paschen
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
  1. 请不要发布与C++技术无关的贴子
  2. 请不要发布与技术无关的招聘、广告的帖子
  3. 请尽可能的描述清楚你的问题,如果涉及到代码请尽可能的格式化一下

试试用AI创作助手写篇文章吧