HAMLOG開発室は、HAMLOGに関連したプログラム開発(C、パスカル、VB言語等、又はDLL)についての
専用BBSです。プログラム言語に関する投稿以外は通常のHAMLOG相談室に投稿して下さい。
HAMLOG開発室BBS

> ありがとうございます。
>
> まだ宿題が残っていまして...。
> JTDXのソースを修正して sendmaessage() でHamlogへ転送時の
> JTDXのウインドウ・ハンドルが取れていません。
> 言語はQtなのでサンプルも少なくて。
> C++のコードとは違いがあるのかも....。
WinApi を使って得ます
FindWindowEx() が使えると思います。ご存じの事と思いますが、JTDX WSJT-X共にClassNameが"Qt5QWindowIcon"と成っています(spay++で調べた結果)。FindWindowExは一連のOpen中のWinが順次得られますので、どのWinか判定するには captionと申しましょうか、Winに表示されている文字で判定するしかないと思います。
hWnd を得るためでなく動いている Verを調べるために作った例を提示します C# 対応です IntPtr hWnd が該当Winハンドルです


// WSJTX JTDX が起動されているかチェックしてそのCaptionを得る
private IntPtr hWndJtdx = (IntPtr)0;
public string GetWsjtxOrJtdxCaption()

{ string sCaptionVer1_8_0 = "WSJT-X v1.";
// 1 ソフトのキャプション Ver 1.8.0-rc2 3 では稼働確認 Ver 1.9.0-rc3

string sCaptionVer1_8_1 = "JTDX v18.1";
// 2 JTDX のMein確認
string sCaptionVerJTDX = "JTDX by HF community"; // 3 JTDX Ver 18.1.0.59
string sCaptionVer2_0 = "WSJT-X v2.0"; // 4 WSJT-X Ver 2.0.0
string sCaptionVer2_1 = "WSJT-X v2.1"; // 5 WSJT-X Ver 2.1.0以降
//
IntPtr hwndParent = (IntPtr)null;
IntPtr hwndChildAfter = (IntPtr)null ;
string className = "Qt5QWindowIcon";
string windowName = (string)null;
StringBuilder title = new StringBuilder(1048);
do

{ IntPtr hWnd = Win32Apis.NativeMethods.FindWindowEx(hwndParent, hwndChildAfter, className, windowName);
hWndJtdx = hWnd;
if (hWnd == (IntPtr)0) { JtVer = 0; return ""; }
string passnae = GetExeFileName(hWnd);

Win32Apis.NativeMethods.GetWindowText(hWnd, title, 1024);
int titlelen = title.ToString().Length;
string cp = "";
if (titlelen >= sCaptionVer1_8_0.Length)

{ cp = title.ToString().Substring(0, sCaptionVer1_8_0.Length);
if (sCaptionVer1_8_0.CompareTo(cp) == 0) { JtVer = 1; break; }
}
if (titlelen >= sCaptionVer1_8_1.Length)

{ cp = title.ToString().Substring(0, sCaptionVer1_8_1.Length);
if (sCaptionVer1_8_1.CompareTo(cp) == 0) { JtVer = 2; break; }
}
if (titlelen >= sCaptionVerJTDX.Length)

{ cp = title.ToString().Substring(0, sCaptionVerJTDX.Length);
if (sCaptionVerJTDX.CompareTo(cp) == 0) { JtVer = 3; break; }
}
// sCaptionVer2_0
if (titlelen >= sCaptionVer2_0.Length)

{ cp = title.ToString().Substring(0, sCaptionVer2_0.Length);
if (sCaptionVer2_0.CompareTo(cp) == 0) { JtVer = 4; break; }
}
// Ver2.1
if (titlelen >= sCaptionVer2_1.Length)

{ cp = title.ToString().Substring(0, sCaptionVer2_1.Length);
if (sCaptionVer2_1.CompareTo(cp) == 0) { JtVer = 5; break; }
}

hwndChildAfter = hWnd;
} while (true);
return title.ToString();
}

/////
public class Win32Apis


{ internal static class NativeMethods

{ // ---------------------------------------------------------------------------------
[DllImport("User32.dll", BestFitMapping = false, ThrowOnUnmappableChar = true )]
internal static extern IntPtr FindWindowEx
( IntPtr hwndParent,
IntPtr hwndChildAfter,
[MarshalAs(UnmanagedType.LPStr)] string className,
[MarshalAs(UnmanagedType.LPStr)] string windowName);

[DllImport("user32.dll", BestFitMapping = false, ThrowOnUnmappableChar = true)]
internal static extern int GetWindowText(IntPtr hWnd, StringBuilder text, int length);
    }
}

2020/04/04(Sat) 20:50:55  [No.896]


- 関連一覧ツリー (★ をクリックするとツリー全体を一括表示します)
- 返信フォーム (この記事に返信する場合は下記フォームから投稿して下さい)
Call 名前 ※必須
文字色
Eメール
タイトル sage
URL
メッセージ 手動改行 強制改行 図表モード
メッセージには上記と同じURLを書き込まないで下さい
画像File  (130kBまで)
暗証キー (英数字で8文字以内)
投稿キー (投稿時 投稿キー を入力してください)
プレビュー