-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMainWindow.cs
109 lines (94 loc) · 3.27 KB
/
MainWindow.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace ScreenReaderTest
{
public class MainWindow : CustomNativeWindow
{
private bool controlsOnTop_ = true;
public MainWindow()
{
InitWindow();
AddChildren();
}
public ControlsWindow ControlsWindow { get; private set; }
public ApplicationWindow ApplicationWindow { get; private set; }
public string ZOrderText
{
get
{
return controlsOnTop_ ? "Controls on top" : "Controls at bottom";
}
}
public void ToggleZOrder()
{
controlsOnTop_ = !controlsOnTop_;
UpdateChildrenBounds();
}
private void InitWindow()
{
var createParams = new CreateParams();
createParams.X = 100;
createParams.Y = 100;
createParams.Width = 800;
createParams.Height = 600;
createParams.Caption = "Screen reader test";
CreateHandle(createParams);
Utils.SetTopWindowStyles(Handle);
}
private void AddChildren()
{
ControlsWindow = new ControlsWindow(this);
ControlsWindow.SetParent(Handle);
ControlsWindow.Show(false);
ApplicationWindow = new ApplicationWindow();
ApplicationWindow.SetParent(Handle);
ApplicationWindow.Show(false);
}
protected override bool SupportsAccessibiliyObject()
{
return true;
}
protected override AccessibleObject OnAccessibleObjectHitTestCore(int x, int y)
{
var sPoint = new sPOINT() { x = x, y = y };
var target = Win32.WindowFromPoint(sPoint);
if (target != IntPtr.Zero && ApplicationWindow.ContainsHandle(target))
{
return ApplicationWindow.AccessibleObject;
}
return base.OnAccessibleObjectHitTestCore(x, y);
}
protected override void OnDestroyedCore()
{
base.OnDestroyedCore();
Win32.PostQuitMessage(0);
}
protected override bool OnEraseBackgroundCore(IntPtr hDC)
{
return true;
}
protected override bool OnPaintCore(IntPtr hDC)
{
return true;
}
protected override void OnBoundsChangedCore(Rectangle prevBounds, Rectangle newBounds)
{
base.OnBoundsChangedCore(prevBounds, newBounds);
UpdateChildrenBounds();
}
private void UpdateChildrenBounds()
{
var clientRect = ClientRect;
var controlsInsertAfter = controlsOnTop_ ? Win32.HWND_TOP : Win32.HWND_BOTTOM;
ControlsWindow.SetBounds(controlsInsertAfter, clientRect);
var windowArea = ControlsWindow.WindowArea;
var applicationInsertAfter = controlsOnTop_ ? Win32.HWND_BOTTOM : Win32.HWND_TOP;
ApplicationWindow.SetBounds(applicationInsertAfter, windowArea);
}
}
}