| ||||
■ Win32 APIを使用するWin32 APIを使用するにはSystem.Runtime.InteropServicesを使って、以下のように宣言する。DllImport属性で目的のAPIが属するDLLを指定する。呼び出しは通常のメソッド呼び出しと同様に行うことができる。
using System.Runtime.InteropServices;
namespace Test
{
public class Form1 : System.Windows.Forms.Form
{
[DllImport("user32.dll")]
extern static IntPtr GetDesktopWindow();
// 途中省略
private void menuItem1_Click(object sender, System.EventArgs e)
{
IntPtr h = GetDesktopWindow();
Debug.WriteLine("h = " + h);
}
}
}
この例ではAPIのGetDesktopWindowを呼び出してデスクトップのハンドルを取得している。 (2005/07/12)
Copyright(C) 2004-2012 モバイル開発系(K) All rights reserved.
[Home]
|