I have a console app in .net that I'm doing some processing of fonts. I'm using Win32APIs for this and one of them requires a device context for loading a font - actually a IntPtr hdc = GetDC(handle of screen element)
. Obviously, my app doesn't have these handles as it's a console app. Is there a way to get around this?
views:
47answers:
3
+3
A:
In win32 GetDC( null ) should give a context back (for the entire screen)
So you should be able to do something like
IntPtr hdc = GetDC( null );
if( hdc == null )
{
OopsError();
}
BioBuckyBall
2010-08-03 23:15:26
+1
A:
GetConsoleWindow()
(http://msdn.microsoft.com/en-us/library/ms683175.aspx):
Retrieves the window handle used by the console associated with the calling process.
Alternatively, passing NULL might work. From the GetDC()
docs (http://msdn.microsoft.com/en-us/library/dd144871.aspx):
A handle to the window whose DC is to be retrieved. If this value is NULL, GetDC retrieves the DC for the entire screen.
Michael Burr
2010-08-03 23:19:05
+1
A:
IntPtr hdc = GetDC(System.Diagnostics.Process.GetCurrentProcess().MainWindowHandle);
works in .Net console apps just fine.
I don't believe null
will work in .Net as it kicks Error, Argument: cannot convert from '<null>'
to 'System.IntPtr'
Otaku
2010-08-05 03:58:41
thanks, works well.
WinnerWinnerChickenDinner
2010-08-05 21:01:20