The FindWindow function retrieves a handle to the top-level window whose class name and window name match the specified strings. This function does not search child windows. This function does not perform a case-sensitive search.
HWND FindWindow(
LPCTSTR lpClassName, // pointer to class name
LPCTSTR lpWindowName // pointer to window name
);
Parameters
lpClassName
Pointer to a null-terminated string that specifies the class name or is an atom that identifies the class-name string. If this parameter is an atom, it must be a global atom created by a previous call to theGlobalAddAtom function. The atom, a 16-bit value, must be placed in the low-order word of lpClassName; the high-order word must be zero.
lpWindowName
Pointer to a null-terminated string that specifies the window name (the window's title). If this parameter is NULL, all window names match.
위는 MSDN원문이구여
HWND FindWindow(
LPCTSTR lpClassName, // pointer to class name - Class Name이구여
LPCTSTR lpWindowName // pointer to window name - Window Caption 임덩.
if Handle := FindWindow( 'TForm1', 'Form1' ) <> 0 then
SendMessage(Handle, wm_Close, 0, 0);
김지태 wrote:
> 박태준 wrote:
> > Handle: hWnd;
> > Handle := FindWindow('이름', nil);
> > SendMessage(Handle, wm_Close, 0, 0);
> >
> > 위에서 이름부분에 실행파일 이름을 적으면되나요
> > 근데 혹시 위의 findwindow가 실행파일을 찾는게 아니구 같은 프로그램에서
> > 윈도우창을 가리키는게 아닌가요.
> >
> > 프로그램 실행할때 같은 프로그램이 실행중이면 죽이고 새로운 프로그램을
> > 띄울려구하는데
> > 알려주세요
> >
>
> 안냐세영. UserSpace임덩.
>
> FindWindow의 사용법은 다음과 같습니다.
>
> FindWindow
> The FindWindow function retrieves a handle to the top-level window whose class name and window name match the specified strings. This function does not search child windows. This function does not perform a case-sensitive search.
>
> HWND FindWindow(
> LPCTSTR lpClassName, // pointer to class name
> LPCTSTR lpWindowName // pointer to window name
> );
>
> Parameters
> lpClassName
> Pointer to a null-terminated string that specifies the class name or is an atom that identifies the class-name string. If this parameter is an atom, it must be a global atom created by a previous call to theGlobalAddAtom function. The atom, a 16-bit value, must be placed in the low-order word of lpClassName; the high-order word must be zero.
> lpWindowName
> Pointer to a null-terminated string that specifies the window name (the window's title). If this parameter is NULL, all window names match.
>
>
> 위는 MSDN원문이구여
>
> HWND FindWindow(
> LPCTSTR lpClassName, // pointer to class name - Class Name이구여
> LPCTSTR lpWindowName // pointer to window name - Window Caption 임덩.
> The FindWindow function retrieves a handle to the top-level window whose class name and window name match the specified strings. This function does not search child windows. This function does not perform a case-sensitive search.
>
> HWND FindWindow(
> LPCTSTR lpClassName, // pointer to class name
> LPCTSTR lpWindowName // pointer to window name
> );
>
> Parameters
> lpClassName
> Pointer to a null-terminated string that specifies the class name or is an atom that identifies the class-name string. If this parameter is an atom, it must be a global atom created by a previous call to theGlobalAddAtom function. The atom, a 16-bit value, must be placed in the low-order word of lpClassName; the high-order word must be zero.
> lpWindowName
> Pointer to a null-terminated string that specifies the window name (the window's title). If this parameter is NULL, all window names match.
>
>
> 위는 MSDN원문이구여
>
> HWND FindWindow(
> LPCTSTR lpClassName, // pointer to class name - Class Name이구여
> LPCTSTR lpWindowName // pointer to window name - Window Caption 임덩.
> Handle: hWnd;
> Handle := FindWindow('이름', nil);
> SendMessage(Handle, wm_Close, 0, 0);
>
> 위에서 이름부분에 실행파일 이름을 적으면되나요
> 근데 혹시 위의 findwindow가 실행파일을 찾는게 아니구 같은 프로그램에서
> 윈도우창을 가리키는게 아닌가요.
>
> 프로그램 실행할때 같은 프로그램이 실행중이면 죽이고 새로운 프로그램을
> 띄울려구하는데
> 알려주세요
>
안냐세영. UserSpace임덩.
FindWindow의 사용법은 다음과 같습니다.
FindWindow
The FindWindow function retrieves a handle to the top-level window whose class name and window name match the specified strings. This function does not search child windows. This function does not perform a case-sensitive search.
HWND FindWindow(
LPCTSTR lpClassName, // pointer to class name
LPCTSTR lpWindowName // pointer to window name
);
Parameters
lpClassName
Pointer to a null-terminated string that specifies the class name or is an atom that identifies the class-name string. If this parameter is an atom, it must be a global atom created by a previous call to theGlobalAddAtom function. The atom, a 16-bit value, must be placed in the low-order word of lpClassName; the high-order word must be zero.
lpWindowName
Pointer to a null-terminated string that specifies the window name (the window's title). If this parameter is NULL, all window names match.
위는 MSDN원문이구여
HWND FindWindow(
LPCTSTR lpClassName, // pointer to class name - Class Name이구여
LPCTSTR lpWindowName // pointer to window name - Window Caption 임덩.
);
그래서 찾을때는
Handle := FindWindow('이름', nil);
가 아니라
Handle := FindWindow( nil, 'Form Caption');
ex) 1. Handle := FindWindow( nil, 'Test 프로그램');
2. Handle := FindWindow( 'TForm1', 'Test 프로그램');
과 같이 하시면 되구여.
Class Name을 알고 싶을때는 Spy++ 을 사용하셔서 Tool Button에 있는
FindWindow를 사용하시면 편리하실겁니다.
그리고 혹시 해서 올리는데여, 위의 내용이 들어갈 부분은 Form Create보단
Project1.dpr부분이 적당할것 같네영.
Application.Initialize;
if FindWindow( 'TForm1', 'Form1' ) = 0 then
ShowMessage( 'Not Found' )
else
begin
ShowMessage( 'Find' );
Application.Terminate;
end;
Application.CreateForm(TForm1, Form1);
Application.Run;
그럼 20000.