Q&A

  • 같은 프로그램 두번실행 안되게?
Handle: hWnd;

Handle := FindWindow('이름', nil);

SendMessage(Handle, wm_Close, 0, 0);



위에서 이름부분에 실행파일 이름을 적으면되나요

근데 혹시 위의 findwindow가 실행파일을 찾는게 아니구 같은 프로그램에서

윈도우창을 가리키는게 아닌가요.



프로그램 실행할때 같은 프로그램이 실행중이면 죽이고 새로운 프로그램을

띄울려구하는데

알려주세요



4  COMMENTS
  • Profile
    김지태 2001.11.12 23:04
    박태준 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 임덩.

    );



    그래서 찾을때는



    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.















  • Profile
    궁금이 2001.11.16 19:52
    김지태님 잘 보았습니다.

    알려주신데로 하니까 되는데요

    그런데 알려주신건 새로 시작하는 프로그램을 죽이는 건데

    이전에 뜬 프로그램을 죽이는 방법은 없을까요?

    SendMessage로 보내도 묵묵부답이네요.



    Handle: hWnd;

    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 임덩.

    > );

    >

    > 그래서 찾을때는

    >

    > 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.

    >

    >

    >

    >

    >

    >

    >

  • Profile
    버섯 2001.11.13 18:22
    김지태 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 임덩.

    > );

    >

    > 그래서 찾을때는

    >

    > 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.

    >

    >

    >

    >

    >

    >

    >





    위방법은 좋은게 아닌듯 싶구요..

    19940 답변을 참조하세요

  • Profile
    김지태 2001.11.13 18:57
    안냐세영. UserSpace임덩.



    reply 감사하구여...



    전 그저 조금의 도움이 되었으면 하는 마음에 FindWindow의 사용법에



    대해 쬐끔 서술하였을 뿐인데, 음...



    >> 위방법은 좋은게 아닌듯 싶구요..

    >> 19940 답변을 참조하세요



    라고 말씀하신건 뭐가 좋은 방법이 아닌지 구체적으로 이해가 안가는군요.



    그리고 19940 답변을 찾을려고 무지 Next를 눌러 보았으나,



    번호가 중간에 없고 다른곳에 있는것 같아 못찾았군여.



    제가 또 한가하게 끝까지 찾을.... (좀 게을러서여.. ㅋㅋ)



    reply하실때 위 답변의 내용을 주셨으면 좋았을텐데...



    아쉬움이 남는군여. 버섯님이 말씀하시는 좋은 방법이란...



    도통 모르겠으니 이거 참... ㅡㅡ;



    혹 시간 나시면 reply부탁함덩...



    그럼 20000.