오전 10:37 2002-11-08
다른 스레드에서 만든 윈도우의 SetFocus 주기
=============================================================================
저도 msdn을 읽고 보니 재미있는 구석이 있어서 한마디 합니다.

AttachThreadInput 를 써야 한다는 군요.
SetFocus는 현재 스레드 컨텍스트의 input process 에 메시지를 보내게 되는데, 님은
현재 다른 스레드의 인풋으로 넣은거라 안되나 봅니다.
다른 스레드의 SetFocus를 하고 싶으면 인풋 프로세스를 서로 공유하도록
Attach시키라고 하는군요.

Windows created in different threads typically process input independently of each other. That is, they have their own input states (focus, active, capture windows, key state, queue status, and so on), and they are not synchronized with the input processing of other threads. By using the AttachThreadInput function, a thread can attach its input processing to another thread. This also allows threads to share their input states, so they can call the SetFocus function to set the keyboard focus to a window of a different thread. This also allows threads to get key-state information. These capabilities are not generally possible.

윈도우가 서로 다른 스레드에서 생성되면 전형적으로 서로다른 스레드의 인풋에 의존하게 된다.
( Advanced Window NT를 보시면 아시겠지만 윈도우는 해당 생성한 스레드의 스레드 메시지 큐를 이용하여 펌핑을하죠)
그 말인즉슨, 스레드들은 각각 자신의 입력 상태 ( 포커스, 윈도활성, 윈도우 마우스캡쳐링, 키 상태값, 큐 상태 등)을 갖는
다는 말이다. 그리고 스레드마다 비동기적으로 그 상태를 갖고 있다. AttachThreadInput 함수를 이용하면 스레드는
그의 인풋 처리를 다른 스레드로 붙일 수 있다. 이는 또한 자신의 인풋 상태를 다른 스레드에게 공유하는것을 허락하는
것이다. 그렇게 함으로써 SetFocus함수를 다른 스레드에서 호출 할 수 있게 한다. ...... (후략 -_- )
잘 써보세요.

저도 재미있는걸 알게 되었군요..
( 이런것을 모를땐 그냥 항상 ui는 해당 처리 스레드에서 생성해야만 한다라고만 한정지었는데 저도 잘 배웠습니다. )

+ Recent posts