掲示板システム
ホーム
アクセス解析
カテゴリ
ログアウト
アクティブウインドウのウインドウ名取得 (ID:147161)
名前
ホームページ(ブログ、Twitterなど)のURL (省略可)
本文
いろいろと間違っていますよ。 その Declare で As Long を使うべきでは無いですし、 文字列処理も 〜A 系ではない方が望ましいです。 > フォームのボタンはmousemoveを使用して MouseMove の最中に MsgBox を呼び出すのは、都合が悪くありませんか? > Declare Function GetActiveWindow GetActiveWindow は自スレッド内のアクティブウィンドウを得るものなので、 実質、ActiveForm の Handle プロパティを得るような意味になってしまいます。 別アプリのウィンドウを得たいのであれば、GetForegroundWindow API を 試してみてください。たとえばこんな感じです。 Public Class Form1 Private Declare Function GetForegroundWindow Lib "user32" () As IntPtr Private Declare Auto Function GetWindowText Lib "user32" _ (ByVal hWnd As IntPtr, _ ByVal lpString As System.Text.StringBuilder, _ ByVal cch As Integer) As Integer Private Sub Button1_MouseMove(ByVal sender As Object, ByVal e As MouseEventArgs) Handles Button1.MouseMove Dim title As New System.Text.StringBuilder(256) Dim hWnd As IntPtr = GetForegroundWindow() If Not (IntPtr.Zero.Equals(hWnd) OrElse Me.Handle.Equals(hWnd)) Then Dim ret As Integer = GetWindowText(hWnd, title, 256) DirectCast(sender, Control).Text = title.ToString(0, ret) End If End Sub Private Sub Button1_Click(ByVal sender As Object, ByVal e As EventArgs) Handles Button1.Click MsgBox(DirectCast(sender, Control).Text) End Sub End Class
←解決時は質問者本人がここをチェックしてください。
戻る
掲示板システム
Copyright 2021 Takeshi Okamoto All Rights Reserved.