When the window is opened, I save its handle to a TXT document. When I need to invoke the window, I retrieve the string from the document and open it.
Here is my code. When I run it, there are no errors, but there is no response either. Can someone help me identify where the problem might be?
var groups = readtogroup('C:\\Temp\\list.txt');
var mark = 0;
var currHandle = sp.ForegroundWindow().Process.Handle.ToString();
for (var i=0,lens = groups.Length; i < lens;i++){
if(currHandle == groups[i]){
if (i<groups.length-1){
switchToHandle(groups[i+1]);
mark = 1;
}else{
switchToHandle(groups[0]);
mark = 1;
}
break;
}
}
if(mark == 0){
switchToHandle(groups[0]);
}
// Switch to a window with a specified handle value.
function switchToHandle (handle){
var wnds = sp.AllApplications();
for (var i = 0, len = wnds.Length; i < len; i++) {
if (wnds[i].Process.Handle.ToString() == handle ){
wnds[i].Activate();
break;
}
}
}
//Read the contents of a specified document into an array, with each line stored as an element。
function readtogroup (path){
var sr = clr.System.IO.File.OpenText(path);
//stores current line
var line;
//stores current line number
var lineNumber = 0;
//tracks whether keyword is found or not
var content = new Array();
try{
//traverse the file
while ((line = sr.ReadLine()) != null ){
//increment line counter
lineNumber += 1;
//check for a keyword match in line
content.push(String(line));
}
}catch{
sp.MessageBox( "Error","biaoti");
}
//close file
sr.Close();
sr.Dispose();
//sp.MessageBox(content[2],"biaoti");
return content;
}
Edited by user Saturday, June 10, 2023 4:09:04 PM(UTC)
| Reason: Not specified