Answers for "get handle for console window C#"

C#
0

get handle for console window C#

using System;
using System.Runtime.InteropServices;

namespace MyConsoleApp
{
	static class Program
    {
      	[DllImport("user32.dll")]
      	private static extern IntPtr FindWindow(string lpClassName, string lpWindowName);
      	
    	static void Main(string[] args)
        {
          	// make sure to put this after any assignments to Console.Title
          	// so that the handle to the Console Window will be valid
        	IntPtr consolePtr = FindWindow(null, Console.Title);
        }
    }
}
Posted by: Guest on August-12-2021

C# Answers by Framework

Browse Popular Code Answers by Language