The code library in C#, comprised of classes that abstract and encapsulate such notions such as instruction set, font data, model number etc. What is good at this library is it runs threads and the 'server' takes commands and send them for number of times until they are passed to the module. Namely, the commands is queue until the event is processed.
A server is also called daemon that runs as a separate process along with the main procedure.
A queue is a FIFO that stack data for processing when the resources are available.
An event is a chunk of data that will be passed to the queue which contains the necessary data for each transaction.
Abstraction is a process that parameterize any variables that can be applied to same sort of procedure.
Encapsulation is a process to separate a set of data from direct manipulation so that any modification to the data will be monitored.
A thread is a process that can be processed pseudo simultaneously. The processor process each thread one at a time so it is pseudo-simultaneous.
With this library, commands are passed to the module in a safer and more secure manner. The server can wait, for sending data and receiving the data at the same time while queuing other data as well.
木曜日, 9月 29, 2011
水曜日, 8月 31, 2011
Java and C++ Exception Handling
Java and C++ differs in how to handle exceptions. In Java, every possible exception must be handled. In C++, the exceptions handling can be omitted.
The demerit of not having to write exception handling procedure is not of optimization but in the safe programming practice. The exceptions readied for the methods will be thrown away, which might cause some fatal errors. Java has it that those have to be taken care of. Every method that throws exceptions must declare as "throws Exception" or any exception class. When the method is called, it must be in the try-catch block.
The counter argument is that when exception handling can be omitted, the code can be short as pointed out by this g++ user(s), the program size will not be affected unless the exceptions are explicitly stated to be thrown and handled in case of the g++ compiler. You can safely ignore any error message the original library writer tried to warn you in calling the methods. And those who use the method won't be warned as well.
There is no way to assume that any method won't throw exceptions, unless explicitly stated as in Java code, as throws Exception. Going through all the possibilities to make sure that the method that you are calling does not call just any method that throws exceptions, is if not an impossible task then tedious work. Therefore, this practice may leave the programmer unsafe and the products made from those libraries.
The demerit of not having to write exception handling procedure is not of optimization but in the safe programming practice. The exceptions readied for the methods will be thrown away, which might cause some fatal errors. Java has it that those have to be taken care of. Every method that throws exceptions must declare as "throws Exception" or any exception class. When the method is called, it must be in the try-catch block.
The counter argument is that when exception handling can be omitted, the code can be short as pointed out by this g++ user(s), the program size will not be affected unless the exceptions are explicitly stated to be thrown and handled in case of the g++ compiler. You can safely ignore any error message the original library writer tried to warn you in calling the methods. And those who use the method won't be warned as well.
There is no way to assume that any method won't throw exceptions, unless explicitly stated as in Java code, as throws Exception. Going through all the possibilities to make sure that the method that you are calling does not call just any method that throws exceptions, is if not an impossible task then tedious work. Therefore, this practice may leave the programmer unsafe and the products made from those libraries.
火曜日, 8月 16, 2011
Why, just why?
The Professional edition of Visual Studio 2010 C++ does not compile dependent projects right.
It does not compile the static or dynamic libraries even when the configuration is set to compile them. This bug is more annoying since it says Rebuild All Succeeded when it is set to be compiled from the main project. This can be avoided if the project is compiled separately.
This is such a major bug that it is rather puzzling it is not set in that way, particularly in C++. Could there a way to compile them all together?
土曜日, 8月 13, 2011
Visual Studio: Refactoring
Microsoft's Visual Studio has a very nice feature called 'refactor'. It replaces the names of a method or function to whatever you rename it. It does contextual search and replace. The same name used in other namespace or scope will not be affected. It alleviates all the troubles associated with renaming. In the end, the code would come up closer to the final products no matter how you change your course of programming.
Visual Studio's C# refactor, however, is not perfect. It replaces the names even when there are the same names within the scope. There is no way to distinguish the variables that has renamed and the existing variables with the same name. That certainly is detectable. As for C++ version of the IDE, there isn't such a function to rename methods and variables with contextual searches.
Visual Studio's C# refactor, however, is not perfect. It replaces the names even when there are the same names within the scope. There is no way to distinguish the variables that has renamed and the existing variables with the same name. That certainly is detectable. As for C++ version of the IDE, there isn't such a function to rename methods and variables with contextual searches.
土曜日, 8月 06, 2011
C#の列挙型
C#の列挙型は特殊です。
列挙型は、Cなどでは定数程度としか使えませんが、C#では名前を取得したり、オブジェクトから列挙型の値を得ることができます。
FontStyle fontStyle = (FontStyle)Enum.Parse(typeof(FontStyle), (string)obj);
「今までと違う」列挙型は、なにも嫌がらせのためにあるわけではなく、これこそはコンピュータ科学の成果であり、技術の進歩...と声を大にして言いたいところですが、あまり主張すると「シカト」などの憂き目にあうのでリーマン稼業の人間には注意が必要です。
改革は、草の根から...ですね。
列挙型は、Cなどでは定数程度としか使えませんが、C#では名前を取得したり、オブジェクトから列挙型の値を得ることができます。
FontStyle fontStyle = (FontStyle)Enum.Parse(typeof(FontStyle), (string)obj);
「今までと違う」列挙型は、なにも嫌がらせのためにあるわけではなく、これこそはコンピュータ科学の成果であり、技術の進歩...と声を大にして言いたいところですが、あまり主張すると「シカト」などの憂き目にあうのでリーマン稼業の人間には注意が必要です。
改革は、草の根から...ですね。
木曜日, 7月 28, 2011
C#: ComboBox をカスタマイズする
ComboBox リスト項目の描画をカスタマイズし、チェックマークなど描く方法を説明します。
ComboBox のリスト項目は、単なる Object クラスです。つまり、リスト項目クラスを継承などしてデータを追加することはできません。適宜、ComboBox クラスにリストなどデータ構造を用意してデータを保存します。
データの準備ができたら、ComboBox のプロパティで DrawMode を OwnerDrawVariable に変更してやります。ここを変更すると、リスト項目の描画イベントをオーバーライドすることができます。DrawItem イベントに、イベントハンドラを追加し、描画手順を記述します。
具体的にはこのように描画をすべて記述することになります。
ComboBox のリスト項目は、単なる Object クラスです。つまり、リスト項目クラスを継承などしてデータを追加することはできません。適宜、ComboBox クラスにリストなどデータ構造を用意してデータを保存します。
データの準備ができたら、ComboBox のプロパティで DrawMode を OwnerDrawVariable に変更してやります。ここを変更すると、リスト項目の描画イベントをオーバーライドすることができます。DrawItem イベントに、イベントハンドラを追加し、描画手順を記述します。
具体的にはこのように描画をすべて記述することになります。
private void comboBox1_DrawItem(object sender, DrawItemEventArgs e) { e.DrawBackground(); if (e.Index < comboBox1.Items.Count) { e.Graphics.DrawString((string)comboBox1.Items[e.Index], e.Font, Brushes.Black, e.Bounds); if (e.Index < modifiedMessages.Count() && modifiedMessages[e.Index]) { Bitmap bmp = new Bitmap(Properties.Resources.checkMark); int iconWidth = 16; int iconHeight = 16; e.Graphics.DrawImage(bmp, e.Bounds.Right - iconWidth, e.Bounds.Bottom - iconHeight, iconWidth, iconHeight); } } e.DrawFocusRectangle(); }
火曜日, 6月 21, 2011
iPad Safari's Arabic/Persian scripts drawing bug
Safari on iPad has a bug -- does not draw Arabic/Persian scripts right when font tag is in between.
It should look like the bottom but looks like the top, the supposed connected form of the letter appear in an independent form.
Firefox either on the Ubuntu platform or the Windows seems to draw it correctly.
It should look like the bottom but looks like the top, the supposed connected form of the letter appear in an independent form.
Firefox either on the Ubuntu platform or the Windows seems to draw it correctly.
水曜日, 6月 08, 2011
DataGridView: 初期値を指定する
DataGridView を使うと、テーブル形式でデータを扱うことができます。
それぞれのコラムで、値を限定し、ドロップダウンリストで選択できるようにすることもできます。
ただし、この場合には、値に制限がつくことになるので、つねに決められた値を設定してやる必要があります。
つまり、新規にデータを追加する場合など、値を空白とすることはできません。
この際には、データを追加するたびに、初期値を設定してやる必要があります。
なぜかDataTableなどではデフォルト値を設定するメソッドがありません。
イベントをフックし、値を設定してやります。
次に示すコードは、それぞれのコラムの値に適応した初期値を新規作成されたデータに設定するやり方を示したものです。
本来ならば、設定するコラムでそれぞれデフォルト値を設定できるような仕組みになっているべきではあると思います。
それぞれのコラムで、値を限定し、ドロップダウンリストで選択できるようにすることもできます。
ただし、この場合には、値に制限がつくことになるので、つねに決められた値を設定してやる必要があります。
つまり、新規にデータを追加する場合など、値を空白とすることはできません。
この際には、データを追加するたびに、初期値を設定してやる必要があります。
なぜかDataTableなどではデフォルト値を設定するメソッドがありません。
イベントをフックし、値を設定してやります。
次に示すコードは、それぞれのコラムの値に適応した初期値を新規作成されたデータに設定するやり方を示したものです。
private void dataGridView1_CellFormatting(object sender , DataGridViewCellFormattingEventArgs e) { if (e.Value == null) { switch (e.ColumnIndex) { case 0: e.Value=dataGridView1.Rows.Count; break; case 1: break; case 2: e.Value = "Instant"; break; case 3: break; case 4: e.Value = "0"; break; case 5: e.Value = "0 sec"; break; } } }
本来ならば、設定するコラムでそれぞれデフォルト値を設定できるような仕組みになっているべきではあると思います。
The formality problem: Java and C# -- extended class
Small things get in the way.
The way to write extended classes in Java and C# differs slightly.
Just for the record the following cases depicts the differences.
The extended class -- the case with Java:
The extended class -- the case with C#:
The way to write extended classes in Java and C# differs slightly.
Just for the record the following cases depicts the differences.
The extended class -- the case with Java:
public class NewClassTest { class A { int i=0; A(int i) { this.i=i; } } class B extends A { B() { super(1); } } public void test() { System.out.println(new B().i); } public static void main(String args[]) { new NewClassTest().test(); } }
The extended class -- the case with C#:
class Class1 { protected string value = "to be overwritten"; public Class1(string convert) { value = convert; } } class Class2 : Class1 { public Class2(string additional, string convert) : base(convert) { value = convert + additional; } public string value { get; set; } } public partial class Form1 : Form { public Form1() { InitializeComponent(); Class2 test = new Class2(" additional text", "original text"); label1.Text = test.value; } }
土曜日, 6月 04, 2011
C# プログレスバーの色を変える
C#のライブラリでは、プログレスバーの色を変えるメソッドが用意されていません。
そこで、「メモリ容量がいっぱいになりました」的な状態を示すために、プログレスバーの色を緑から赤に変える方法を紹介します。
このように、Win32APIを呼び出す関数を用意して、エラー状態をセットしてやります。
もとの緑色に変更するには、ノーマル状態に戻してやります。
追記: ここで注意せねばならないのは、プログレスバーのバグで、エラー状態を設定した時点では値が変更されません。
エラー状態を設定したら、値の変更を再度行う必要があります。
これはWindowsのバグらしいです。
そこで、「メモリ容量がいっぱいになりました」的な状態を示すために、プログレスバーの色を緑から赤に変える方法を紹介します。
using System.Runtime.InteropServices; const int WM_USER = 0x400; const int PBM_SETSTATE = WM_USER + 16; const int PBM_GETSTATE = WM_USER + 17; [DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = false)] public static extern IntPtr SendMessage(IntPtr hWnd, uint Msg, IntPtr wParam, IntPtr lParam);
このように、Win32APIを呼び出す関数を用意して、エラー状態をセットしてやります。
public enum ProgressBarStateEnum : int { Normal = 1, Error = 2, Paused = 3, } public static void SetState(ProgressBar pBar, ProgressBarStateEnum state) { SendMessage(pBar.Handle, PBM_SETSTATE, (IntPtr)state, IntPtr.Zero); } SetState(progressBar1, ProgressBarStateEnum.Error);
もとの緑色に変更するには、ノーマル状態に戻してやります。
SetState(progressBar1, ProgressBarStateEnum.Normal);
追記: ここで注意せねばならないのは、プログレスバーのバグで、エラー状態を設定した時点では値が変更されません。
エラー状態を設定したら、値の変更を再度行う必要があります。
これはWindowsのバグらしいです。
if (progressBar1.Maximum * .9 < len) { progressBar1.Value = 0; SetState(progressBar1, ProgressBarStateEnum.Normal); progressBar1.Value = len; SetState(progressBar1, ProgressBarStateEnum.Error); } else { progressBar1.Value = len; SetState(progressBar1, ProgressBarStateEnum.Normal); }
水曜日, 6月 01, 2011
フォームで、まとめてイベントを管理 AddMessageFilter()
Windows フォームで、まとめてイベントを管理したいとします。
その場でテキストエディターを立ち上げて、文字列を編集するときなど、部品全てについてイベント処理しなければなりません。
テキストエディターで編集して、コンポーネントからフォーカスが外れたとき、イベントを管理する必要があります。
これが意外な難関で、WinProcをオーバーライドしても、このメソッドではイベントが処理されません。個々のコンポーネントで処理しなければなりません。
そこで用意されているのが、ApplicationクラスにあるAddMessageFilter()メソッドです。
Application.AddMessageFilter(new MyMessageFilter())
このような形で、MessageFilter派生クラスを指定してやります。
イベント処理は、MessageFilterクラスのPreFilterMessage()メソッドで行います。
ここで、WM_NCLBUTTONDBLCLK 、WM_NCLBUTTONDOWN はタイトルバーでのイベントで、WM_LBUTTONDOWNはクライアントエリアで発生するイベントを指します。
こんな感じです。
その場でテキストエディターを立ち上げて、文字列を編集するときなど、部品全てについてイベント処理しなければなりません。
テキストエディターで編集して、コンポーネントからフォーカスが外れたとき、イベントを管理する必要があります。
これが意外な難関で、WinProcをオーバーライドしても、このメソッドではイベントが処理されません。個々のコンポーネントで処理しなければなりません。
そこで用意されているのが、ApplicationクラスにあるAddMessageFilter()メソッドです。
Application.AddMessageFilter(new MyMessageFilter())
このような形で、MessageFilter派生クラスを指定してやります。
イベント処理は、MessageFilterクラスのPreFilterMessage()メソッドで行います。
ここで、WM_NCLBUTTONDBLCLK 、WM_NCLBUTTONDOWN はタイトルバーでのイベントで、WM_LBUTTONDOWNはクライアントエリアで発生するイベントを指します。
こんな感じです。
private const int WM_LBUTTONDOWN = 0x201; private const int WM_NCLBUTTONDBLCLK = 0x00A3; private const int WM_NCLBUTTONDOWN = 0x00A1; public bool PreFilterMessage(ref Message msg) { switch (msg.Msg) { case WM_NCLBUTTONDBLCLK: case WM_NCLBUTTONDOWN: case WM_LBUTTONDOWN: { int lparam = (int)msg.LParam; int x = lparam & 0xffff; int y = lparam >> 16; Simulator simulator = (Simulator)sender; Point pos = simulator.RichTextBox1.PointToClient(new Point(x, y)); Rectangle rect = new Rectangle(0, 0, simulator.RichTextBox1.Bounds.Width , simulator.RichTextBox1.Bounds.Height + SystemInformation.HorizontalScrollBarThumbWidth); if (!rect.Contains(pos)) { simulator.focusOff(); } } break; } return false; }
日曜日, 5月 22, 2011
C# クラスのAPIレファレンスの自動生成
C#には、自動的にクラスのAPIレファレンスを作成する機能があります。
Visual Studioでは、プロジェクトのプロパティでXMLファイルを出力できます。
あとはSandcastle Help File Builderなどを使ってレファレンスの形にします。
Visual Studioでは、プロジェクトのプロパティでXMLファイルを出力できます。
あとはSandcastle Help File Builderなどを使ってレファレンスの形にします。
土曜日, 5月 07, 2011
C#の、プリンタの状態を示すクラス
C#では、プリンタの状態を示すクラスがあって便利です。
プリンタサーバーを指定するクラス PrintServer 、プリンタキューのリストを返すクラス PrintQueueCollection が準備されています。
プリンタキューからジョブリストを得るメソッド GetPrintJobInfoCollection もあります。
プリンタサーバーを指定するクラス PrintServer 、プリンタキューのリストを返すクラス PrintQueueCollection が準備されています。
プリンタキューからジョブリストを得るメソッド GetPrintJobInfoCollection もあります。
LocalPrintServer myPrintServer = new LocalPrintServer(); PrintQueueCollection myPrintQueues = myPrintServer.GetPrintQueues(); string jobList = ""; foreach (PrintQueue pq in myPrintQueues) { if (!pq.IsWaiting) { PrintJobInfoCollection jobs = pq.GetPrintJobInfoCollection(); foreach (PrintSystemJobInfo job in jobs) { jobList = jobList + "Job: " + job.JobName + " ID: " + job.JobIdentifier+"\n"; } } }
土曜日, 4月 09, 2011
C#の多次元配列
C#では、配列の宣言がJavaと異なります。
角カッコが、型のほうにつく。
(C#)
string[] nameList={"Ann","Chris","Freda","Darlene","Toni"};
こんな感じです。
これがJavaだと、変数名のほうにつきます。
(Java)
String list[]={"Brad","Alfie","Chris"};
こんなことでも、結構ストレスになるものです。
C#では、多次元配列がさらに特殊な形をとります。
(C#)
int[,] intList = { { 1, 2 }, { 3, 4 } };
あれ、というような意外感があるように思います。
さらに、Javaのように宣言する配列は、C#ではjagged配列という、また別なデータ構造を意味します。
これは、配列の配列という位置づけで、それぞれの配列の要素に、任意の配列を指定できます。
逆に言うと、それぞれの配列の要素に配列を指定しなければなりません。
(C#)
int[][] jaggedList =new int[2][];
jaggedList[0] = new int[2];
jaggedList[1] = new int[3];
注意が必要です。
角カッコが、型のほうにつく。
(C#)
string[] nameList={"Ann","Chris","Freda","Darlene","Toni"};
こんな感じです。
これがJavaだと、変数名のほうにつきます。
(Java)
String list[]={"Brad","Alfie","Chris"};
こんなことでも、結構ストレスになるものです。
C#では、多次元配列がさらに特殊な形をとります。
(C#)
int[,] intList = { { 1, 2 }, { 3, 4 } };
あれ、というような意外感があるように思います。
さらに、Javaのように宣言する配列は、C#ではjagged配列という、また別なデータ構造を意味します。
これは、配列の配列という位置づけで、それぞれの配列の要素に、任意の配列を指定できます。
逆に言うと、それぞれの配列の要素に配列を指定しなければなりません。
(C#)
int[][] jaggedList =new int[2][];
jaggedList[0] = new int[2];
jaggedList[1] = new int[3];
注意が必要です。
土曜日, 4月 02, 2011
仕事でC#を使うことに。
C#は、Javaもどきとしか認識しておりませんでしたが、なんといってもマイクロソフトのVisual Studioつき。
IDEが完備しているのは強い。情報もある、といえるでしょう。
使いやすい。
イベントの処理の方法など、VC・C++などと同様に扱えます。
無意味な数値を極力使わないJava系のよさも引き継いています
リソースに「番号」を振り分ける悪趣味は、ここにはない。
コンポーネントに追加した順番ですべてが決まります。
--
Eclipse と比較すると、ヘルプやサンプルコードにすぐにアクセス出来ない、遠い感じがします。
情報はすべからくHTML形式にして、ネットに置いて欲しいものです。
IDEが完備しているのは強い。情報もある、といえるでしょう。
使いやすい。
イベントの処理の方法など、VC・C++などと同様に扱えます。
無意味な数値を極力使わないJava系のよさも引き継いています
リソースに「番号」を振り分ける悪趣味は、ここにはない。
コンポーネントに追加した順番ですべてが決まります。
--
Eclipse と比較すると、ヘルプやサンプルコードにすぐにアクセス出来ない、遠い感じがします。
情報はすべからくHTML形式にして、ネットに置いて欲しいものです。
水曜日, 12月 29, 2010
電子書籍:世界標準、日本語も対応 EPUB縦書き可能に
電子書籍のEPUBが日本語に正式対応するという。
来年5月に完成予定のEPUB3.0は縦書きや句読点の禁則処理、ルビ表記などに対応するという。
電子書籍市場は爆発的な伸びを見せており、2010年は前年度比3倍超という試算があるという。
→ 電子書籍:世界標準、日本語も対応 EPUB縦書き可能に (2010-12-29)
来年5月に完成予定のEPUB3.0は縦書きや句読点の禁則処理、ルビ表記などに対応するという。
電子書籍市場は爆発的な伸びを見せており、2010年は前年度比3倍超という試算があるという。
→ 電子書籍:世界標準、日本語も対応 EPUB縦書き可能に (2010-12-29)
水曜日, 12月 01, 2010
水曜日, 10月 27, 2010
世界一安全な日本ドメイン
米マカフィーの「危険なウエブサイトの世界分布2010」によると、日本(.jp)ドメインは危険度0.1%と2年連続で最も安全な国別ドメインとなったという。
→ 最も危険な国別ドメインはベトナム マカフィー調査 (2010-10-27)
→ 最も危険な国別ドメインはベトナム マカフィー調査 (2010-10-27)
金曜日, 10月 22, 2010
Amazon.comのQ3決算、39%増収で16%増益
米アマゾン社は21日、同年代3四半期の決算を前年同期比39%増と発表したという。
→ Amazon.comのQ3決算、39%増収で16%増益 (2010-10-22)
フランスのFNACでも電子ブックを売っているようです。
→ E-book : La Fnac attaque Amazon avec sa liseuse FnacBook
全世界的な現象ですね。
→ Amazon.comのQ3決算、39%増収で16%増益 (2010-10-22)
フランスのFNACでも電子ブックを売っているようです。
→ E-book : La Fnac attaque Amazon avec sa liseuse FnacBook
全世界的な現象ですね。
月曜日, 10月 04, 2010
Firefoxをもっと便利にする10のテクニック
Firefox のショートカットやツールバー、アイコンについての記事をマイコミジャーナルで発見しました。
ちょうどこんなのが欲しかった 的な工夫が満載です。
ちょうどこんなのが欲しかった 的な工夫が満載です。
http://journal.mycom.co.jp/articles/2010/10/04/firefox-useful-10-tips/index.html
登録:
投稿 (Atom)
PHP: 定数を扱う
プロジェクトごとの定数を扱うクラス Config\Constants の紹介です。 <?php namespace Config; class Constants { public const DB_USER = "linguist...
-
Qt はまってます。Mac でも書いたアプリがコンパイルできて、しっかり動くのを確認しました。このあいだ Chitubox が Qt 使ってるのを知ってうれしかったです。 Mac でもそのまま動くんですが、アプリのアイコンの設定はプラットフォーム依存です。 公式マニュアルでも設定...
-
コンデンサマイク 極性があります コンデンサマイクがようやく届きました。モジュールではないのでそのままでは信号が弱いので使えません。信号を増幅する必要があります。 ちょっとした手間ですが、首尾よく動いてくれました。この回路の応用で、使えるマイクが出来ます。 ...
-
Flask/SQLAlchemy 使ってる方、jinja で困ってませんか? 本体で Python の関数を書いてもいいんですが、テンプレートでも関数が呼べます。 日付を出したい場合、フォーマットなら strftime() が使えます。 わざわざ文字列を作って渡す必...