C#初心者です。以下のC#のコードでfirefoxのウインドウを移動しようとしましたが、できませんでした。"MozillaWindowClass"を変更すればメモ帳を移動できることは確認しました。UWSCならfirefoxのウインドウを移動できることも確認しています。C#でfirefoxのウインドウを移動する方法を教えてください。
using System;
using System.Windows.Forms;
using System.Runtime.InteropServices;
namespace WindowsFormsApplication2
{
public partial class Form1 : Form
{
[DllImport("User32.dll", EntryPoint = "FindWindow")]
public static extern IntPtr FindWindow(String lpClassName, String lpWindowName);
public Form1()
{
InitializeComponent();
}
[System.Runtime.InteropServices.DllImport("user32.dll")]
private static extern int MoveWindow(IntPtr hwnd, int x, int y,
int nWidth, int nHeight, int bRepaint);
private void Form1_Load(object sender, EventArgs e)
{
IntPtr hwnd1 = FindWindow("MozillaWindowClass", null);
MoveWindow(hwnd1, 0, 0, 500, 700, 1);
}
}
}
No.1ベストアンサー
- 回答日時:
FindWindowで引数lpWindowNameをNULLとして与えると lpClassNameに該当するすべてのウィンドウの中で初めて見つかったものを返します
FireFox自体が 何かしらのダミーを作っているようで 実際操作したいもの以外のハンドルを取得しているのが原因のようですよ
対策として lpWindowNameを指定してやるか EnumWindowsで列挙しながら GetClassNameでFireFoxか特定し
その上で GetWindowTextなどで 対象かどうか確かめてはいかがでしょう
ありがとうございます。
教えていただいた方法を試してみようと思いましたが、EnumWindowsをよく理解できず、
調査中です。
お探しのQ&Aが見つからない時は、教えて!gooで質問しましょう!
関連するカテゴリからQ&Aを探す
おすすめ情報
- ・漫画をレンタルでお得に読める!
- ・人生のプチ美学を教えてください!!
- ・10秒目をつむったら…
- ・あなたの習慣について教えてください!!
- ・牛、豚、鶏、どれか一つ食べられなくなるとしたら?
- ・【大喜利】【投稿~9/18】 おとぎ話『桃太郎』の知られざるエピソード
- ・街中で見かけて「グッときた人」の思い出
- ・「一気に最後まで読んだ」本、教えて下さい!
- ・幼稚園時代「何組」でしたか?
- ・激凹みから立ち直る方法
- ・1つだけ過去を変えられるとしたら?
- ・【あるあるbot連動企画】あるあるbotに投稿したけど採用されなかったあるある募集
- ・【あるあるbot連動企画】フォロワー20万人のアカウントであなたのあるあるを披露してみませんか?
- ・映画のエンドロール観る派?観ない派?
- ・海外旅行から帰ってきたら、まず何を食べる?
- ・誕生日にもらった意外なもの
- ・天使と悪魔選手権
- ・ちょっと先の未来クイズ第2問
- ・【大喜利】【投稿~9/7】 ロボットの住む世界で流行ってる罰ゲームとは?
- ・推しミネラルウォーターはありますか?
- ・都道府県穴埋めゲーム
- ・この人頭いいなと思ったエピソード
- ・準・究極の選択
デイリーランキングこのカテゴリの人気デイリーQ&Aランキング
-
DataSet(DataTable)の使い方
-
c# デリゲート関連の命名について
-
行の途中から読み込む方法
-
メインが含まれていません
-
JAVA エラー 式の開始が不正で...
-
Javaのファイル名チェックについて
-
三目並べ(Tick-Tack-Toe)をJav...
-
成績表示プログラム
-
javaでcsvファイル読込時の改行...
-
intが負の時に投げる例外はあり...
-
同じ数字のある並べ方のすべて...
-
アクセス用クラスを利用した登...
-
6桁の数字を重複なしでランダム...
-
ビープ音をなめらかに鳴らしたい
-
二次元配列の初期化の方法。
-
[JAVA]互換性のない型です・・...
-
JavaScriptからJavaアプレット...
-
初心者ですが、今javaで簡単な...
-
classを使って座標軸を求めるコ...
-
javaのパッケージについての質...
マンスリーランキングこのカテゴリの人気マンスリーQ&Aランキング
-
「配列定数は、イニシャライザ...
-
java spring でエラーが出て困...
-
Java 初心者 int型の取り扱い方
-
式の型は配列型で int に解決済...
-
DataSet(DataTable)の使い方
-
C#で、デリゲートからその関数...
-
6桁の数字を重複なしでランダム...
-
C#で実行時にメソッドの返り値...
-
JUnit4のアノテーションについて
-
行の途中から読み込む方法
-
Javaで電卓を作りたい
-
SwingでJtableのヘッダ行が表示...
-
javaでcsvファイル読込時の改行...
-
javaでカレンダー作成
-
ビープ音をなめらかに鳴らしたい
-
c# デリゲート関連の命名について
-
intが負の時に投げる例外はあり...
-
java 長さの異なる配列の代入
-
デスクトップのアイコンの位置...
-
【C#】フォームをなめらかに移動
おすすめ情報