|
4 | 4 | using System.Drawing; |
5 | 5 | using System.Runtime.InteropServices; |
6 | 6 | using System.Windows.Forms; |
| 7 | +using Rubberduck.Common.WinAPI; |
7 | 8 | using Rubberduck.VBEditor; |
8 | 9 |
|
9 | 10 | namespace Rubberduck.UI |
@@ -40,10 +41,10 @@ private struct Rect |
40 | 41 | private IntPtr _parentHandle; |
41 | 42 | private SubClassingWindow _subClassingWindow; |
42 | 43 |
|
43 | | - internal void AddUserControl(UserControl control) |
| 44 | + internal void AddUserControl(UserControl control, IntPtr vbeHwnd) |
44 | 45 | { |
45 | 46 | _parentHandle = GetParent(Handle); |
46 | | - _subClassingWindow = new SubClassingWindow(_parentHandle); |
| 47 | + _subClassingWindow = new SubClassingWindow(_parentHandle, vbeHwnd); |
47 | 48 | _subClassingWindow.CallBackEvent += OnCallBackEvent; |
48 | 49 |
|
49 | 50 | if (control != null) |
@@ -116,27 +117,35 @@ public class SubClassingWindow : NativeWindow |
116 | 117 | public event SubClassingWindowEventHandler CallBackEvent; |
117 | 118 | public delegate void SubClassingWindowEventHandler(object sender, SubClassingWindowEventArgs e); |
118 | 119 |
|
| 120 | + private readonly IntPtr _vbeHwnd; |
| 121 | + |
119 | 122 | private void OnCallBackEvent(SubClassingWindowEventArgs e) |
120 | 123 | { |
121 | 124 | Debug.Assert(CallBackEvent != null, "CallBackEvent != null"); |
122 | 125 | CallBackEvent(this, e); |
123 | 126 | } |
124 | 127 |
|
125 | | - public SubClassingWindow(IntPtr handle) |
| 128 | + public SubClassingWindow(IntPtr handle, IntPtr vbeHwnd) |
126 | 129 | { |
| 130 | + _vbeHwnd = vbeHwnd; |
127 | 131 | AssignHandle(handle); |
128 | 132 | } |
129 | 133 |
|
130 | 134 | protected override void WndProc(ref Message msg) |
131 | 135 | { |
132 | | - const int wmSize = 0x5; |
133 | | - |
134 | | - if (msg.Msg == wmSize) |
| 136 | + switch ((uint)msg.Msg) |
135 | 137 | { |
136 | | - var args = new SubClassingWindowEventArgs(msg); |
137 | | - OnCallBackEvent(args); |
| 138 | + case (uint)WM.SIZE: |
| 139 | + var args = new SubClassingWindowEventArgs(msg); |
| 140 | + OnCallBackEvent(args); |
| 141 | + break; |
| 142 | + case (uint)WM.SETFOCUS: |
| 143 | + User32.SendMessage(_vbeHwnd, WM.RUBBERDUCK_CHILD_FOCUS, Handle, Handle); |
| 144 | + break; |
| 145 | + case (uint)WM.KILLFOCUS: |
| 146 | + User32.SendMessage(_vbeHwnd, WM.RUBBERDUCK_CHILD_FOCUS, Handle, IntPtr.Zero); |
| 147 | + break; |
138 | 148 | } |
139 | | - |
140 | 149 | base.WndProc(ref msg); |
141 | 150 | } |
142 | 151 |
|
|
0 commit comments