主にプログラミングに関して。Python, .NET Framework(C#), JavaScript, その他いくらか。
記事にあるサンプルやコードは要検証。使用に際しては責任を負いかねます

Windows 10: 自分のために作ったユニバーサルアプリをインストール

                
tags: .NET
 Windows 10のユニバーサルアプリはストアアプリと同様、基本的にストアからインストールをしてくださいという形になっている。そのためアプリ自体をビルドして出てきたファイルを実行しようとしてもAppContainerから実行されてないというようなエラーが出て実行できない。これを回避し自作ユニバーサルアプリを自分の環境で使いたい場合、アプリをインストールしてから実行する必要がある。というわけで自作ユニバーサルアプリのインストール方法のメモ。表示言語が英語での操作でやっているのでそこらは適宜読み換え。
 まず注意点。ユニバーサルアプリをストアを介さずにインストールできるようにするのはリスクを抱えることになる。基本審査を行うストアを介してインストールされるべきアプリが、ストア以外の入手先もOKということになってしまうので。というわけでインストールして使うのは自作アプリに絞ること。どっかから拾ってきたアプリでこの方法を実行しないこと。

 Windows10のSettingsメニューにデベロッパーモードへ切り替えるスイッチがある。これをオンにする。先にもあるとおり、これはセキュリティリスクを増す行為である。これをやるなら以降はファイル実行、スクリプト実行などで注意を増す必要がある。

 ユニバーサルアプリを作成したVisualStudioプロジェクトを開き、「Project」- 「Store」 - 「Create App Packages」とたどる。
1507191315283.jpg

 ストアへはアップしない。
 1507191315536.jpg

 CPU構成を自分の環境に合わせる。パッケージ作成は数分かかるようなので余計な設定はしないでおいたほうがいいかも。
1507191316143.jpg

 パッケージ作成が終わったら認証が課される。
1507191313275.jpg

 実行するテストの選択。
 1507191314034.jpg

 以上が終了したら作成したアプリのプロジェクトフォルダにAppPackagesというディレクトリがあり、そのさらに下にそれらしきプロジェクト名とバージョン名のディレクトリができているのでそこへ下りていく。.ps1ファイルがあるのでそれを右クリックしてPowerShellで走らせる。これでインストールが始まる。
 1507191325235.jpg

スポンサーサイト



C#: クラスやメソッドの宣言時に知っておくこと

                
クラスやメソッドや変数の定義に出てくるpublicやprivateから。いわゆる「アクセシビリティ」。どの範囲にまでその変数をアクセス可能にするか。
参考:http://dobon.net/vb/dotnet/beginner/accessibilitylevel.html

public→どこからでも使える

protected→そのクラスやメソッドが定義されているメンバーから、もしくはその派生クラスからのみ使える

internal→同じアセンブリからなら使える

protected internal→同じアセンブリ、もしくは派生クラスからのみ

private→そのクラスやメソッドが定義されているメンバーからのみ使える



続いて修飾子staticをクラス定義に使う場合。最近、Expression Encoder SDKを使ってスクリーンキャプチャ機能を提供するクラスを作っているときにお世話になった。これはどういう効果を持つか一番しっくりきた表現はMSDNにあった、「静的メンバーは、インスタンスを使って参照できません」ということ(参考:MSDN)。
インスタンスを作らずに使う関数の寄せ集めのクラスを作りたいときに使った。
以下のコードで、ThumbnailGeneratorクラスは外部から見ると、SaveThumbnailメソッドとGetThumbnailメソッドのみを持つ。ThumbnailGeneratorクラスのインスタンスは必要としておらず、外部からSaveThumbnailメソッドかGetThumbnailメソッドのすきなほうに引数を渡して使うようになっている。インスタンスを作らずにそれぞれのメソッドにアクセスできるようにするために、staticにせねばならない。

using System;
using System.Drawing;
using System.Drawing.Imaging;
using System.IO;
using Microsoft.Expression.Encoder;

namespace Generator
{
public static class ThumbnailGenerator
{

public static void SaveThumbnail(string src, string outputName, double point)
{
Bitmap thumbnail = GetThumbnail(src, point);

// sets thumbnail name unique and saves
thumbnail.Save(outputName, ImageFormat.Jpeg);

thumbnail.Dispose();
}

public static Bitmap GetThumbnail(string src, double point)
{
Bitmap thumbnail;
//string bitmapDir = Environment.CurrentDirectory;

if (!File.Exists(src))
{
System.ArgumentException argEx = new System.ArgumentException("Source file not found");
throw argEx;
}
AudioVideoFile avFile = null;
try
{
avFile = new AudioVideoFile(src);
}
catch (Exception ex)
{
System.ArgumentException argEx = new System.ArgumentException(ex.Message);
throw argEx;
}

// Gets the time for each thumbnail.
if (point > avFile.Duration.TotalSeconds)
{
Console.WriteLine(avFile.Duration.TotalSeconds);
System.ArgumentException argEx = new System.ArgumentException("Over a duration");
throw argEx;
}

// Create ThumbnailGenerator object to get thumbs from AudioVideoFile
Microsoft.Expression.Encoder.ThumbnailGenerator generator = avFile.CreateThumbnailGenerator(avFile.VideoStreams[0].VideoSize);

// Gets image based on timing
thumbnail = generator.CreateThumbnail(TimeSpan.FromSeconds(point));

generator.Dispose();
return thumbnail;
}
}
}

staticをメンバに使う場合は下記を参考に。インスタンスごとに変える必要がなく、インスタンス間で共通の変数にしたいときなどに使うものらしい。
http://ufcpp.net/study/csharp/oo_static.html



C#の基礎はこんなところか。オブジェクト指向のコンセプトである「内部実装は隠蔽して、外部の振る舞いだけを使用者に見せる」といったようなコンセプトが基礎レベルからもろに出ているように感じる。

ぼくが学んだ言語としてC#は6番目だ。Cから始まってスクリプト言語をいくつか経てC#に出くわした。で、C#を書いてみた感想は「素晴らしい。だけどプログラミング経験のない人には教えたくないな」。

はじめて学校でCを習ったとき、単純な整数同士の加算をやるにも、いわゆる「おまじない」がたくさん出てきた。「stdio.hヲインクルードシテクダサイ」、「ヘンスウヲカタヲキメテセンゲンシテクダサイ」、「mainノウシロニカッコヲツケテショリヲカイテクダサイ」などなど。いくらかやっているうちにスラスラと書けるようになって、学校での演習時間も持て余すようになった。その一方で、できない人は変数宣言にすら納得ができていなかった。
数年後、大学の卒研で初めてスクリプト言語に触った。MATLABのクローンでScilabというものだ。処理を書くための「おまじない」が少ないのがとっつやすかった。この言語で計算式や定数、変数を書いていくことで物理的なシミュレーションをおこなうプログラムを作り、はじめてまともなプログラムを書いたなと感慨を得た。そのあとにPythonとJavaScriptに触れてオブジェクト指向やらなんやらいっそうプログラミングらしいことに触れていた。そこで「おまじない」を使うと、プログラム作成が便利になったり、コードをきれいに書けたりすることを知った。

で、C#へ。すべてがクラスであったり、メソッド宣言時にstaticやprivateで容易にアクセシビリティを決められたり。書いたものの管理や流用が楽だなーと感じた。
でもこれが初めてのプログラミング言語だったらそんなことは思わなかったと思う。「おまじない」が盛りだくさん。staticとかprivateってなにさ? いや、そもそもすべてがクラスだなんて「クラス」も知らんわ。基礎部分がCより厚いんじゃないかと思う。実際仕様書はC#のほうが厚いらしいし。

個人的にC#はより玄人向けな言語なんじゃないかなーと感じるところ。これを通じて育った人は一層優れたものになるけど、スクリプト言語なんかと比べるとだいぶ重いギブスみたいだなと。

Boo: C#で書いていたコードをBooで書いてみる

                
今回はBooがC#に取って代われる可能性があるかを確認したい。そのためにC#で書かれたコードをBooに直してみる。

Pythonの影響を受けたBooのスクリプトの可読性は価値がある。
.NET上でC#にとって代わりたいならIronPythonという選択肢もある。なぜIronPythonでなくBooかというと、IronPythonは根本がPythonなので、C#に似た書き方ができない。C#には属性があったりrefによる参照渡しがあったり。これをIronPythonで真似するのは手間がかかる。
BooはPythonの皮をかぶったC#だ。属性もrefによる参照渡しもある。パフォーマンスだってC#に遜色ないどころか、若干勝ることもある。それならBooでもいいじゃないか。
http://elicon.blog57.fc2.com/blog-entry-253.html

まずはMicrosoft Expression Encoder 4 SDKを使った、動画からサムネイルを作るクラスをBooで書いてみる。
↓これを……
using System;
using System.Drawing;
using System.Drawing.Imaging;
using System.IO;
using Microsoft.Expression.Encoder;

namespace Generator
{
public static class ThumbnailGenerator
{

public static void SaveThumbnail(string src, string outputName, double point)
{
Bitmap thumbnail = GetThumbnail(src, point);

// sets thumbnail name unique and saves
thumbnail.Save(outputName, ImageFormat.Jpeg);

thumbnail.Dispose();
}

public static Bitmap GetThumbnail(string src, double point)
{
Bitmap thumbnail;
//string bitmapDir = Environment.CurrentDirectory;

if (!File.Exists(src))
{
System.ArgumentException argEx = new System.ArgumentException("Source file not found");
throw argEx;
}
AudioVideoFile avFile = null;
try
{
avFile = new AudioVideoFile(src);
}
catch (Exception ex)
{
System.ArgumentException argEx = new System.ArgumentException(ex.Message);
throw argEx;
}

// Gets the time for each thumbnail.
if (point > avFile.Duration.TotalSeconds)
{
Console.WriteLine(avFile.Duration.TotalSeconds);
System.ArgumentException argEx = new System.ArgumentException("Over a duration");
throw argEx;
}

// Create ThumbnailGenerator object to get thumbs from AudioVideoFile
Microsoft.Expression.Encoder.ThumbnailGenerator generator = avFile.CreateThumbnailGenerator(avFile.VideoStreams[0].VideoSize);

// Gets image based on timing
thumbnail = generator.CreateThumbnail(TimeSpan.FromSeconds(point));

generator.Dispose();
return thumbnail;
}
}
}


Booで上記のコードを書きかえる
namespace BooThumbnailGenerator

import System
import System.Drawing
import System.Drawing.Imaging
import System.IO
import Microsoft.Expression.Encoder

public static class ThumbnailGenerator:
public def SaveThumbnail(src as string, outputName as string, point as double) as void:
thumbnail = GetThumbnail(src, point) as Bitmap

// sets thumbnail name unique and saves
thumbnail.Save(outputName, ImageFormat.Jpeg)

thumbnail.Dispose()

public def GetThumbnail(src as string, point as double) as Bitmap:
thumbnail as Bitmap

if not File.Exists(src):
raise "Source file not found"
avFile = null as AudioVideoFile
try:
avFile = AudioVideoFile(src)
except e:
raise e

// Gets the time for each thumbnail.
if point > avFile.Duration.TotalSeconds:
print(avFile.Duration.TotalSeconds)
raise "Over a duration"

// Create ThumbnailGenerator object to get thumbs from AudioVideoFile
generator = avFile.CreateThumbnailGenerator(avFile.VideoStreams[0].VideoSize) as Microsoft.Expression.Encoder.ThumbnailGenerator

// Gets image based on timing
thumbnail = generator.CreateThumbnail(TimeSpan.FromSeconds(point))

generator.Dispose()
return thumbnail


クラスなので、コンパイルでDLL化すれば.NET上ならC#, VB, IronPython, IronRuby, Booなどどの言語からだって使える。動作はIronPythonで確認したが、問題なく動いた。
import  clr

clr.AddReference('BooThumbnailGenerator')
clr.AddReference('System.Drawing')

from BooThumbnailGenerator import ThumbnailGenerator
from System.Drawing import Bitmap

ThumbnailGenerator.SaveThumbnail(r"C:\Users\h\Videos\B'z\B'z _ C'mon.mp4",
r'hoge.jpg',
10)

bitmap = ThumbnailGenerator.GetThumbnail(r"C:\Users\h\Videos\B'z\B'z _ C'mon.mp4",
3.3)
bitmap.Save("hoge.png")




続いて、DllImportを使用して、マウスイベントを下に重なっているウィンドウにスルーパスするWPFウィンドウを作ってみる。ウィンドウにスルー機能を持たせるクラスはC#で以下のように。
using System;

using System.Windows.Interop;
using System.Runtime.InteropServices;

namespace WindowServices
{
public static class WindowsServices
{
const int WS_EX_TRANSPARENT = 0x00000020;
const int GWL_EXSTYLE = (-20);

[DllImport("user32.dll")]
static extern int GetWindowLong(IntPtr hwnd, int index);

[DllImport("user32.dll")]
static extern int SetWindowLong(IntPtr hwnd, int index, int newStyle);

public static void SetWindowExTransparent(IntPtr hwnd)
{
var extendedStyle = GetWindowLong(hwnd, GWL_EXSTYLE);
SetWindowLong(hwnd, GWL_EXSTYLE, extendedStyle | WS_EX_TRANSPARENT);
}
}
}


上記のクラスをBooで書き、そのままウィンドウ表示までやってみる。
namespace BooWPF

import System
import System.Windows
import System.Windows.Media

import System.Windows.Interop
import System.Runtime.InteropServices

static class WindowsServices:
WS_EX_TRANSPARENT = 0x00000020
GWL_EXSTYLE = -20

[DllImport("user32.dll")]
def GetWindowLong(hwnd as IntPtr, index as int) as int:
pass

[DllImport("user32.dll")]
def SetWindowLong(hwnd as IntPtr, index as int, newStyle as int) as int:
pass

public def SetWindowExTransparent(hwnd as IntPtr) as void:
extendedStyle = GetWindowLong(hwnd, GWL_EXSTYLE)
SetWindowLong(hwnd, GWL_EXSTYLE, extendedStyle | WS_EX_TRANSPARENT)


class Window1(Window):
def constructor():
WindowStyle = WindowStyle.None
Topmost = true
Background = BrushesBlue
AllowsTransparency = true
Opacity = 0.5
Show()


[STAThread]
def Main():
app = Application()
w = Window1()
hwnd = WindowInteropHelper(w).Handle
WindowsServices.SetWindowExTransparent(hwnd)
app.Run()


上記のコードでやっているのは、半透明で青色のコントロールなしウィンドウを表示して、マウスイベント(クリックやドラッグ)をその背後にあるウィンドウに渡すということ。このコードも難なく動いた。


IronPythonでC#のまねごとをしようとすると、言語の持つ機能の違いがモロに出て厄介なことになる。その点、BooでC#のまねごとをしようとすると、割とすんなりいく。このあたりはBooはPythonの皮をかぶったC#であるんじゃないかと常々感じる。
まあなんにしろ、Booは読みやすくてなおかつ書きやすい言語だ。.NETでDLL化したいクラスをつくるときはこの言語を使っていくのがいいと思う。

C#, IronPython: 動画をキャプチャしてサムネイルを作る

                
.NETでの動画のサムネイルの作り方はこれまでに二通りやってきた。

一つ目はWPFのMediaElementによる再生で、ディスプレイ上に表示した動画をキャプチャするやり方だ。ディスプレイに動画を表示しなければいけないが、表示サイズは1×1でも表示できればサムネイルは問題なくキャプチャできる。この方法はDRMのかかったコンテンツでもキャプチャできるというメリットがある。しかしグラフィック機能の弱いコンピュータ(グラボなしのi3 M370とか)で使うと、MediaElementの副作用で一瞬ディスプレイの描画が止まる。
http://elicon.blog57.fc2.com/blog-entry-177.html

二つ目のやり方はDirectShowを使ったやり方で、動画をディスプレイ上に表示しなくてもキャプチャできる。だけどDRMのかかったコンテンツは開けない。そしてDirectShowがもとは.NET向けの技術でないために、ドキュメントや使い方の面で不便。
http://elicon.blog57.fc2.com/blog-entry-186.html

今回は三つ目のやり方を見つけたので、ちょいとC#でやってみる。クラス化したので、dllにしてIronPythonから使うことだってもちろんできる。
必要なのはMicrosoft Expression Encoder 4。これのインストール時にSDKとサンプルがついてくる。
やっぱりDRMコンテンツは扱えないのだけど、SDKは標準でC#から使えるようになっている。これならDirectShowの代替手段として使える。ドキュメントは下記。
http://msdn.microsoft.com/en-us/library/cc761464(v=expression.40).aspx

C#コードは下記。これをdllにすれば容易にサムネイルが作れる。
using System;
using System.Drawing;
using System.Drawing.Imaging;
using System.IO;
using Microsoft.Expression.Encoder;

namespace Generator
{
public static class ThumbnailGenerator
{

public static void SaveThumbnail(string src, string outputName, double point)
{
Bitmap thumbnail = GetThumbnail(src, point);

// sets thumbnail name unique and saves
thumbnail.Save(outputName, ImageFormat.Jpeg);

thumbnail.Dispose();
}

public static Bitmap GetThumbnail(string src, double point)
{
Bitmap thumbnail;
//string bitmapDir = Environment.CurrentDirectory;

if (!File.Exists(src))
{
System.ArgumentException argEx = new System.ArgumentException("Source file not found");
throw argEx;
}
AudioVideoFile avFile = null;
try
{
avFile = new AudioVideoFile(src);
}
catch (Exception ex)
{
System.ArgumentException argEx = new System.ArgumentException(ex.Message);
throw argEx;
}

// Gets the time for each thumbnail.
if (point > avFile.Duration.TotalSeconds)
{
Console.WriteLine(avFile.Duration.TotalSeconds);
System.ArgumentException argEx = new System.ArgumentException("Over a duration");
throw argEx;
}

// Create ThumbnailGenerator object to get thumbs from AudioVideoFile
Microsoft.Expression.Encoder.ThumbnailGenerator generator = avFile.CreateThumbnailGenerator(avFile.VideoStreams[0].VideoSize);

// Gets image based on timing
thumbnail = generator.CreateThumbnail(TimeSpan.FromSeconds(point));

generator.Dispose();
return thumbnail;
}
}
}


dllを用意したら、.NET Framework環境なら他の言語からも使える。IronPythonからは以下のように。
import clr

clr.AddReference('Generator')
clr.AddReference('System.Drawing')

from Generator import ThumbnailGenerator
from System.Drawing import Bitmap

ThumbnailGenerator.SaveThumbnail(r"C:\Users\h\Videos\***.mp4",
r'c:\users\h\desktop\hoge.jpg',
10.0)

bitmap = ThumbnailGenerator.GetThumbnail(r"C:\Users\h\Videos\***.mp4",
15.0)
bitmap.Save("hoge.png")


C#
using Generator
using System.Drawing

ThumbnailGenerator.SaveThumbnail(@"C:\Users\h\Videos\***.mp4",
@'c:\users\h\desktop\hoge.jpg',
10.0);

Bitmap bitmap = ThumbnailGenerator.GetThumbnail(@"C:\Users\h\Videos\***.mp4",
15.0);
bitmap.Save("hoge.png");

IronPython, C#: Expression Encoder SDKを使ったスクリーンキャプチャアプリケーション

                
Windows向けスクリーンキャプチャアプリケーションを作った。今回はスクリプトとともに技術的なことをメモ。

13051201.png

画像のように、デスクトップ上の録画領域の位置を調整する際に、半透明でなにもコントロールのないウィンドウを表示することで、録画領域がどこかわかりやすくなるようにしている。この半透明領域はウィンドウだが、領域内でクリックをしてもスルーして、下のウィンドウにマウスイベントをパスするようになっている。この技術はC#で見つけることができた。
http://stackoverflow.com/questions/2842667/how-to-create-a-semi-transparent-window-in-wpf-that-allows-mouse-events-to-pass
C#でクラスを作成してdll化し、それをIronPythonから利用している。
using System;

using System.Windows.Interop;
using System.Runtime.InteropServices;

namespace WindowServices
{
public static class WindowsServices
{
const int WS_EX_TRANSPARENT = 0x00000020;
const int GWL_EXSTYLE = (-20);

[DllImport("user32.dll")]
static extern int GetWindowLong(IntPtr hwnd, int index);

[DllImport("user32.dll")]
static extern int SetWindowLong(IntPtr hwnd, int index, int newStyle);

public static void SetWindowExTransparent(IntPtr hwnd)
{
var extendedStyle = GetWindowLong(hwnd, GWL_EXSTYLE);
SetWindowLong(hwnd, GWL_EXSTYLE, extendedStyle | WS_EX_TRANSPARENT);
}
}
}


from System.Windows.Interop import *
from WindowsServices import WindowsServices

hwnd = WindowInteropHelper(window).Handle
WindowsServices.SetWindowExTransparent(hwnd)


Window1.py
import wpf, clr

clr.AddReference('System.Drawing')
clr.AddReference('Microsoft.Expression.Encoder')
clr.AddReference('WindowServices')

import System
from System.Drawing import *
from System.IO import *
from System.Threading import *
from System.Windows import *

from Microsoft.Expression.Encoder.ScreenCapture import *
from Microsoft.Expression.Encoder.Devices import *
from Microsoft.Expression.Encoder.Profiles import *
from System.Windows.Interop import *
from System.Runtime.InteropServices import *
from WindowServices import WindowsServices

class Window1 (Window):
def __init__(self):
wpf.LoadComponent(self, 'Window1.xaml')
self.textBoxX = self.FindName('textBoxX')
self.textBoxX.TextChanged += self.AdjustTransparentWindow
self.textBoxY = self.FindName('textBoxY')
self.textBoxY.TextChanged += self.AdjustTransparentWindow
self.textBoxWidth = self.FindName('textBoxWidth')
self.textBoxWidth.TextChanged += self.AdjustTransparentWindow
self.textBoxHeight = self.FindName('textBoxHeight')
self.textBoxHeight.TextChanged += self.AdjustTransparentWindow
self.recButton = self.FindName('RecButton')
self.stopButton = self.FindName('StopButton')

self.StateChanged += self.StateChange

self.job = ScreenCaptureJob()

self.Show()

self.tWindow = Window()
wpf.LoadComponent(self.tWindow, 'TransparentWindow.xaml')
self.tWindow.Show()
self.AdjustTransparentWindow()
hwnd = WindowInteropHelper(self.tWindow).Handle
WindowsServices.SetWindowExTransparent(hwnd)

def StateChange(self, target, e):
if self.WindowState == WindowState.Minimized:
self.tWindow.WindowState = WindowState.Minimized
elif self.WindowState == WindowState.Normal:
self.tWindow.WindowState = WindowState.Normal

def AdjustTransparentWindow(self, *args):
try:
x0 = int(self.textBoxX.Text)
except ValueError:
return
try:
y0 = int(self.textBoxY.Text)
except ValueError:
return
try:
width = int(self.textBoxWidth.Text)
except ValueError:
return
try:
height = int(self.textBoxHeight.Text)
except ValueError:
return

if (x0 < 0) or (y0 < 0) or (width < 0) or (height < 0):
return
self.tWindow.Left = x0
self.tWindow.Top = y0
self.tWindow.Width = width
self.tWindow.Height = height
self.tWindow.WindowState = System.Windows.WindowState.Normal

def OnClose(self, sender, e):
if (self.job.Status == RecordStatus.Running):
result = System.Windows.MessageBox.Show("Capturing in Progress. Are You Sure You Want To Quit?", "Capturing", MessageBoxButton.YesNo)
if (result == MessageBoxResult.No):
e.Cancel = True
return
self.job.Stop()
self.job.Dispose()
Application.Current.Shutdown()

def RecButton_Checked(self, sender, e):
try:
x0 = int(self.textBoxX.Text)
except ValueError:
return
try:
y0 = int(self.textBoxY.Text)
except ValueError:
return
try:
width = int(self.textBoxWidth.Text)
except ValueError:
return
try:
height = int(self.textBoxHeight.Text)
except ValueError:
return
width = width + (4 - width % 4)
height = height + (4 - height % 4)
if (x0 < 0) or (y0 < 0) or (width < 0) or (height < 0):
return
capRect = Rectangle(x0, y0, width, height)

audioDevices = EncoderDevices.FindDevices(EncoderDeviceType.Audio)
self.job.AddAudioDeviceSource(audioDevices[len(audioDevices)-1])
self.tWindow.Opacity = 0.0
self.job.ScreenCaptureVideoProfile.Bitrate = ConstantBitrate(300 * 10 ** 3)
self.job.CaptureRectangle = capRect
self.job.OutputPath = Directory.GetCurrentDirectory()
self.recButton.Width = 0
self.stopButton.Width = 112
self.job.Start()

def RecButton_UnChecked(self, sender, e):
self.job.Stop()
self.recButton.Width = 112
self.stopButton.Width = 0
self.tWindow.Opacity = 0.7

def IncreaseX(self, sender, e):
try:
x0 = int(self.textBoxX.Text)
except ValueError:
return
x0 += 1
self.textBoxX.Text = x0.ToString()
self.tWindow.Left = x0

def DecreaseX(self, sender, e):
try:
x0 = int(self.textBoxX.Text)
except ValueError:
return
x0 -= 1
self.textBoxX.Text = x0.ToString()
self.tWindow.Left = x0

def IncreaseY(self, sender, e):
try:
y0 = int(self.textBoxY.Text)
except ValueError:
return
y0 += 1
self.textBoxY.Text = y0.ToString()
self.tWindow.Top = y0

def DecreaseY(self, sender, e):
try:
y0 = int(self.textBoxY.Text)
except ValueError:
return
y0 -= 1
self.textBoxY.Text = y0.ToString()
self.tWindow.Top = y0

def IncreaseWidth(self, sender, e):
try:
width = int(self.textBoxWidth.Text)
except ValueError:
return
width += 1
self.textBoxWidth.Text = width.ToString()
self.tWindow.Width = width

def DecreaseWidth(self, sender, e):
try:
width = int(self.textBoxWidth.Text)
except ValueError:
return
width -= 1
self.textBoxWidth.Text = width.ToString()
self.tWindow.Width = width

def IncreaseHeight(self, sender, e):
try:
height = int(self.textBoxHeight.Text)
except ValueError:
return
height += 1
self.textBoxHeight.Text = height.ToString()
self.tWindow.Height = height

def DecreaseHeight(self, sender, e):
try:
height = int(self.textBoxHeight.Text)
except ValueError:
return
height -= 1
self.textBoxHeight.Text = height.ToString()
self.tWindow.Height = height


Window1.xaml
<?xml version="1.0" encoding="utf-8"?>
<Window xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="Screen Capture"
Closing="OnClose"
mc:Ignorable="d" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
Height="200"
Width="150"
WindowStartupLocation="Manual"
Top="150"
Left="700"
ResizeMode="CanMinimize"
HorizontalContentAlignment="Left">
<WrapPanel HorizontalAlignment="Center">
<Button
Name="RecButton"
Content="Rec Start"
Click="RecButton_Checked"
Height="30"
VerticalAlignment="Top"
Width="140" />
<Button
Name="StopButton"
Content="Stop"
Click="RecButton_UnChecked"
Height="30"
VerticalAlignment="Top"
Width="0" />
<TextBlock
Height="23"
Name="textBlock1"
Text="X"
Width="50"
TextAlignment="Center" />
<Button
Content="-"
Width="13"
Height="23"
Click="DecreaseX" />
<TextBox
Height="22"
HorizontalAlignment="Left"
Name="textBoxX"
VerticalAlignment="Top"
Width="50"
TextAlignment="Right"
Text="100" />
<Button
Content="+"
Width="13"
Height="23"
Click="IncreaseX" />
<TextBlock
Height="23"
Name="textBlock2"
Text="Y"
Width="50"
TextAlignment="Center" />
<Button
Content="-"
Width="13"
Height="23"
Click="DecreaseY" />
<TextBox
Height="22"
HorizontalAlignment="Left"
Name="textBoxY"
VerticalAlignment="Top"
Width="50"
TextAlignment="Right"
Text="100" />
<Button
Content="+"
Width="13"
Height="23"
Click="IncreaseY" />
<TextBlock
Height="23"
Name="textBlock3"
Text="Width"
Width="50"
TextAlignment="Center" />
<Button
Content="-"
Width="13"
Height="23"
Click="DecreaseWidth" />
<TextBox
Height="22"
HorizontalAlignment="Left"
Name="textBoxWidth"
VerticalAlignment="Top"
Width="50"
TextAlignment="Right"
Text="600" />
<Button
Content="+"
Width="13"
Height="23"
Click="IncreaseWidth" />
<TextBlock
Height="23"
Name="textBlock4"
Text="Height"
Width="50"
TextAlignment="Center" />
<Button
Content="-"
Width="13"
Height="23"
Click="DecreaseHeight" />
<TextBox
Height="22"
HorizontalAlignment="Left"
Name="textBoxHeight"
VerticalAlignment="Top"
Width="50"
TextAlignment="Right"
Text="360" />
<Button
Content="+"
Width="13"
Height="23"
Click="IncreaseHeight" />
</WrapPanel>
</Window>



TransparentWindow.xaml
<Window xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
WindowStyle="None"
Opacity="0.7"
ShowInTaskbar="False"
AllowsTransparency="True" Background="Black"
Topmost="True" WindowState="Normal"
WindowStartupLocation="Manual"
Left="0" Top="0">
</Window>


Application.py
import wpf

from System.Windows import Application
from Window1 import Window1

window = Window1()
app = Application()
app.Run(window)
プロフィール

h

Author:h

最新記事
リンク
作ったものなど
月別アーカイブ
カテゴリ
タグリスト

検索フォーム
Amazon