HwndSource 클래스를 사용하여 C++/CLI 응용 프로그램에서 WPF 컨트롤을로드하려고합니다.C++/CLI : Interop 창이 제대로 구성되지 않았습니다.
IntPtr MyWindowWrapper::MessageHookFunction(IntPtr HWnd, int Msg,
IntPtr WParam, IntPtr LParam, bool% OutHandled) {
IntPtr Result = (IntPtr)0;
OutHandled = false;
if(Msg == WM_GETDLGCODE) {
OutHandled = true;
// This tells Windows that we'll need keyboard events for this control
Result = IntPtr(DLGC_WANTALLKEYS | DLGC_WANTCHARS | DLGC_WANTMESSAGE);
}
return Result;
}
그리고 여기 내 문제가 있습니다 : 그래서 (
- 창 제목이 비어있는 키보드 이벤트 창에 전달되도록
UBOOL MyWindowWrapper::Init(const HWND InParentWindowHandle) { Interop::HwndSourceParameters sourceParams("WindowName"); sourceParams.PositionX = 0; sourceParams.PositionY = 0; sourceParams.ParentWindow = (IntPtr)InParentWindowHandle; sourceParams.WindowStyle = (WS_VISIBLE | WS_CHILD); sourceParams.HwndSourceHook = nullptr; InteropWindow = gcnew Interop::HwndSource(sourceParams); Control = gcnew MyWPFUserControl(); InteropWindow->RootVisual = Control; InteropWindow->AddHook(gcnew Interop::HwndSourceHook( this, &MyWindowWrapper::MessageHookFunction)); return TRUE; }
는 그리고는 후크 함수를 정의 "WindowName"매개 변수는 고려되지 않음)
- 일부 키보드 이벤트 만 전송됩니다 : 공간, 제어, 화살표는 괜찮지 만 문자를 입력 할 수는 없습니다 모든 텍스트 상자에
내가 뭘 잘못하고 있니?
나는 실제로 새로운 빈 프로젝트로 몇 가지 테스트를 만들었고 키보드 이벤트는 후크없이 전송된다. 그래서 그것은 다른 곳에서 왔을 것입니다 ... 어쩌면 WxWidgets에서 온 것일 수도 있습니다. 제목에 대해서는 예, 테스트 프로젝트에서 HwndSource가 Hwnd 창의 하위 노드로 연결되어있는 것을 보았습니다. 반면에 주 프로젝트에는 완전히 새로운 창이 생성되었습니다. 그래서 HwndSource를 첨부하면 자동으로 윈도우가 생성되는 것 같습니다. 이유는 모르겠습니다. 답장을 보내 주셔서 감사합니다. – user258607
HwndSource는 항상 새 창을 만듭니다. – Andy