|
お世話になります。 ソフトを1度起動すると、1つも画面が出てきますが、再度、起動すると、同じ画面がまた出ます、そこでこの二つを区別したいのですが、なにかしらの方法はございますでしょうか、getidでは、当然、同じものしか取得できません。 getid("無題 - メモ帳", "Notepad")
|
No.1159 2021/02/09(Tue) 12:06:09
|
☆ Re: 同じアプリを区別 / Rayna |
|
|
|
>>1159 sousou さん
・Execで起動時のIdを取る 一番確実でローコスト, 安定性もある 一部取れないウインドウとかは idWnd = Status(Exec("app.exe"), ST_PARENT) とかで取れる場合がある
・GetId, Exec を使わない場合 GetAllWinを使うことになりますが実行コスト高めです
・GetAllWinで差分を獲得する Dim saIds, saNewIds, idWnd SendStr(Exec("notepad.exe"), "1つめ") saIds = GetNewWin() // すべてのウインドウ SendStr(Exec("notepad.exe"), "2つめ") saNewIds = GetNewWin(saIds) // すべてのウインドウ - saIds
idWnd = GetIdByIdList(saIds, EMPTY, "Notepad", 1) // 1つめ SendStr(idWnd, "<#CR>1つめに追記") idWnd = GetIdByIdList(saNewIds, EMPTY, "Notepad", 1) // 2つめ SendStr(idWnd, "<#CR>2つめに追記")
・GetAllWinのフィルター関数を作る // ウインドウクラスが "Notepad" And プライマリモニタに表示されてるウインドウ For idWnd In GetIdsByEval("Status(<ID>, ST_CLASS)=<#DBL>Notepad<#DBL> And Status(<ID>, ST_MONITOR)=0") Print GetStr(idWnd, 1) Next
// 関数サンプル // GetAllWinで差分を獲得する Function GetNewWin(saOldWins=) GetAllWin() Select VarType(saOldWins) Case VAR_ARRAY Or VAR_VARIANT Dim aNewIds[Length(saOldWins)+Length(ALL_WIN_ID)] Dim sOldWins = " "+Join(saOldWins, " ")+" " Dim i, j=0 For i = 0 To Length(ALL_WIN_ID)-1 If Pos(" "+ALL_WIN_ID[i]+" ", sOldWins)<>0 Then Continue aNewIds[j] = ALL_WIN_ID[i] j = j + 1 Next RESULT = Slice(aNewIds, 0, j-1) Default RESULT = Slice(ALL_WIN_ID) SelEnd FEnd Function GetIdByIdList(saIds, sTitle=, sClass=, nOffset=0) RESULT = -1 nOffset = Int(nOffset) If VarType(saIds)<>(VAR_ARRAY Or VAR_VARIANT) Then Exit If Length(sTitle+sClass)=0 Then Exit If nOffset=0 Then nOffset=1 Dim idWnd For idWnd In saIds IfB VarType(sTitle)<>VAR_EMPTY Then If Pos(sTitle, Status(idWnd, ST_TITLE))=0 Then Continue EndIf IfB VarType(sClass)<>VAR_EMPTY Then If Pos(sClass, Status(idWnd, ST_CLASS))<>1 Then Continue EndIf RESULT = idWnd nOffset = nOffset - 1 If nOffset=0 Then Exit Next FEnd
// GetAllWinのフィルター関数を作る Function GetIdsByEval(sEval="") GetAllWin() Dim idWnd, i=-1, aIds[i] sEval = Replace(sEval, "<ID>", "idWnd") IfB Length(sEval)=0 Then RESULT = Slice(ALL_WIN_ID) Exit EndIf For idWnd In ALL_WIN_ID Try If Eval(sEval) Then i = i + 1 Resize(aIds, i) aIds[i] = idWnd EndIf Except EndTry Next RESULT = Slice(aIds, 0, i) FEnd
|
No.1160 2021/02/09(Tue) 15:42:16
|
|