Autor Beitrag
BloodyBastard
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 22

FC1, Win XP
D6 Enterprise
BeitragVerfasst: Fr 17.09.04 13:52 
Hallo

Ich müsste bei einem Click wissen, was für ein Fenster sich unter dem Cursor befindet. Gibt es dafür bereits eine API funktion?? Wenn nein, welche würden sich dafür anbieten??

Danke bereits im Voraus.

Greetz
BloodyBastard

_________________
nix
toms
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 1099
Erhaltene Danke: 2



BeitragVerfasst: Fr 17.09.04 13:55 
BloodyBastard Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 22

FC1, Win XP
D6 Enterprise
BeitragVerfasst: Fr 17.09.04 13:57 
Oooh , das ging ja extrem schnel!! Ich danke dir!! Ich hoffe das geht auch, wenn das Window disabled ist... Naja, mal ausprobieren

_________________
nix
toms
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 1099
Erhaltene Danke: 2



BeitragVerfasst: Fr 17.09.04 16:35 
Zitat:
Ich hoffe das geht auch, wenn das Window disabled ist


Nein, geht nicht.


Ich (resp. Eugen) habe dafür mal einen Code geschrieben:

ausblenden volle Höhe Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:
70:
71:
72:
73:
74:
75:
76:
77:
78:
79:
80:
81:
82:
83:
84:
85:
86:
87:
88:
89:
90:
91:
92:
93:
94:
95:
96:
97:
98:
99:
100:
101:
102:
103:
104:
105:
106:
107:
108:
109:
110:
111:
112:
113:
114:
115:
116:
117:
118:
119:
120:
121:
122:
123:
124:
125:
126:
127:
128:
129:
130:
131:
132:
133:
function RealWindowFromPoint(pt: TPoint{$IFDEF RWFPCHOICE}; swinvis: boolean = true{$ENDIF}): HWND;
(*
  Functionality:
    This will get a windows handle from the position of the mouse, even if it is
    for example inside the area occupied by a groupbox.
    [GENERIC] It may be used as a substitute to "ChildWindowFromPoint" which
    however doesn't work as well as this one ;)

  Featured by Eugen, all credits go to him ...

  Corrected version (by Eugen) - should work on 9x now ;)
  I changed a few things more to have a more consistent behavior
*)

type
  PCHILDS_ENUM = ^CHILDS_ENUM;
  CHILDS_ENUM = record
    nDiff: integer;
    hWndFound: HWND;
    pt: TPoint;
   {$IFDEF RWFPCHOICE}
    showinvis: boolean;
   {$ENDIF RWFPCHOICE}
  end;

var
  ce: CHILDS_ENUM;

  function EnumProc(hwndChild: HWND; lParam: LPARAM): Boolean; stdcall;
  (*
    Functionality:
      This is the core of RealWindowFromPoint. It enumerates child windows of the
      window given by handle.
      [SPECIFIC] only useful in the context of this function.
  *)

  var
    rc: TRECT;
  begin
    GetWindowRect(hwndChild, rc);

    with PCHILDS_ENUM(lParam)^, rc do
    {$IFDEF RWFPCHOICE}
      case showinvis of
        true:
          if (pt.x >= Left) and (pt.x < Right) and (pt.y >= Top) and (pt.y < Bottom) and
            (nDiff > (Right - Left) + (Bottom - Top)) then
          begin
            hWndFound := hwndChild;
            nDiff := (Right - Left) + (Bottom - Top);
          end;
      else
        if (pt.x >= Left) and (pt.x < Right) and (pt.y >= Top) and (pt.y < Bottom) and
          (nDiff > (Right - Left) + (Bottom - Top)) and IsWindowVisible(hwndChild) then
        begin
          hWndFound := hwndChild;
          nDiff := (Right - Left) + (Bottom - Top);
        end;
      end;
     {$ELSE RWFPCHOICE}
      if (pt.x >= Left) and (pt.x < Right) and (pt.y >= Top) and (pt.y < Bottom) and
        (nDiff > (Right - Left) + (Bottom - Top)) then
      begin
        hWndFound := hwndChild;
        nDiff := (Right - Left) + (Bottom - Top);
      end;
    {$ENDIF RWFPCHOICE}
    Result := True;
  end;

begin
  ce.nDiff := MAXLONG;
  ce.hWndFound := WindowFromPoint(pt);
  ce.pt.x := pt.x; //sche***-w9x
  ce.pt.y := pt.y; //sche***-w9x
  {$IFDEF RWFPCHOICE}
  ce.showinvis := swinvis;
  {$ENDIF RWFPCHOICE}
  if (ce.hWndFound <> 0then
  begin
    // Windows 9x does not like NULL for a handle handed over to EnumChildWindows()
    // The NT platform treats this just like EnumWindows()
    if (GetWindowLong(ce.hWndFound, GWL_STYLE) and WS_CHILD <> 0then
      ce.hwndFound := GetParent(ce.hwndFound);
    EnumChildWindows(ce.hWndFound, @EnumProc, Integer(@ce));
  end;
  Result := ce.hwndFound;
end;

function _GetWindowText(Wnd: HWND): string;
var
  TextLn: Integer;
  StrBuf: PChar;
begin
  Result := '';
  TextLn := SendMessage(Wnd, WM_GETTEXTLENGTH, 00);
  if TextLn = 0 then
    Exit;
  GetMem(StrBuf, TextLn + 1);
  try
    SendMessage(Wnd, WM_GETTEXT, TextLn + 1, Integer(StrBuf));
    Result := StrBuf;
  finally
    FreeMem(StrBuf);
  end;
end;

function _GetClassName(Handle: Hwnd): string;
var
  ClassName: string;
begin
  SetLength(className, MAX_PATH);
  SetLength(className, GetClassName(Handle, pchar(className), MAX_PATH));
  Result := ClassName;
end;

procedure TForm1.Timer1Timer(Sender: TObject);
var
  C: Array[0..255of Char;
  h: hWnd;
  p: TPoint;
const
 {$j+} x: Integer= -1;
       y: Integer= -1;
 {$j-}
begin
  p := Mouse.CursorPos;
  if (p.x <> x) and (p.y <> y) then
  begin
    h := RealWindowFromPoint(Mouse.CursorPos);
    x := p.x;
    y := p.y;
    caption := _GetClassName(h) + '-' +_GetWindowText(h);
  end;
end;