-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathUtils.cs
71 lines (65 loc) · 2.66 KB
/
Utils.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
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ScreenReaderTest
{
public class Utils
{
public static void SetChildWindowStyles(IntPtr handle)
{
var styles = Win32.GetWindowStyles(handle);
styles = styles & ~(Win32.WS_CAPTION | Win32.WS_THICKFRAME | Win32.WS_OVERLAPPEDWINDOW | Win32.WS_POPUP)
| Win32.WS_CHILDWINDOW;
Win32.SetWindowStyles(handle, styles);
var exStyles = Win32.GetWindowExStyles(handle);
exStyles &= ~(Win32.WS_EX_APPWINDOW);
exStyles |= Win32.WS_EX_TOOLWINDOW;
Win32.SetWindowExStyles(handle, exStyles);
}
public static void SetTopWindowStyles(IntPtr handle)
{
var styles = Win32.GetWindowStyles(handle);
styles = styles & ~(Win32.WS_CHILDWINDOW) |
Win32.WS_CLIPCHILDREN | Win32.WS_CLIPSIBLINGS |
Win32.WS_OVERLAPPED | Win32.WS_CAPTION | Win32.WS_SYSMENU |
Win32.WS_MINIMIZEBOX | Win32.WS_MAXIMIZEBOX | Win32.WS_THICKFRAME;
Win32.SetWindowStyles(handle, styles);
var exStyles = Win32.GetWindowExStyles(handle);
exStyles &= ~(Win32.WS_EX_TOOLWINDOW);
exStyles |= Win32.WS_EX_APPWINDOW;
Win32.SetWindowExStyles(handle, exStyles);
}
public static void SetLayeredWindowStyles(IntPtr handle, Color keyColor)
{
var exStyles = Win32.GetWindowExStyles(handle);
exStyles = exStyles | Win32.WS_EX_LAYERED;
Win32.SetWindowExStyles(handle, exStyles);
Win32.SetLayeredWindowAttributes(handle, ColorTranslator.ToWin32(keyColor), 0, Win32.LWA_COLORKEY);
}
public static Point PointToScreen(IntPtr handle, int x, int y)
{
var p = new sPOINT() { x = x, y = y };
Win32.ClientToScreen(handle, ref p);
return new Point(p.x, p.y);
}
public static Point PointToClient(IntPtr handle, int x, int y)
{
var p = new sPOINT() { x = x, y = y };
Win32.ScreenToClient(handle, ref p);
return new Point(p.x, p.y);
}
public static void FillRect(IntPtr hDC, Rectangle rect, Color color)
{
using (var g = Graphics.FromHdc(hDC))
{
using (var brush = new SolidBrush(color))
{
g.FillRectangle(brush, rect.X, rect.Y, rect.Width, rect.Height);
}
}
}
}
}