Skip to content

Instantly share code, notes, and snippets.

@ambyte
ambyte / acc.cs
Last active Mar 31, 2016
Some code for Accessible and UIAutomation
View acc.cs
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 Mar 18, 2015
Get selected text with UI Automation
View gist:f2e77c771b6b816bdea0
public static string GetText()
{
try
{
var element = AutomationElement.FocusedElement;
if (element != null)
{
object pattern;
if (element.TryGetCurrentPattern(TextPattern.Pattern, out pattern))
{
View gist:8f474733daa8741af061
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 Jan 14, 2015
Get correct TextRange in richtextbox with newlines
View gist:dc32cbe0dd47470801d4
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;
View gist:a7d9a456156c386149d8
[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 Jan 14, 2015
Converting a mapped drive letter to a network path using C#
View gist:01664dc7ee576f69042c
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