コンテンツ

Activity

リンク

Comment

雑記に戻る

2004/02/17(火)

XP スタイルを解除してみる

β3でもまだ HSP エディタのコモンコントロール問題が健在なようなようなので手抜き実装ですが、 XP スタイルを外す manifest ファイルを生成するツール。文字コードが UTF-8 なので .NET のほうが楽だろうということで C# 製ですが、よく考えると Ascii 文字だけなので別に HSP で組んでもかまわなかったり。


using System;
using System.IO;
using System.Drawing;
using System.Windows.Forms;

class Form : System.Windows.Forms.Form {
    private const string manifest
        = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>\r\n"
            + "<assembly "
                +" xmlns=\"urn:schemas-microsoft-com:asm.v1\" "
                + "manifestVersion=\"1.0\">\r\n"
            + "<description></description>\r\n"
            + "<dependency>\r\n"
            + "\t<dependentAssembly>\r\n"
            + "\t</dependentAssembly>\r\n"
            + "</dependency>\r\n"
            + "</assembly>";

    public Form() {
        Label label = new Label();
        label.Text = "exe をドロップしてください";
        label.Dock  = DockStyle.Fill;
        label.TextAlign = ContentAlignment.MiddleCenter;
        this.Controls.Add( label  );

        this.Text = "XPStyle Eraser";
        this.AllowDrop = true;
        this.TopMost   = true;
    }

    protected override void OnDragDrop( DragEventArgs e ) {
        if( e.Data.GetDataPresent(DataFormats.FileDrop) ) {
            string[] files = (string[])e.Data.GetData(DataFormats.FileDrop);
            foreach( string filePass in files ) {
                StreamWriter stream= null;
                try {
                    stream = File.CreateText( filePass+".manifest" );
                    stream.Write( manifest  );
                }
                // TODO: 必要なら例外処理を実装してください
                finally {
                    if( stream != null ) stream.Close();
                }
            }
        }
    }

    protected override void OnDragEnter( DragEventArgs e ) {
        if (e.Data.GetDataPresent(DataFormats.Bitmap) || 
            e.Data.GetDataPresent(DataFormats.FileDrop) )
        {
            e.Effect = DragDropEffects.Copy;
        } else {
            e.Effect = DragDropEffects.None;
        }
    }

    [STAThread]
    static void Main() {
        Application.Run( new Form() );
    }
}

コンパイル方法が分からない人は、.NET Framework(Runtime で可)をインストールした後小野さんのコンパイルツール辺りを使用すると分かりやすいかと思います。作成されたexeの使い方は窓内にファイルをドロップするだけです。

<>等を実態参照に置き換えるを忘れてたので修正。

2004/02/18(水) 17:13 方位記号 さん
Window Form アプリは Main() に STAThread 属性が必須なようなのでつけてみる。

2004/02/20(金) 16:43 方位記号 さん

コメントを追加

名前、コメントは必須です。HTMLタグ、実態参照文字は使うことが出来ません。クッキーは年内対応予定。URI,メールアドレスはリンクを張ります。

名前 : 
Mail : 
Web : 

goto Top

Copyright(C)方位記号

Gポイントポイ活 Amazon Yahoo 楽天

無料ホームページ 楽天モバイル[UNLIMITが今なら1円] 海外格安航空券 海外旅行保険が無料!