Писал значит как новичок код с YouTube'а. И после точной переписи появилась с ошибкой запуска окна класса.
Вот собственно где ошибка:
using srcpp____Engine_.VTFEdit;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace srcpp____Engine_
{
public partial class mainForm : Form
{
private Window window;
public mainForm()
{
InitializeComponent();
}
private void mainForm_Load(object sender, EventArgs e)
{
window = new Window();
window.Open(windowParent.Handle, (success) =>
{
if (!success)
{
MessageBox.Show("Error");
}
});
}
}
}
ошибка с windowParent, когда у человека все верно и без ошибок.
Код ошибки CS0103.
Если вам нужно больше для решения проблемы, то вот само видео:
https://www.youtube.com/watch?v=RaWtwHsDD6k&ab_cha... , с таймкодом 22:07
Скрипт который писал раннее с этого видео:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.IO;
using System.Diagnostics;
namespace srcpp____Engine_.VTFEdit
{
public class Window
{
private const string VTFEDIT_WINDOW_CLASSNAME = "VTFEditWndClass";
private const int VTFEDIT_WINDOW_FIND_TIMEOUT = 5;
private Process process;
private string FileName
{
get
{
return @"C:\Users\Nerediska\Desktop\srcpp\tools\VTFEdit\VTFEdit.exe";
}
}
private IntPtr Handle = new IntPtr(0);
DateTime start = DateTime.Now;
private bool StartProcess(IntPtr owner)
{
if (File.Exists(FileName))
{
ProcessStartInfo info = new ProcessStartInfo(FileName, "-parentHWD" + owner.ToInt32().ToString());
process = Process.Start(info);
return true;
}
return false;
}
private bool WaitWindow(IntPtr owner)
{
IntPtr vtfeditWindow = new IntPtr(0);
try
{
List<IntPtr> childWindows = WinApi.GetAllChildHandles(owner);
while (vtfeditWindow.ToInt32() == 0)
{
childWindows = WinApi.GetAllChildHandles(owner);
vtfeditWindow = childWindows.FirstOrDefault(w => WinApi.GetWindowClass(w) == VTFEDIT_WINDOW_CLASSNAME);
if ((DateTime.Now - start).TotalSeconds >= VTFEDIT_WINDOW_FIND_TIMEOUT)
{
break;
}
}
}
catch
{
}
bool success = vtfeditWindow.ToInt32() != 0;
if (success)
{
Handle = vtfeditWindow;
}
return success;
}
public async void Open(IntPtr owner, Action<bool> embeddingCallback)
{
if (StartProcess(owner))
{
await Task.Run(() => embeddingCallback(WaitWindow(owner)));
}
else
{
embeddingCallback(false);
}
}
}
Класс WinApi
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading.Tasks;
namespace srcpp____Engine_
{
public static class WinApi
{
private delegate bool EnumWindowProc(IntPtr hwnd, IntPtr lParam);
[DllImport("user32.dll")]
private static extern int SendMessage(IntPtr hWnd, int wMsg, IntPtr wParam, IntPtr lParam);
[DllImport("user32.dll", EntryPoint = "SetWindowsPos")]
private static extern bool SetWindowPos(IntPtr hWnd, int hWndInsertAfter, int x, int Y, int cx, int cy, int wFlags);
[DllImport("user32.dll")]
[return: MarshalAs(UnmanagedType.Bool)]
private static extern bool EnumChildWindows(IntPtr window, EnumWindowProc callback, IntPtr lParam);
[DllImport("user32.dll", SetLastError = true)]
private static extern int GetClassName(IntPtr hWnd, StringBuilder lpString, int nMaxCount);
private static List<IntPtr> childWindows;
private static bool EnumWindow(IntPtr hWnd, IntPtr lParam)
{
childWindows.Add(hWnd);
EnumChildWindows(hWnd, EnumWindow, IntPtr.Zero);
return true;
}
public static void SetSize(IntPtr hWnd, int hWndInsertAfter, int cx, int cy, int wFlags)
{
SetWindowPos(hWnd, hWndInsertAfter, 0, 0, cx, cy, wFlags);
}
public static string GetWindowClass(IntPtr hWnd)
{
int length = 256;
StringBuilder stringBuilder = new StringBuilder(length);
length = GetClassName(hWnd, stringBuilder, length);
return stringBuilder.ToString(0, length);
}
public static List<IntPtr> GetAllChildHandles(IntPtr handle)
{
childWindows = new List<IntPtr>();
EnumChildWindows(handle, EnumWindow, IntPtr.Zero);
return childWindows;
}
}
}
P.S: Я заменил все что в видео на своё.