问题描述
usingSystem;usingSystem.Collections.Generic;usingSystem.ComponentModel;usingSystem.Data;usingSystem.Drawing;usingSystem.Linq;usingSystem.Text;usingSystem.Windows.Forms;usingSystem.Runtime.InteropServices;namespaceWindowsFormsApplication17{publicpartialclassForm1:Form{publicForm1(){InitializeComponent();}[DllImport("user32.dll")]staticexternIntPtrFindWindow(stringstrClass,stringstrWindow);[DllImport("user32.dll")]staticexternIntPtrFindWindowEx(IntPtrhwndParent,IntPtrhwndChildAfter,stringstrClass,stringstrWindow);[DllImport("user32.dll",EntryPoint="SendMessage")]privatestaticexternintSendMessage(IntPtrHwnd,intwMsg,intdwFlags,intdwExtraInfo);privateIntPtrSubFindWindowEx(IntPtrhwnd){IntPtrfindHwnd=FindWindowEx(hwnd,IntPtr.Zero,"CtrlNotifySink","");if(findHwnd!=IntPtr.Zero){IntPtrnoHwnd=FindWindowEx(findHwnd,IntPtr.Zero,"Button","否(&N)");if(noHwnd!=IntPtr.Zero){returnnoHwnd;}else{returnFindWindowEx(hwnd,IntPtr.Zero,"CtrlNotifySink","");}}returnIntPtr.Zero;}privatevoidbutton2_Click(objectsender,EventArgse){constintBM_CLICK=0xF5;IntPtrmaindHwnd=FindWindow(null,"注册表编辑器");IntPtrDirectUIHWND=FindWindowEx(maindHwnd,IntPtr.Zero,"DirectUIHWND","");IntPtrnoHwnd=SubFindWindowEx(DirectUIHWND);if(noHwnd!=IntPtr.Zero){SendMessage(noHwnd,BM_CLICK,0,0);}else{MessageBox.Show("没有找到No按钮");}}}}
这个模拟按键是,在运行了一个.reg文件时,弹出一个对话框的“否”按钮发送鼠标单击可是,findwindowex可以找到button,但是sendmesssage好像无效,大家帮忙看看问题在哪里?
解决方案
解决方案二:
加个断点,看下执行了没