一个关于sendmessage和postmessage 的问题(20分)

  • 主题发起人 主题发起人 xinxin0519
  • 开始时间 开始时间
X

xinxin0519

Unregistered / Unconfirmed
GUEST, unregistred user!
不好意思,小弟没有分了,小弟遇到一个问题,请各位大侠帮忙。我在自己的程序中打开显示属性,但是我没有办法在程序中从主题切换到设置中去,如果我用sendmessage和postmessage好象没有办法模拟方向键盘的操作。但是可以模拟TAB的操作,原代码如下:<br>unit Unit1;<br><br>interface<br><br>uses<br> &nbsp;Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,<br> &nbsp;Dialogs, StdCtrls;<br><br>type<br> &nbsp;TForm1 = class(TForm)<br> &nbsp; &nbsp;Memo1: TMemo;<br> &nbsp; &nbsp;btn_listwindow: TButton;<br> &nbsp; &nbsp;Button1: TButton;<br> &nbsp; &nbsp;Edit1: TEdit;<br> &nbsp; &nbsp;Label1: TLabel;<br> &nbsp; &nbsp;procedure btn_listwindowClick(Sender: TObject);<br> &nbsp;private<br> &nbsp; &nbsp;{ Private declarations }<br> &nbsp;public<br> &nbsp; &nbsp;{ Public declarations }<br> &nbsp;end;<br><br>var<br> &nbsp;Form1: TForm1;<br> &nbsp; function &nbsp;EnumChildWndProc(AhWnd:LongInt;<br> &nbsp; &nbsp;AlParam:lParam):boolean;stdcall;<br><br><br>implementation<br><br>{$R *.dfm}<br>function &nbsp;EnumChildWndProc(AhWnd:LongInt;<br> &nbsp;AlParam:lParam):boolean;stdcall;<br><br>var<br><br> &nbsp;WndClassName: array[0..254] of Char;<br> &nbsp;WndCaption: array[0..254] of Char;<br>begin<br> &nbsp;GetClassName(AhWnd,wndClassName,254);<br> &nbsp;GetWindowText(aHwnd,WndCaption,254);<br> &nbsp;with form1.memo1 do<br> &nbsp;begin<br> &nbsp; &nbsp;lines.add( string(wndClassName));<br> &nbsp; &nbsp;lines.add( string(wndCaption));<br> &nbsp; &nbsp;lines.add('-------');<br><br>if (string(WndCaption)='取消') &nbsp; then<br>begin<br> PostMessage(AhWnd,WM_KEYDOWN,VK_TAB,0);//<br> PostMessage(AhWnd,WM_KEYDOWN,VK_right,0);//这个地方 没有办法执行成功,没有反应 <br> &nbsp; end<br><br> &nbsp; &nbsp;end &nbsp;;<br> &nbsp;result:=true;<br><br>end;<br><br>procedure TForm1.btn_listwindowClick(Sender: TObject);<br><br>var<br> &nbsp;hWnd:LongInt;<br><br>begin<br> &nbsp; memo1.Lines.Clear;<br> &nbsp;Memo1.Lines.Add(Edit1.Text+' 有如下控件类名称');<br> &nbsp;hWnd:=FindWindow(nil,'显示 属性');<br> &nbsp;if hWnd&lt;&gt;0 then<br> &nbsp;begin<br><br> &nbsp; EnumChildWindows(hWnd,@EnumChildWndProc,0);<br> &nbsp;end<br> &nbsp;else &nbsp;MessageBox(self.handle,'没找到该窗口句柄','提示',0);<br>end;<br>end.<br><br>请各位大侠不要嫌分少,谢谢。
 
你何不直接用rundll32.exe shell32.dll,Control_RunDLL desk.cpl,,3 <br>显示设置
 
to tianliangle2003:<br> &nbsp; 这位大哥,你也许没有完全理解我的意思,是这样的,我可以打开显示设置,但是我需要知道如何在自己的程序中模拟键盘切换到设置页面。请赐教!谢谢!
 
鼠标移动(移动量dx,dy)<br>mouse_event(MOUSEEVENTF_MOVE,dx,dy,0, 0 );<br>鼠标在(x,y)处按下或释放<br>setcursorpos(x,y);<br>单击鼠标<br>mouse_event(MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0 );<br>mouse_event(MOUSEEVENTF_LEFTUP, 0, 0, 0, 0 );
 
unit Unit1;<br><br>interface<br><br>uses<br> &nbsp;Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,<br> &nbsp;Dialogs, StdCtrls,shellapi;<br><br>type<br> &nbsp;TForm1 = class(TForm)<br> &nbsp; &nbsp;Memo1: TMemo;<br> &nbsp; &nbsp;btn_listwindow: TButton;<br> &nbsp; &nbsp;Button1: TButton;<br> &nbsp; &nbsp;Edit1: TEdit;<br> &nbsp; &nbsp;Label1: TLabel;<br> &nbsp; &nbsp;procedure btn_listwindowClick(Sender: TObject);<br> &nbsp;private<br> &nbsp; &nbsp;{ Private declarations }<br> &nbsp;public<br> &nbsp; &nbsp;{ Public declarations }<br> &nbsp;end;<br><br>var<br> &nbsp;Form1: TForm1;<br> &nbsp; function &nbsp;EnumChildWndProc(AhWnd:LongInt;<br> &nbsp; &nbsp;AlParam:lParam):boolean;stdcall;<br><br><br>implementation<br><br>{$R *.dfm}<br>function &nbsp;EnumChildWndProc(AhWnd:LongInt;<br> &nbsp;AlParam:lParam):boolean;stdcall;<br><br>var<br>fwnd:thandle;<br> &nbsp;WndClassName: array[0..254] of Char;<br> &nbsp;WndCaption: array[0..254] of Char;<br>begin<br> &nbsp;<br> &nbsp;result:=true;<br><br> &nbsp;GetClassName(AhWnd,wndClassName,254);<br> &nbsp;GetWindowText(aHwnd,WndCaption,254);<br> &nbsp; with form1.memo1 do<br> &nbsp;begin<br> &nbsp; &nbsp;lines.add( string(wndClassName));<br> &nbsp; &nbsp;lines.add( string(wndCaption));<br> &nbsp; &nbsp;lines.add('-------');<br><br>if (string(WndCaption)='高级(&V)') &nbsp; then<br>begin<br> sendmessage(ahwnd,wm_lbuttondown,0,0);<br> &nbsp;sendmessage(ahwnd,wm_lbuttonup,0,0);<br>end<br><br> &nbsp; &nbsp;end &nbsp;;<br>end;<br><br>procedure TForm1.btn_listwindowClick(Sender: TObject);<br><br>var<br> &nbsp;hWnd:LongInt;<br><br>begin<br> &nbsp; memo1.Lines.Clear;<br> &nbsp; ShellExecute(0, 'open', 'rundll32.exe', 'shell32.dll,Control_RunDLL desk.cpl,,3', nil, SW_SHOWNORMAL);<br> &nbsp; sleep(1000);<br> &nbsp; Memo1.Lines.Add(Edit1.Text+' 有如下控件类名称');<br> &nbsp; hWnd:=FindWindow(nil,'显示 属性');<br> &nbsp; if hWnd&lt;&gt;0 then<br> &nbsp;begin<br> &nbsp; EnumChildWindows(hWnd,@EnumChildWndProc,0);<br> &nbsp;end<br> &nbsp;else &nbsp;MessageBox(self.handle,'没找到该窗口句柄','提示',0);<br>end;<br>end.<br>有个新的问题,当我用sendmessage 模拟鼠标在高级上面点 一下的时候,出现新的页面的时候我的程序就处于假死的状况,不知道是为什么?必须关掉新的页面才可以,请大虾们赐教。
 
to tianliangle2003:<br> &nbsp;老兄,如何确定其他程序控件的坐标,必须知道坐标才可以呀!
 
我知道如何做了,呵呵
 
接受答案了.
 
后退
顶部