Handle in console application

I have a console application in .net that I am making to handle fonts. I use Win32API for this, and one of them requires a device context to download the font - actually IntPtr hdc = GetDC(handle of screen element). Obviously, my application does not have such handles as a console application. Is there any way around this?

+3
source share
3 answers

IntPtr hdc = GetDC(System.Diagnostics.Process.GetCurrentProcess().MainWindowHandle); works in .Net console applications just fine.

I do not believe that it nullwill work in .Net, since it launches Error, Argument: it is impossible to convert from '<null>'to'System.IntPtr'

+1
source

In win32, GetDC (null) should give the context back (for the whole screen)

MSDN

, -

IntPtr hdc = GetDC( null );
if( hdc == null ) 
{
    OopsError();
}
+3

GetConsoleWindow() (http://msdn.microsoft.com/en-us/library/ms683175.aspx):

Gets the window handle used by the console associated with the calling process.

Alternatively, NULL transmission may work. From GetDC()docs ( http://msdn.microsoft.com/en-us/library/dd144871.aspx ):

The handle to the window whose DC should be restored. If this value is NULL, GetDC receives DC for the entire screen.

+1
source

Source: https://habr.com/ru/post/1757914/


All Articles