1. EnumWindowsProc에서 실행되어 있는 윈도우들의 핸들을 구하고
2. GetClassName에서 Class이름을 구하려고 하는데요...
showmesage(GetClassName(Handle))하면
Exploer - 'IEFram', 메모장 - 'Notepad'식으로 제가 원하는 값이지만.
일반 응용프로그램(델파이나 다른 비쥬얼 툴로 작성한 것)들은 폼이름을 MainForm으로
해도 TApplication이 출력됩니다..
제가 원하는 것은 TApplication이 아니라 TMainForm과 같은 값이 출력되는 겁니다.
spy에서 보면 잘 나오는데..GetClassName에서는 TApplication만 출력이 되는군요...
제 소스는 다음과 같습니다......
-----------------------------------------------------------------------------
function EnumWindowsProc(Wnd: HWND; lb: TListbox): BOOL; stdcall;
var
caption: Array [0..128] of Char;
begin
Result := True;
if //skip invisible windows
IsWindowVisible(Wnd) and
//only process truly top-level windows. GetWindowLong must be used, not GetParent
((GetWindowLong(Wnd, GWL_HWNDPARENT) = 0) or
(HWND(GetWindowLong(Wnd, GWL_HWNDPARENT)) = GetDesktopWindow)) and
//skip WS_EX_TOOLWINDOW windows
((GetWindowLong(Wnd, GWL_EXSTYLE) and WS_EX_TOOLWINDOW) = 0) then
begin
SendMessage(Wnd, WM_GETTEXT, Sizeof(caption), integer(@caption));
lb.Items.AddObject(caption, TObject(Wnd));
end;
end;
function GetClassName(Wnd: HWnd): string;
var
Buf : array[0..128] of Char;
begin
if ((IsWindow(Wnd)) and (Windows.GetClassNameA(Wnd, Buf, SizeOf(Buf)) > 0)) then
Result := Buf
else
Result := '';
end;
Procedure TMainForm.FormCreate(Sender: TObject);
var
WinHandle : THandle;
fRect : TRect;
i : Integer;
begin
ListBox1.Clear;
EnumWindows(@EnumWindowsProc, Integer(ListBox1));
for i := 0 to ListBox1.Items.Count-1 do
begin
WinHandle := HWND(ListBox1.Items.Objects[i]);
ShowMessage(GetClassName(WinHandle));
// WinHandle := FindWindow('CabsinetWClass',nil);
// if WinHandle <= 0 then
// WinHandle := FindWindow('IEFrame',nil);
end; // end for
end;
TApplication으로 나오는 것이 정상입니다. 델파이 프로젝트를 만들때 메인 윈도우는
TApplication이고 이것의 서브윈도우로 메인폼을 비롯한 여러가지 폼들이 들어가게
됩니다. 이건 스파이프로그램으로 보셨다면 아실텐데요... TApplication의 핸들을
찾으셨다면 GetWindowEx를 이용해서 메인폼의 핸들을 찾으실 수 있습니다.
^^ 항상 즐코하세요...
나그네... wrote:
> 1. EnumWindowsProc에서 실행되어 있는 윈도우들의 핸들을 구하고
> 2. GetClassName에서 Class이름을 구하려고 하는데요...
>
> showmesage(GetClassName(Handle))하면
> Exploer - 'IEFram', 메모장 - 'Notepad'식으로 제가 원하는 값이지만.
> 일반 응용프로그램(델파이나 다른 비쥬얼 툴로 작성한 것)들은 폼이름을 MainForm으로
> 해도 TApplication이 출력됩니다..
> 제가 원하는 것은 TApplication이 아니라 TMainForm과 같은 값이 출력되는 겁니다.
>
> spy에서 보면 잘 나오는데..GetClassName에서는 TApplication만 출력이 되는군요...
>
> 제 소스는 다음과 같습니다......
> -----------------------------------------------------------------------------
> function EnumWindowsProc(Wnd: HWND; lb: TListbox): BOOL; stdcall;
> var
> caption: Array [0..128] of Char;
> begin
> Result := True;
> if //skip invisible windows
> IsWindowVisible(Wnd) and
> //only process truly top-level windows. GetWindowLong must be used, not GetParent
> ((GetWindowLong(Wnd, GWL_HWNDPARENT) = 0) or
> (HWND(GetWindowLong(Wnd, GWL_HWNDPARENT)) = GetDesktopWindow)) and
> //skip WS_EX_TOOLWINDOW windows
> ((GetWindowLong(Wnd, GWL_EXSTYLE) and WS_EX_TOOLWINDOW) = 0) then
> begin
> SendMessage(Wnd, WM_GETTEXT, Sizeof(caption), integer(@caption));
> lb.Items.AddObject(caption, TObject(Wnd));
> end;
> end;
>
> function GetClassName(Wnd: HWnd): string;
> var
> Buf : array[0..128] of Char;
> begin
> if ((IsWindow(Wnd)) and (Windows.GetClassNameA(Wnd, Buf, SizeOf(Buf)) > 0)) then
> Result := Buf
> else
> Result := '';
> end;
>
>
> Procedure TMainForm.FormCreate(Sender: TObject);
> var
> WinHandle : THandle;
> fRect : TRect;
> i : Integer;
> begin
> ListBox1.Clear;
> EnumWindows(@EnumWindowsProc, Integer(ListBox1));
>
> for i := 0 to ListBox1.Items.Count-1 do
> begin
> WinHandle := HWND(ListBox1.Items.Objects[i]);
>
> ShowMessage(GetClassName(WinHandle));
>
> // WinHandle := FindWindow('CabsinetWClass',nil);
> // if WinHandle <= 0 then
> // WinHandle := FindWindow('IEFrame',nil);
>
> end; // end for
> end;
>