|











|
 |
ウィンドウを整列させる
|
開発環境: Visual Studio 2003
|
|
|
|
|
|
Windows.Forms では、自分自身のWindow 自体は簡単に操作できるようになっていますが、
自分以外のWindow の操作に関しては何も用意されていません。
したがって、自分以外のウィンドウの操作をする場合には、プラットフォームSDK のウィンドウ関数で処理する必要があります。
|
|
|
(1) MSDN:
ウィンドウズ関数
(2) MSDN: コールバック関数の実装
|
|
|
プラットフォームSDKを使用して、自分以外のウィンドウの位置を操作するためのテストツールを作ります。
機能は次のようなものです。
このツールで、デスクトップウィンドウサイズのボタンは、文字通りデスクトップウィンドウサイズを取得し、TextBoxへ表示します。
メモ帳を起動する、メモ帳を移動するボタンは、メモ帳を起動し、そのメモ帳を指定した場所へ移動するテスト用です。
EnumWindows ボタンは、ListViewにビジブルな状態のウィンドウの詳細情報を表示するものです。
ListView の ウィンドウハンドル(hWnd)
を選択した状態で、移動テストボタンを押すと、そのウィンドウを特定の場所に移動するテスト用です。
IE を整列するボタンは、インターネットエクスプローラを整列させるテスト用です。

次のスクリーンショットは、IE を整列した様子です。
ただ、整列アルゴリズムは手を抜いているので、単にデスクトップの縦に分割して並べるだけです。^^

| 注意 |
動作確認は、Windows XP Professional Edition + VS.2003 Enterprise
Edition のみです。
95/98 系では動作しない可能性が高いです。
Platform SDK の動作環境を確認してください。
また、例によってエラー処理は思いっきりはしょっています。^^
|
|
|
|
ここで使用するプラットフォームSDKのウィンドウ関数です。
| GetDesktopWindow() :デスクトップウィンドウのハンドルを取得します。 |
// HWND GetDesktopWindow(VOID);
[DllImport("User32.Dll")]
static extern IntPtr GetDesktopWindow();
|
| GetWindowRect() :ウィンドウハンドルよりウィンドウの大きさを取得します。 |
// typedef struct _RECT
// {
// LONG left;
// LONG top;
// LONG right;
// LONG bottom;
// } RECT, *PRECT;
[StructLayout(LayoutKind.Sequential, Pack = 4)]
private struct RECT
{
public int left;
public int top;
public int right;
public int bottom;
}
// BOOL GetWindowRect(
// HWND hWnd, // ウィンドウのハンドル
// LPRECT lpRect // ウィンドウの座標値
// );
[DllImport("User32.Dll")]
static extern int GetWindowRect(
IntPtr hWnd, // ウィンドウのハンドル
out RECT rect // ウィンドウの座標値
);
|
| MoveWindow() :ウィンドウを移動します。 |
// BOOL MoveWindow(
// HWND hWnd, // ウィンドウのハンドル
// int X, // 横方向の位置
// int Y, // 縦方向の位置
// int nWidth, // 幅
// int nHeight, // 高さ
// BOOL bRepaint // 再描画オプション
// );
[DllImport("User32.dll")]
static extern int MoveWindow(
IntPtr hWnd,
int x,
int y,
int nWidth,
int nHeight,
int bRepaint
);
|
| FindWindow() :クラス名、ウィンドウ名に一致するウィンドウのハンドルを返します。 |
// HWND FindWindow(
// LPCTSTR lpClassName, // クラス名
// LPCTSTR lpWindowName // ウィンドウ名
// );
// Unicode:Windows NT/2000 は Unicode 版と ANSI 版を実装
[DllImport("User32.dll", CharSet = CharSet.Unicode)]
static extern IntPtr FindWindow(
string lpszClass,
string lpszWindow
);
|
| SetForegroundWindow() :ウィンドウをフォアグラウンドにし、アクティブにします。 |
// BOOL SetForegroundWindow(
// HWND hWnd // ウィンドウのハンドル
// );
[DllImport("User32.dll")]
static extern int SetForegroundWindow(
IntPtr hWnd
);
|
| GetClassName() :ウィンドウのクラス名を返します。 |
// int GetClassName(
// HWND hWnd, // ウィンドウのハンドル
// LPTSTR lpClassName, // クラス名
// int nMaxCount // クラス名バッファのサイズ
// );
// Unicode:Windows NT/2000 は Unicode 版と ANSI 版を実装
[DllImport("User32.Dll", CharSet = CharSet.Unicode)]
public static extern int GetClassName(
IntPtr hWnd,
StringBuilder s,
int nMaxCount
);
|
| GetWindowText() :ウィンドウのタイトルバーのテキストを返します。 |
// int GetWindowText(
// HWND hWnd, // ウィンドウまたはコントロールのハンドル
// LPTSTR lpString, // テキストバッファ
// int nMaxCount // コピーする最大文字数
// );
// Unicode:Windows NT/2000 は Unicode 版と ANSI 版を実装
[DllImport("User32.Dll", CharSet = CharSet.Unicode)]
static extern int GetWindowText(
IntPtr hWnd,
StringBuilder s,
int nMaxCount
);
|
| GetParent() :親のウィンドウのハンドルを返します。 |
// HWND GetParent(
// HWND hWnd // 子ウィンドウのハンドル
// );
[DllImport("User32.Dll")]
static extern int GetParent(
IntPtr hWnd
);
|
| IsWindowVisible() :ウィンドウがVISIBLEかどうかを返します。 |
// BOOL IsWindowVisible(
// HWND hWnd // ウィンドウのハンドル
// );
[DllImport("User32.Dll")]
static extern int IsWindowVisible(
IntPtr hWnd
);
|
| IsChild() :ウィンドウが子ウィンドウかどうかを返します。 |
// BOOL IsChild(
// HWND hWndParent, // 親ウィンドウのハンドル
// HWND hWnd // 調査するウィンドウのハンドル
// );
[DllImport("User32.Dll")]
static extern int IsChild(
IntPtr hWnd
);
|
| ShowWindow() :ウィンドウの表示状態を設定します。 |
// BOOL ShowWindow(
// HWND hWnd, // ウィンドウのハンドル
// int nCmdShow // 表示状態
// );
const int SW_HIDE = 0;
const int SW_SHOWNORMAL = 1;
const int SW_NORMAL = 1;
const int SW_SHOWMINIMIZED = 2;
const int SW_SHOWMAXIMIZED = 3;
const int SW_MAXIMIZE = 3;
const int SW_SHOWNOACTIVATE = 4;
const int SW_SHOW = 5;
const int SW_MINIMIZE = 6;
const int SW_SHOWMINNOACTIVE = 7;
const int SW_SHOWNA = 8;
const int SW_RESTORE = 9;
const int SW_SHOWDEFAULT = 10;
const int SW_FORCEMINIMIZE = 11;
const int SW_MAX = 11;
[DllImport("User32.Dll")]
static extern int ShowWindow(
IntPtr hWnd,
int nCmdShow
);
|
| EnumWindows() :ウィンドウを列挙します。コールバック関数が呼び出されます。 |
public delegate bool EnumWindowCallBack(IntPtr hwnd, IntPtr lParam);
・・・・
[DllImport("user32.Dll")]
static extern int EnumWindows(EnumWindowCallBack x, IntPtr y);
|
|
|
|
EnumWindows(....)では、コールバック関数を使用します。
コールバック関数については、参考文献(1)の説明が詳しいのでそちらをご覧になってください。
簡単に説明すると、
EnumWindows(...) を呼び出すと、すべてのウィンドウに対してコールバック関数が順次呼び出されます。
コールバック関数の中で、ウィンドウの情報を取得することになります。
すべてのウィンドウのコールバック関数がリターンした段階で、EnumWindows(...) が終了します。
このとき、画面に表示されないウィンドウに対してもコールバックがかかってしまいます。
通常は、画面に表示されているウィンドウに対しての操作が主になりますから、それを判定してあげる必要があります。
このテストツールで、ListView にウィンドウの情報を表示している部分の骨格を次に示します。
これからわかるように、コールバック関数EnumWindowCallBackをデリゲイトで宣言します。
次に、ボタンが押されたときに、
EnumWindows(new EnumWindowCallBack(Form1.ListViewCallBack),
this.listView1.Handle)
というように、コールバック関数とリストビューコントロールのハンドルを渡してあげます。
すると、すべてのウィンドウに対してコールバックされ、ListViewCallBack が呼び出されます。
この中で、ウィンドウがビジブルなもののウィンドウクラス名、ウィンドウテキストをリストビューに追加するように処理しています。
using ....
public delegate bool EnumWindowCallBack(IntPtr hwnd, IntPtr lParam);
namespace WindowsApplication14
{
public class Form1 : System.Windows.Forms.Form
{
....
[DllImport("user32.Dll")]
static extern int EnumWindows(EnumWindowCallBack x, IntPtr y);
public static bool ListViewCallBack(IntPtr hwnd, IntPtr lParam)
{
ListView lview = (ListView)FromHandle(lParam);
StringBuilder sbClassName = new StringBuilder(256);
StringBuilder sbWindowText = new StringBuilder(256);
string hasParent = "";
if (GetParent(hwnd) > 0)
hasParent = "Has Parent";
else
hasParent = "";
GetClassName(hwnd, sbClassName, sbClassName.Capacity);
if( sbClassName.Length > 0 && IsWindowVisible(hwnd) > 0)
{
GetWindowText(hwnd, sbWindowText, sbWindowText.Capacity);
ListViewItem item = lview.Items.Add(hwnd.ToString());
item.SubItems.Add(hasParent);
item.SubItems.Add(sbClassName.ToString());
item.SubItems.Add(sbWindowText.ToString());
}
return true;
}
private void button4_Click(object sender, System.EventArgs e)
{
EnumWindows(new EnumWindowCallBack(Form1.ListViewCallBack), this.listView1.Handle);
}
}
}
|
|
|
ここまでくれば、どのように IE を整列させればよいか想像がつくと思います。
デスクトップの大きさを調べる。
IE のウィンドウの数を EnumWindows で調べる。
IE を表示させ、ウィンドウの位置を MoveWindow(..)で調整する。 という流れになります。
処理的には、public でArrayList を出していてかっちょ悪いですが、とりあえず動作確認用ということで^^
using ....
public delegate bool EnumWindowCallBack(IntPtr hwnd, IntPtr lParam);
namespace WindowsApplication14
{
public class Form1 : System.Windows.Forms.Form
{
public Form1()
{
....
}
[STAThread]
static void Main()
{
....
}
[DllImport("user32.Dll")]
static extern int EnumWindows(EnumWindowCallBack x, IntPtr y);
public static bool IECallBack(IntPtr hwnd, IntPtr lParam)
{
StringBuilder sbClassName = new StringBuilder(256);
GetClassName(hwnd, sbClassName, sbClassName.Capacity);
if( sbClassName.ToString().StartsWith("IEFrame"))
{
Form1.al.Add(hwnd);
}
return true;
}
public static ArrayList al = null;
private void button6_Click(object sender, System.EventArgs e)
{
al = new ArrayList();
// デスクトップウィンドウのサイズを求める。
RECT rect;
GetWindowRect(GetDesktopWindow(), out rect);
// EnumWindows でIECallBack へさせる。
EnumWindows(new EnumWindowCallBack(Form1.IECallBack), IntPtr.Zero);
// デスクトップウィンドウの縦サイズをIEの数で割る。
int hw = rect.bottom / al.Count;
// IE を整列させる。
for(int i = 0; i < al.Count; i++)
{
SetForegroundWindow((IntPtr)al[i]);
ShowWindow((IntPtr)al[i], SW_SHOWNORMAL);
MoveWindow((IntPtr)al[i], 0, i*hw, rect.right/3, hw, 1);
}
}
}
}
|
|
|
FindWindow()で必要となる主なウィンドウクラス名です。
| アプリケーション | ウィンドウクラス |
| エクスプローラ | ExplorerWClass |
| メモ帳 | Notepad |
| インターネットエクスプローラ | IEFrame |
| マイクロソフトワード 2003 | OpusApp |
| マイクロソフトエクセル 2003 | XLMAIN |
|
|
|
| 変更履歴 |
| 2003/11/24 | 初版作成 (注意:エラー手を抜いています) |
| Form1.cs |
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.Diagnostics;
using System.Runtime.InteropServices;
using System.Text;
public delegate bool EnumWindowCallBack(IntPtr hwnd, IntPtr lParam);
namespace WindowsApplication14
{
/// <summary>
/// Form1 の概要の説明です。
/// </summary>
public class Form1 : System.Windows.Forms.Form
{
private System.Windows.Forms.Button button1;
private System.Windows.Forms.Button button2;
private System.Windows.Forms.Button button3;
private System.Windows.Forms.Button button4;
private System.Windows.Forms.Button button5;
private System.Windows.Forms.TextBox textBox1;
private System.Windows.Forms.ListView listView1;
private System.Windows.Forms.ColumnHeader columnHeader1;
private System.Windows.Forms.ColumnHeader columnHeader2;
private System.Windows.Forms.ColumnHeader columnHeader3;
private System.Windows.Forms.ColumnHeader columnHeader4;
private System.Windows.Forms.Button button6;
/// <summary>
/// 必要なデザイナ変数です。
/// </summary>
private System.ComponentModel.Container components = null;
public Form1()
{
//
// Windows フォーム デザイナ サポートに必要です。
//
InitializeComponent();
//
// TODO: InitializeComponent 呼び出しの後に、コンストラクタ コードを追加してください。
//
}
/// <summary>
/// 使用されているリソースに後処理を実行します。
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}
#region Windows フォーム デザイナで生成されたコード
/// <summary>
/// デザイナ サポートに必要なメソッドです。このメソッドの内容を
/// コード エディタで変更しないでください。
/// </summary>
private void InitializeComponent()
{
this.button1 = new System.Windows.Forms.Button();
this.button2 = new System.Windows.Forms.Button();
this.button3 = new System.Windows.Forms.Button();
this.button4 = new System.Windows.Forms.Button();
this.button5 = new System.Windows.Forms.Button();
this.textBox1 = new System.Windows.Forms.TextBox();
this.listView1 = new System.Windows.Forms.ListView();
this.columnHeader1 = new System.Windows.Forms.ColumnHeader();
this.columnHeader2 = new System.Windows.Forms.ColumnHeader();
this.columnHeader3 = new System.Windows.Forms.ColumnHeader();
this.columnHeader4 = new System.Windows.Forms.ColumnHeader();
this.button6 = new System.Windows.Forms.Button();
this.SuspendLayout();
//
// button1
//
this.button1.Location = new System.Drawing.Point(16, 8);
this.button1.Name = "button1";
this.button1.Size = new System.Drawing.Size(144, 23);
this.button1.TabIndex = 0;
this.button1.Text = "デスクトップウィンドウサイズ";
this.button1.Click += new System.EventHandler(this.button1_Click);
//
// button2
//
this.button2.Location = new System.Drawing.Point(16, 48);
this.button2.Name = "button2";
this.button2.Size = new System.Drawing.Size(144, 23);
this.button2.TabIndex = 1;
this.button2.Text = "メモ帳を起動する";
this.button2.Click += new System.EventHandler(this.button2_Click);
//
// button3
//
this.button3.Location = new System.Drawing.Point(184, 48);
this.button3.Name = "button3";
this.button3.Size = new System.Drawing.Size(144, 23);
this.button3.TabIndex = 2;
this.button3.Text = "メモ帳を移動する";
this.button3.Click += new System.EventHandler(this.button3_Click);
//
// button4
//
this.button4.Location = new System.Drawing.Point(16, 88);
this.button4.Name = "button4";
this.button4.Size = new System.Drawing.Size(144, 23);
this.button4.TabIndex = 3;
this.button4.Text = "EnumWindows";
this.button4.Click += new System.EventHandler(this.button4_Click);
//
// button5
//
this.button5.Location = new System.Drawing.Point(184, 88);
this.button5.Name = "button5";
this.button5.Size = new System.Drawing.Size(144, 23);
this.button5.TabIndex = 4;
this.button5.Text = "移動テスト";
this.button5.Click += new System.EventHandler(this.button5_Click);
//
// textBox1
//
this.textBox1.Location = new System.Drawing.Point(184, 8);
this.textBox1.Name = "textBox1";
this.textBox1.Size = new System.Drawing.Size(280, 19);
this.textBox1.TabIndex = 5;
this.textBox1.Text = "";
//
// listView1
//
this.listView1.Columns.AddRange(new System.Windows.Forms.ColumnHeader[] {
this.columnHeader1,
this.columnHeader2,
this.columnHeader3,
this.columnHeader4});
this.listView1.Dock = System.Windows.Forms.DockStyle.Bottom;
this.listView1.Location = new System.Drawing.Point(0, 158);
this.listView1.Name = "listView1";
this.listView1.Size = new System.Drawing.Size(512, 224);
this.listView1.TabIndex = 6;
this.listView1.View = System.Windows.Forms.View.Details;
//
// columnHeader1
//
this.columnHeader1.Text = "hWnd";
this.columnHeader1.Width = 71;
//
// columnHeader2
//
this.columnHeader2.Text = "Parent";
this.columnHeader2.Width = 76;
//
// columnHeader3
//
this.columnHeader3.Text = "ClassName";
this.columnHeader3.Width = 132;
//
// columnHeader4
//
this.columnHeader4.Text = "WindowName";
this.columnHeader4.Width = 223;
//
// button6
//
this.button6.Location = new System.Drawing.Point(16, 128);
this.button6.Name = "button6";
this.button6.Size = new System.Drawing.Size(144, 23);
this.button6.TabIndex = 7;
this.button6.Text = "IEを整列";
this.button6.Click += new System.EventHandler(this.button6_Click);
//
// Form1
//
this.AutoScaleBaseSize = new System.Drawing.Size(5, 12);
this.ClientSize = new System.Drawing.Size(512, 382);
this.Controls.Add(this.button6);
this.Controls.Add(this.listView1);
this.Controls.Add(this.textBox1);
this.Controls.Add(this.button5);
this.Controls.Add(this.button4);
this.Controls.Add(this.button3);
this.Controls.Add(this.button2);
this.Controls.Add(this.button1);
this.Name = "Form1";
this.Text = "Form1";
this.ResumeLayout(false);
}
#endregion
/// <summary>
/// アプリケーションのメイン エントリ ポイントです。
/// </summary>
[STAThread]
static void Main()
{
Application.Run(new Form1());
}
// BOOL MoveWindow(
// HWND hWnd, // ウィンドウのハンドル
// int X, // 横方向の位置
// int Y, // 縦方向の位置
// int nWidth, // 幅
// int nHeight, // 高さ
// BOOL bRepaint // 再描画オプション
// );
[DllImport("User32.dll")]
static extern int MoveWindow(
IntPtr hWnd,
int x,
int y,
int nWidth,
int nHeight,
int bRepaint
);
// HWND FindWindow(
// LPCTSTR lpClassName, // クラス名
// LPCTSTR lpWindowName // ウィンドウ名
// );
// Unicode:Windows NT/2000 は Unicode 版と ANSI 版を実装
[DllImport("User32.dll", CharSet = CharSet.Unicode)]
static extern IntPtr FindWindow(
string lpszClass,
string lpszWindow
);
// BOOL SetForegroundWindow(
// HWND hWnd // ウィンドウのハンドル
// );
[DllImport("User32.dll")]
static extern int SetForegroundWindow(
IntPtr hWnd
);
// int GetClassName(
// HWND hWnd, // ウィンドウのハンドル
// LPTSTR lpClassName, // クラス名
// int nMaxCount // クラス名バッファのサイズ
// );
// Unicode:Windows NT/2000 は Unicode 版と ANSI 版を実装
[DllImport("User32.Dll", CharSet = CharSet.Unicode)]
public static extern int GetClassName(
IntPtr hWnd,
StringBuilder s,
int nMaxCount
);
// int GetWindowText(
// HWND hWnd, // ウィンドウまたはコントロールのハンドル
// LPTSTR lpString, // テキストバッファ
// int nMaxCount // コピーする最大文字数
// );
// Unicode:Windows NT/2000 は Unicode 版と ANSI 版を実装
[DllImport("User32.Dll", CharSet = CharSet.Unicode)]
static extern int GetWindowText(
IntPtr hWnd,
StringBuilder s,
int nMaxCount
);
// HWND GetParent(
// HWND hWnd // 子ウィンドウのハンドル
// );
[DllImport("User32.Dll")]
static extern int GetParent(
IntPtr hWnd
);
// BOOL IsWindowVisible(
// HWND hWnd // ウィンドウのハンドル
// );
[DllImport("User32.Dll")]
static extern int IsWindowVisible(
IntPtr hWnd
);
// BOOL IsChild(
// HWND hWndParent, // 親ウィンドウのハンドル
// HWND hWnd // 調査するウィンドウのハンドル
// );
[DllImport("User32.Dll")]
static extern int IsChild(
IntPtr hWnd
);
// BOOL ShowWindow(
// HWND hWnd, // ウィンドウのハンドル
// int nCmdShow // 表示状態
// );
const int SW_HIDE = 0;
const int SW_SHOWNORMAL = 1;
const int SW_NORMAL = 1;
const int SW_SHOWMINIMIZED = 2;
const int SW_SHOWMAXIMIZED = 3;
const int SW_MAXIMIZE = 3;
const int SW_SHOWNOACTIVATE = 4;
const int SW_SHOW = 5;
const int SW_MINIMIZE = 6;
const int SW_SHOWMINNOACTIVE = 7;
const int SW_SHOWNA = 8;
const int SW_RESTORE = 9;
const int SW_SHOWDEFAULT = 10;
const int SW_FORCEMINIMIZE = 11;
const int SW_MAX = 11;
[DllImport("User32.Dll")]
static extern int ShowWindow(
IntPtr hWnd,
int nCmdShow
);
// HWND GetDesktopWindow(VOID);
[DllImport("User32.Dll")]
static extern IntPtr GetDesktopWindow();
// typedef struct _RECT
// {
// LONG left;
// LONG top;
// LONG right;
// LONG bottom;
// } RECT, *PRECT;
[StructLayout(LayoutKind.Sequential, Pack = 4)]
private struct RECT
{
public int left;
public int top;
public int right;
public int bottom;
}
// BOOL GetWindowRect(
// HWND hWnd, // ウィンドウのハンドル
// LPRECT lpRect // ウィンドウの座標値
// );
[DllImport("User32.Dll")]
static extern int GetWindowRect(
IntPtr hWnd, // ウィンドウのハンドル
out RECT rect // ウィンドウの座標値
);
[DllImport("user32.Dll")]
static extern int EnumWindows(EnumWindowCallBack x, IntPtr y);
public static bool ListViewCallBack(IntPtr hwnd, IntPtr lParam)
{
ListView lview = (ListView)FromHandle(lParam);
StringBuilder sbClassName = new StringBuilder(256);
StringBuilder sbWindowText = new StringBuilder(256);
string hasParent = "";
if (GetParent(hwnd) > 0)
hasParent = "Has Parent";
else
hasParent = "";
GetClassName(hwnd, sbClassName, sbClassName.Capacity);
GetWindowText(hwnd, sbWindowText, sbWindowText.Capacity);
if( sbClassName.Length > 0 && IsWindowVisible(hwnd) > 0)
{
ListViewItem item = lview.Items.Add(hwnd.ToString());
item.SubItems.Add(hasParent);
item.SubItems.Add(sbClassName.ToString());
item.SubItems.Add(sbWindowText.ToString());
}
return true;
}
private void button1_Click(object sender, System.EventArgs e)
{
RECT rect;
GetWindowRect(GetDesktopWindow(), out rect);
this.textBox1.Text =
rect.left.ToString() + ","
+ rect.top.ToString() + ","
+ rect.left.ToString() + ","
+ rect.bottom.ToString() ;
}
private void button2_Click(object sender, System.EventArgs e)
{
System.Diagnostics.Process.Start("Notepad.exe");
}
private void button3_Click(object sender, System.EventArgs e)
{
IntPtr h = FindWindow("Notepad", null);
MoveWindow(h, 10, 10, 300, 200, 1);
SetForegroundWindow(h);
}
private void button4_Click(object sender, System.EventArgs e)
{
EnumWindows(new EnumWindowCallBack(Form1.ListViewCallBack), this.listView1.Handle);
}
private void button5_Click(object sender, System.EventArgs e)
{
int index = this.listView1.SelectedIndices[0];
int h = Int32.Parse(this.listView1.Items[index].Text);
MoveWindow((IntPtr)h, 10, 10, 300, 200, 1);
ShowWindow((IntPtr)h, SW_RESTORE);
}
public static bool IECallBack(IntPtr hwnd, IntPtr lParam)
{
StringBuilder sbClassName = new StringBuilder(256);
GetClassName(hwnd, sbClassName, sbClassName.Capacity);
if( sbClassName.ToString().StartsWith("IEFrame"))
{
Form1.al.Add(hwnd);
}
return true;
}
static public ArrayList al = null;
private void button6_Click(object sender, System.EventArgs e)
{
al = new ArrayList();
// デスクトップウィンドウのサイズを求める。
RECT rect;
GetWindowRect(GetDesktopWindow(), out rect);
// EnumWindows でIECallBack へさせる。
EnumWindows(new EnumWindowCallBack(Form1.IECallBack), IntPtr.Zero);
// デスクトップウィンドウの縦サイズをIEの数で割る。
int hw = rect.bottom / al.Count;
// IE を整列させる。
for(int i = 0; i < al.Count; i++)
{
SetForegroundWindow((IntPtr)al[i]);
ShowWindow((IntPtr)al[i], SW_SHOWNORMAL);
MoveWindow((IntPtr)al[i], 0, i*hw, rect.right/3, hw, 1);
}
}
}
}
|
|
|