我希望创建一个应用程序来帮助我的gf仿真器(启动和管理游戏输入配置文件),因为她不擅长使用计算机。我想做的是启动仿真器,然后用鼠标移到正确的位置以配置仿真器,然后开始游戏,那部分很好,但是我找不到找到子窗体的手柄的方法。显示我何时配置仿真器。
首先,我从进程名称中获取模拟器在屏幕上的位置,然后从函数GetWindowRect中获取 其次,我将窗口移动到屏幕上的给定位置,然后从那里将每个仿真器输入设置都放置在不同的位置,因此我对鼠标移动进行硬编码以启动设置表单,但是从那里我找不到找到该位置的方法。主表单的句柄中的那个子表单。
[Emulator settings screenshot]:
//this part is in the window form .cs file
if(path != "Exe not found"){ //can be C:\location\Dolphin\dolphin.exe if the path is found
Process proc = Process.Start(path);
while(string.IsNullOrEmpty(proc.MainWindowTitle)){
Thread.Sleep(25);
proc.Refresh();
}
Activate();
MouseControl.control("dolphin", lstEmuGames.SelectedIndex);
}
//this code is in the mouse_movement.cs
public void control(string emuName, int lstIndex = 0){
MessageBox.Show("DO NOT MOVE THE MOUSE UNTIL THE GAME STARTS");
ControlForm.WindowState = FormWindowState.Minimized;
Thread.Sleep(500);
Process proc = getProcess(emuName);//ex dolphin.exe
if(proc != null){
Rect pos = getPos(proc.MainWindowHandle);
//gets the position of the emulator main form
if(pos.Left > -1){
moveTo(pos.Left + ((pos.Right - pos.Left) / 2), pos.Top + 10);
dragNDrop((pos.Right - pos.Left) / 2 + 25, 25);
/*this part gets the emulator<s main form to pixel 25,25 of the main screen then
from here i dont know what to do to get the child form (Dolphin controller config)
location to hard code the buttons and other controls exact location*/
}
}
private Process getProcess(string emuName){
Process[] processList = Process.GetProcesses();
foreach(Process process in processList)
if(process.MainWindowTitle.Contains(emuName)) return process;
return null;
}
private Rect getPos(IntPtr processHandle){
Rect pos = new Rect();
pos.Left = -1;
GetWindowRect(processHandle, ref pos);
return pos;
}
使用getPos函数返回子窗体的位置,以便我将鼠标相应地移动到窗口位置