能邦我,我太感谢您了。请进来吧,关于98和2000中的EnumChildWindows函数的疑问?(50分)

  • 主题发起人 主题发起人 yypeng
  • 开始时间 开始时间
Y

yypeng

Unregistered / Unconfirmed
GUEST, unregistred user!
我想让另一个程序的combobox改变值,想用此函数找到那个窗口的combobox,然后模拟点击下键,来选择值,并按回车确认。这个函数我在98下完全可以通过,但在2000下就不行了,调试它发现它只执行一次,就是只能取得所给窗口句柄中的第一个控件句柄就退出了,所以程序不能够找到那个combobox句柄,我不知道这个函数在98下和在2000下有什么不同?请各位大侠能够告诉我。我起初还以为我的2000不行,换了台机器,依然是这样,我想,这可能是此函数在98中和2000中不一样,                             请各位大侠给小生讲解一下为什么吧!  太感谢了。。。。。。。。。。。function &nbsp;EnumChildWndProc(AhWnd:HWnd;<br>&nbsp;AlParam:lParam):boolean;stdcall;<br>var<br>&nbsp;WndClassName: array[0..254] of Char;<br>&nbsp;TXT:STRING;<br>&nbsp;Hwnd,h1: THandle;<br>&nbsp;Text: string;<br>&nbsp;Count: Integer;<br>begin<br>&nbsp;GetClassName(AhWnd,wndClassName,255);<br>&nbsp;if pos('COMBOBOX',uppercase(strpas(wndclassname)))&gt;0 then<br>&nbsp;begin<br>&nbsp; &nbsp;Count := SendMessage(AHwnd, CB_GETCOUNT, 0, 0);<br>&nbsp; &nbsp;IF COUNT=4 THEN<br>&nbsp; &nbsp;BEGIN<br>&nbsp; &nbsp; &nbsp; &nbsp;SENDMESSAGE(aHWND,WM_KEYDOWN,VK_DOWN,0);<br>&nbsp; &nbsp; &nbsp; &nbsp;SENDMESSAGE(aHWND,WM_KEYDOWN,VK_DOWN,0);<br>&nbsp; &nbsp; &nbsp; &nbsp;SENDMESSAGE(AHWND,WM_KEYDOWN,VK_RETURN,0);<br>&nbsp; &nbsp;END;<br>&nbsp; end;<br><br>&nbsp;if Pos('EDIT',uppercase(strpas(wndclassname)))&gt;0 then<br>&nbsp; &nbsp; &nbsp;sendmessage(ahwnd,wm_settext,0,longint(pchar(apppath+'tmp')));<br>end;
 
To continue enumeration, the callback function must return TRUE; to stop enumeration, it must return FALSE.
 
EnumChildWndProc(AhWnd:HWnd;<br>&nbsp;AlParam:lParam):boolean;stdcall;<br>var<br>&nbsp;WndClassName: array[0..254] of Char;<br>&nbsp;TXT:STRING;<br>&nbsp;Hwnd,h1: THandle;<br>&nbsp;Text: string;<br>&nbsp;Count: Integer;<br>begin<br>&nbsp;GetClassName(AhWnd,wndClassName,255);<br>&nbsp;if pos('COMBOBOX',uppercase(strpas(wndclassname)))&gt;0 then<br>&nbsp;begin<br>&nbsp; &nbsp;Count := SendMessage(AHwnd, CB_GETCOUNT, 0, 0);<br>&nbsp; &nbsp;IF COUNT=4 THEN<br>&nbsp; &nbsp;BEGIN<br>&nbsp; &nbsp; &nbsp; &nbsp;SENDMESSAGE(aHWND,WM_KEYDOWN,VK_DOWN,0);<br>&nbsp; &nbsp; &nbsp; &nbsp;SENDMESSAGE(aHWND,WM_KEYDOWN,VK_DOWN,0);<br>&nbsp; &nbsp; &nbsp; &nbsp;SENDMESSAGE(AHWND,WM_KEYDOWN,VK_RETURN,0);<br>&nbsp; &nbsp;END;<br>&nbsp; end;<br><br>&nbsp;if Pos('EDIT',uppercase(strpas(wndclassname)))&gt;0 then<br>&nbsp; &nbsp; &nbsp;sendmessage(ahwnd,wm_settext,0,longint(pchar(apppath+'tmp')));<br>[red] &nbsp;Result := True;[/red]<br>end;
 
请看如下示例:<br><br>{our callback function prototype}<br>function EnumerateChildWindows(hWnd:HWND; lParam:LPARAM): BOOL; stdcall;<br><br>var<br>&nbsp; Form1: TForm1;<br><br>implementation<br><br>procedure TForm1.EnumerateChildWindows1Click(Sender: TObject);<br>begin<br>&nbsp; &nbsp;{empty our list box}<br>&nbsp; &nbsp;ListBox1.Items.Clear;<br><br>&nbsp; &nbsp;{enumerate all child windows belonging to Form1}<br>&nbsp; &nbsp;EnumChildWindows(Form1.Handle,@EnumerateChildWindows,0);<br><br>end;<br><br>{these steps execute for every child window belonging to the parent}<br>function EnumerateChildWindows(hWnd: HWND; lParam: LPARAM): BOOL;<br>var<br>&nbsp; &nbsp;ClassName: Array[0..255] of char; &nbsp;// this holds the class name of our child windows<br>begin<br>&nbsp; &nbsp;{get the class name of the given child window}<br>&nbsp; &nbsp;GetClassName(hWnd,ClassName,255);<br><br>&nbsp; &nbsp;{display it in the list box}<br>&nbsp; &nbsp;Form1.ListBox1.Items.Add(ClassName);<br><br><br>&nbsp; &nbsp;{continue enumeration}<br>&nbsp; &nbsp;Result:=TRUE;<br>end;
 
详细请看:<br>http://www.delphibbs.com/delphibbs/dispq.asp?lid=819474
 
谢谢两位的帮助,是我不对,没有多看英文说明,不过,我的E文的确很差,再次感谢!
 
后退
顶部