//先取得这个程序的主窗口句柄,根据句柄枚举子窗口,或子窗口的子窗口,找到button<br>http://www.delphibbs.com/keylife/images/u196832/AdvWNDView06-13.rar <br>窗口查看程序<br>这个程序中的代码是:<br>procedure EnumChildWindows(Parent: HWND);<br> function EChildProc(ChWnd: HWND; lParam: LPARAM): BOOL; stdcall;<br> var<br> sClassName: array [0..254] of Char;<br> Buf: PChar;<br> Len: Integer;<br> A: TListItem;<br> Rect: TRect;<br> begin<br> if ChWnd <> 0 then<br> begin<br> Windows.GetClassName(ChWnd, sClassName, SizeOf(sClassName));<br> A := fm_tasker.LV_ChildWind.Items.Add;<br> A.Caption := Format('%8.8x', [ChWnd]);<br> <br> if Windows.IsWindowEnabled(ChWnd) then<br> A.SubItems.AddObject('True', Pointer(ChWnd))<br> else A.SubItems.AddObject('False', Pointer(ChWnd));<br><br> A.SubItems.Add(Format('%s', [sClassName]));<br> Len := SendMessage(ChWnd, WM_GETTEXTLENGTH, 0, 0) + 1;<br> GetMem(Buf, Len);<br> SendMessage(ChWnd, WM_GETTEXT, Len, Longint(Buf));<br> if Windows.lstrlen(Buf) > 0 then<br> A.SubItems.Add(Buf)<br> else A.SubItems.Add('');<br> FreeMem(Buf, Len);<br> A.SubItems.Add(Format('%8.8x', [lParam]));<br> Windows.GetWindowRect(ChWnd, Rect);<br> A.SubItems.Add(Format('X:%d Y:%d W:%d H:%d', [Rect.Left, Rect.Top, Rect.Right - Rect.Left, Rect.Bottom - Rect.Top]));<br> //MenuItemToTreeNode(GetMenu(ChWnd), fm_tasker.TV_Menu, nil);<br> end;<br> Result := True;<br> end;<br>begin<br><br> fm_tasker.TV_Menu.Items.Clear;<br> fm_tasker.TV_Menu.Tag := Parent;<br> MenuItemToTreeNode(GetMenu(Parent), fm_tasker.TV_Menu, nil);<br> MenuItemToTreeNode(GetSystemMenu(Parent, False), fm_tasker.TV_Menu, nil, True);<br><br> fm_tasker.LV_ChildWind.Clear;<br> fm_tasker.LV_ChildWind.Items.BeginUpdate;<br> Windows.EnumChildWindows(Parent, @EChildProc, Parent);<br> fm_tasker.LV_ChildWind.Items.EndUpdate;<br>end;<br><br>窗口操作:<br>3: begin // 最大化<br> // SetForegroundWindow(H);<br> ShowWindow(H, SW_MAXIMIZE);<br> end;<br> 4: begin // 最小化<br> // SetForegroundWindow(H);<br> ShowWindow(H, SW_MINIMIZE);<br> end;<br> 5: begin //单击<br> SendMessage(H, WM_LBUTTONDOWN, 0, 0);<br> SendMessage(H, WM_LBUTTONUP, 0, 0);<br> end;<br> 6: // 双击<br> SendMessage(H, WM_LBUTTONDBLCLK, 0, 0);<br> 7: begin // 右击<br> SendMessage(H, WM_RBUTTONDOWN, 0, 0);<br> SendMessage(H, WM_RBUTTONUP, 0, 0);<br> end;<br> 8: begin // Enabled<br> En := not Windows.IsWindowEnabled(H);<br> Windows.EnableWindow(H, En);<br> if AppMenu.PopupComponent = LV_Child_HWND then<br> EnumWindow(StrToInt(LV_Child_HWND.Selected.Caption))<br> else if AppMenu.PopupComponent = LV_ChildWind then<br> EnumChildWindows(THandle(LV_Child_HWND.Selected.SubItems.Objects[0]));<br> end;<br> 9: begin // Enabled<br> En := not Windows.IsWindowVisible(H);<br> Windows.ShowWindow(H, SWCOMMAD[En]);<br> if AppMenu.PopupComponent = LV_Child_HWND then<br> EnumWindow(StrToInt(LV_Child_HWND.Selected.Caption))<br> else if AppMenu.PopupComponent = LV_ChildWind then<br> EnumChildWindows(THandle(LV_Child_HWND.Selected.SubItems.Objects[0]));<br> end;