|
|
2020/4/24(Fri) 17:55:32|NO.90167
ウィンドウハンドルがHSP自ウィンドウかどうか判別する方法はありますか?
Win32APIを使った方法でもいいので、教えてほしいです。
|
|
2020/4/25(Sat) 01:14:40|NO.90169
オブジェクトには使えませんが、クラス名で判別出来ます。
#uselib "user32.dll"
#func global GetClassName "GetClassNameA" int, var, int
sdim classname, 260;
GetClassName hWnd, classname, 260;
if( classname == "hspwnd0" ) {
// クラス名がhspwnd0ならばHSP制のウィンドウ
mes "HSPウィンドウ";
}
else {
mes "その他のウィンドウ";
}
|
|
2020/4/25(Sat) 10:32:12|NO.90172
オブジェクトに対応させるにはこれでどうでしょう。
hwnd使えばいいだけだし意味ないかもだけど。
#uselib "user32.dll"
#func global GetClassName "GetClassNameA" int, var, int
#cfunc global GetParent "GetParent" int
sdim classname, 260;
button "test",*main
h=objinfo(stat,2)
*main
GetClassName h, classname, 260;
if( classname == "hspwnd0" ) {
// クラス名がhspwnd0ならばHSP制のウィンドウ
mes "HSPウィンドウ";
}
else {
h=GetParent(h)
if(h=0){
mes "その他のウィンドウ"
}else{
goto *main
}
}
|
|
2020/4/25(Sat) 10:51:40|NO.90173
すいません。SetParent使って子ウィンドウ作ったときに対応してませんでした。
#uselib "user32.dll"
#func global GetClassName "GetClassNameA" int, var, int
#cfunc global GetParent "GetParent" int
#func SetParent "SetParent" int, int
sdim classname, 260;
h = hwnd
screen 1, 300,200, 8, 10,10
SetParent hwnd, h
*main
GetClassName h, classname, 260;
if( classname == "hspwnd0" ) {
h=GetParent(h)
if(h!0):goto *main
// クラス名がhspwnd0ならばHSP制のウィンドウ
mes "HSPウィンドウ";
}
else {
h=GetParent(h)
if(h=0){
mes "その他のウィンドウ"
}else{
goto *main
}
}
|
|
2020/4/25(Sat) 12:18:31|NO.90175
BMSCR使うのもありですね
#module
// HSPウィンドウなら1、HSPオブジェクトなら2、関係なければ0を返す
#defcfunc is_hspwnd int searchfor
found = 0
repeat ginfo_newid
mref bmscr, 96 + cnt
hwin = bmscr(13)
if hwin != 0 {
if hwin == searchfor : found = 1 : break
pobjinfo = bmscr(71)
repeat bmscr(72)
dupptr hobj, pobjinfo + 8, 4, vartype("int")
if hobj == searchfor : found = 2 : break
pobjinfo += 48
loop
if found > 0 : break
}
loop
return found
#global
screen 0, 640, 480
h0 = hwnd
button "A", *a
o0 = objinfo_hwnd(stat)
button "B", *a
o1 = objinfo_hwnd(stat)
screen 1, 640, 480
h1 = hwnd
button "C", *a
o2 = objinfo_hwnd(stat)
gsel 0
mes "------"
mes is_hspwnd(h0)
mes is_hspwnd(h1)
mes is_hspwnd(o0)
mes is_hspwnd(o1)
mes is_hspwnd(o2)
mes is_hspwnd(h0 + 1)
mes is_hspwnd(h1 + 1)
mes is_hspwnd(o0 + 1)
mes is_hspwnd(o1 + 1)
mes is_hspwnd(o2 + 1)
*a
|
|
2020/4/25(Sat) 13:26:01|NO.90176
皆さん回答ありがとうございます。
その方法だと、他のHSPソフトで自ウィンドウではない場合、HSPウィンドウと出てしまうみたいなので、他の方法で判別する方法はないのでしょうか?
語彙力なくてすみません。
|
|
2020/4/25(Sat) 14:40:06|NO.90177
各ウィンドウのウィンドウハンドルを配列に入れおいて、そのどれかと一致するかをみる方法はどうでしょうか。
// 自プロセスのウィンドウの個数
window_count = ???
repeat window_count
gsel cnt
// cnt 番目のウィンドウのハンドル
window_handles(cnt) = hwnd
loop
// 何らかのウィンドウハンドル
the_hwnd = ???
ok = 0
repeat window_count
if the_hwnd == window_handles(cnt) {
ok = 1
break
}
loop
// ok == 1 なら自プロセスのウィンドウのハンドル
|
|
2020/4/25(Sat) 14:51:40|NO.90178
>その方法だと、他のHSPソフトで自ウィンドウではない場合、HSPウィンドウと出てしまうみたいなので
おっしゃる意味を理解できているかわかりませんが、
kanamaruさんの方法を使えば、他のソフトであっても、HSPのscreenやbgscr命令で作られたウィンドウ
の場合にのみ"HSPウィンドウ"と表示されませんか。
それとも、クラス名が衝突した場合ということでしょうか。
|
|
2020/4/25(Sat) 15:11:51|NO.90180
あらやさんのプログラムをもとにしたので僕の方法とは言えない気がします。
たぶん、ウィンドウの列挙をしてその中で自分のウィンドウを探そうとしているのだと思います。
その時、他にhsp製のプログラムを実行済みだったら
クラス名で判別できないということだと思います。
なので、mikumoさんかベインさんの方法を用いてください。
|
|
2020/4/25(Sat) 15:45:15|NO.90181
僕がやりたいのはこんな感じですね。
WindowFromPointでマウスカーソルが自ウィンドウ(他のHSP製プログラムは除外)に当たっているかどうか判別できるようにしたいです。
ベインさんの方法で判別できるのはわかりますが、ちょっと面倒みたいなので・・・。
Win32APIを使う方法でもいいのでお願いします。
#uselib "user32.dll"
#cfunc WindowFromPoint "WindowFromPoint" int,int
#uselib "kernel32.dll"
#func GetModuleFileName "GetModuleFileNameA" int,var,int
repeat 4,1
screen cnt,,,4
loop
repeat
wait 100
if ??(WindowFromPoint(ginfo_mx,ginfo_my))=1//自ウィンドウかどうか判別(他のHSP製プログラムは除外)
loop
|
|
2020/4/25(Sat) 16:49:32|NO.90183
普通に、ウィンドウが所属しているプロセスID が自身かそうでないかで良いんじゃないのかな。
GetWindowThreadProcessId(hwnd,"この値") で取得して、その値を GetCurrentProcessId で比較し一致すれば自身のウィンドウ。
|
|
2020/4/25(Sat) 17:17:47|NO.90185
GetWindowThreadProcessIdでスレッドIDかプロセスIDを確認すれば可能です。
頑張ってマルチスレッドとかやった場合のために
プロセスIDで確認するのが無難かと。
#uselib "user32.dll"
#func global GetClassName "GetClassNameA" int, var, int
#cfunc global GetWindowThreadProcessId "GetWindowThreadProcessId" int, var
#cfunc WindowFromPoint "WindowFromPoint" int,int
#uselib "kernel32.dll"
#func GetModuleFileName "GetModuleFileNameA" int,var,int
repeat 4,1
screen cnt,,,4
loop
// 自アプリのプロセスIDとスレッドIDを取得
OwnThreadId = GetWindowThreadProcessId( WindowFromPoint(ginfo_mx,ginfo_my), OwnProcessId );
repeat
wait 100
// マウス直下ウィンドウのプロセスIDとスレッドIDを取得
ThreadId = GetWindowThreadProcessId( WindowFromPoint(ginfo_mx,ginfo_my), ProcessId );
// 自アプリのプロセスIDとマウス直下ウィンドウのプロセスIDを比較
if( ProcessId == OwnProcessId ) {
mes "自アプリのウィンドウ";
}
else {
mes "他アプリのウィンドウ";
}
loop
|
|
2020/4/26(Sun) 17:49:05|NO.90202
自ウィンドウとは自分のアプリ(他HSP製プログラム以外)のウィンドウと呼んでいます。
わかりづらい説明でごめんなさい・・・!
皆さん、回答ありがとうございました!
//---------アプリケーションの起動チェックを行うモジュール----------
//モジュールを参考にしたサイト:http://chokuto.ifdef.jp/advanced/singleton1.html
#module
#uselib "kernel32.dll"
#func CloseHandle "CloseHandle" int
#cfunc CreateMutex "CreateMutexA" int, int, sptr
#cfunc GetLastError "GetLastError"
#define ERROR_ALREADY_EXISTS 183
#define MUTEX_NAME "HSP_WinAPI_Test_Mutex"
#defcfunc AlreadyAppRunning
if (hMutex == 0) {
hMutex = CreateMutex(0, 0, MUTEX_NAME)
if (GetLastError() == ERROR_ALREADY_EXISTS) {
alreadyRunning = 1
} else {
alreadyRunning = 0
}
}
return alreadyRunning
#deffunc CleanupAppRunChecker onexit
if (hMutex != 0) {
CloseHandle hMutex
hMutex = 0
}
return
#global
#uselib "user32.dll"
#func global GetClassName "GetClassNameA" int, var, int
#cfunc global GetWindowThreadProcessId "GetWindowThreadProcessId" int, var
#cfunc WindowFromPoint "WindowFromPoint" int,int
#uselib "kernel32.dll"
#func GetModuleFileName "GetModuleFileNameA" int,var,int
//アプリケーションの実行チェック
if AlreadyAppRunning()=0{
sdim exefile,256
GetModuleFileName ,exefile,256
exec exefile
}
repeat 2,1
screen cnt,400,240,4
loop
// 自アプリのプロセスIDとスレッドIDを取得
OwnThreadId=GetWindowThreadProcessId(hwnd,OwnProcessId);
repeat
wait 100
cls
// マウス直下ウィンドウのプロセスIDとスレッドIDを取得
ThreadId = GetWindowThreadProcessId( WindowFromPoint(ginfo_mx,ginfo_my), ProcessId );
// 自アプリのプロセスIDとマウス直下ウィンドウのプロセスIDを比較
if( ProcessId == OwnProcessId ) {
mes "自アプリのウィンドウ";
}
else {
mes "他アプリのウィンドウ";
}
loop

| |
|