更新时间:2023-12-06 13:04:04
找出原因,如果有人想知道相同的问题,请在此处张贴.
Found out why, post here if somebody wondering the same problem.
当您将用户控件托管在本机win32窗口中时,它没有窗口句柄. _hwndSource.Handle与本地win32窗口的Hwnd不同.它可能是Interop添加的另一层的句柄吗? (我不知道).
The usercontrol does not have a window handle, when you host it in a native win32 window. the _hwndSource.Handle is not the same as the Hwnd of the native win32 window. It might be the handle of another layer that the Interop added? (I do not know).
仅当HwndSource满足以下所有三个条件时,才会触发WM_SIZE事件
The WM_SIZE event will be triggered only if the HwndSource satisfy all of the following 3 conditions
1.设置HwndSource.SizeToContent = SizeToContent.WidthAndHeight;
1. set the HwndSource.SizeToContent = SizeToContent.WidthAndHeight;
2.通过本地MoveWindow调用调整本地Win32窗口的大小
2. Resize the native win32 window by native MoveWindow call
3.通过设置用户控件的宽度和高度来调整其大小.
3. Resize the usercontrol by set its width and height.
然后WM_SIZE消息正在工作.
then now the WM_SIZE message is working.