Skip to content

Instantly share code, notes, and snippets.

@ambyte
ambyte / acc.cs
Last active March 31, 2016 10:40
Some code for Accessible and UIAutomation
private Accessible GetFocused(Accessible objParent)
{
Accessible objToReturn = default(Accessible);
if (objParent != null)
{
Accessible[] children = null;
objParent.Children(out children);
if (children != null)
{
foreach (var accessible in children)
@ambyte
ambyte / gist:f2e77c771b6b816bdea0
Created March 18, 2015 10:08
Get selected text with UI Automation
public static string GetText()
{
try
{
var element = AutomationElement.FocusedElement;
if (element != null)
{
object pattern;
if (element.TryGetCurrentPattern(TextPattern.Pattern, out pattern))
{
@ambyte
ambyte / gist:8f474733daa8741af061
Created January 21, 2015 13:59
Image opacity
class ImageOpacity
{
private const int bytesPerPixel = 4;
/// <summary>
/// Change the opacity of an image
/// </summary>
/// <param name="originalImage">The original image</param>
/// <param name="opacity">Opacity, where 1.0 is no opacity, 0.0 is full transparency</param>
/// <returns>The changed image</returns>
@ambyte
ambyte / gist:dc32cbe0dd47470801d4
Created January 14, 2015 11:19
Get correct TextRange in richtextbox with newlines
var start = reachTextBox.Document.ContentStart;
var textrange = new TextRange(GetPoint(start, pos), GetPoint(start, pos + len));
private TextPointer GetPoint(TextPointer start, int x)
{
var ret = start;
var i = 0;
while (true)
{
string stringSoFar = new TextRange(ret, ret.GetPositionAtOffset(i, LogicalDirection.Forward)).Text;
@ambyte
ambyte / gist:a7d9a456156c386149d8
Created January 14, 2015 05:25
Get free space
[DllImport("kernel32.dll", SetLastError = true, CharSet = CharSet.Auto)]
[return: MarshalAs(UnmanagedType.Bool)]
static extern bool GetDiskFreeSpaceEx(string lpDirectoryName,
out ulong lpFreeBytesAvailable,
out ulong lpTotalNumberOfBytes,
out ulong lpTotalNumberOfFreeBytes);
ulong FreeBytesAvailable;
ulong TotalNumberOfBytes;
ulong TotalNumberOfFreeBytes;
@ambyte
ambyte / gist:01664dc7ee576f69042c
Created January 14, 2015 05:22
Converting a mapped drive letter to a network path using C#
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.InteropServices;
using System.IO;
namespace WiredPrairie.Samples
{
public static class Pathing