本文整理汇总了C#中NativeMethods.MakeHandleRef方法的典型用法代码示例。如果您正苦于以下问题:C# NativeMethods.MakeHandleRef方法的具体用法?C# NativeMethods.MakeHandleRef怎么用?C# NativeMethods.MakeHandleRef使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类NativeMethods
的用法示例。
在下文中一共展示了NativeMethods.MakeHandleRef方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CreateWindow
private IntPtr CreateWindow(NativeMethods.BitmapHandle hBitmap, int width, int height, bool topMost)
{
if (_defWndProc == null)
{
_defWndProc = new MS.Win32.NativeMethods.WndProc(UnsafeNativeMethods.DefWindowProc);
}
MS.Win32.NativeMethods.WNDCLASSEX_D wndClass = new MS.Win32.NativeMethods.WNDCLASSEX_D();
wndClass.cbSize = Marshal.SizeOf(typeof(MS.Win32.NativeMethods.WNDCLASSEX_D));
wndClass.style = 3; /* CS_HREDRAW | CS_VREDRAW */
wndClass.lpfnWndProc = null;
wndClass.hInstance = _hInstance;
wndClass.hCursor = IntPtr.Zero;
wndClass.lpszClassName = CLASSNAME;
wndClass.lpszMenuName = string.Empty;
wndClass.lpfnWndProc = _defWndProc;
// We chose to ignore re-registration errors in RegisterClassEx on the off chance that the user
// wants to open multiple splash screens.
_wndClass = MS.Win32.UnsafeNativeMethods.IntRegisterClassEx(wndClass);
if (_wndClass == 0)
{
if (Marshal.GetLastWin32Error() != 0x582) /* class already registered */
throw new Win32Exception();
}
int screenWidth = MS.Win32.UnsafeNativeMethods.GetSystemMetrics(SM.CXSCREEN);
int screenHeight = MS.Win32.UnsafeNativeMethods.GetSystemMetrics(SM.CYSCREEN);
int x = (screenWidth - width) / 2;
int y = (screenHeight - height) / 2;
HandleRef nullHandle = new HandleRef(null, IntPtr.Zero);
int windowCreateFlags =
(int) NativeMethods.WS_EX_WINDOWEDGE |
NativeMethods.WS_EX_TOOLWINDOW |
NativeMethods.WS_EX_LAYERED |
(topMost ? NativeMethods.WS_EX_TOPMOST : 0);
// CreateWindowEx will either succeed or throw
IntPtr hWnd = MS.Win32.UnsafeNativeMethods.CreateWindowEx(
windowCreateFlags,
CLASSNAME, SR.Get(SRID.SplashScreenIsLoading),
MS.Win32.NativeMethods.WS_POPUP | MS.Win32.NativeMethods.WS_VISIBLE,
x, y, width, height,
nullHandle, nullHandle, new HandleRef(null, _hInstance), IntPtr.Zero);
// Display the image on the window
IntPtr hScreenDC = UnsafeNativeMethods.GetDC(new HandleRef());
IntPtr memDC = UnsafeNativeMethods.CreateCompatibleDC(new HandleRef(null, hScreenDC));
IntPtr hOldBitmap = UnsafeNativeMethods.SelectObject(new HandleRef(null, memDC), hBitmap.MakeHandleRef(null).Handle);
NativeMethods.POINT newSize = new NativeMethods.POINT(width, height);
NativeMethods.POINT newLocation = new NativeMethods.POINT(x, y);
NativeMethods.POINT sourceLocation = new NativeMethods.POINT(0, 0);
_blendFunc = new NativeMethods.BLENDFUNCTION();
_blendFunc.BlendOp = NativeMethods.AC_SRC_OVER;
_blendFunc.BlendFlags = 0;
_blendFunc.SourceConstantAlpha = 255;
_blendFunc.AlphaFormat = 1; /*AC_SRC_ALPHA*/
bool result = UnsafeNativeMethods.UpdateLayeredWindow(hWnd, hScreenDC, newLocation, newSize,
memDC, sourceLocation, 0, ref _blendFunc, NativeMethods.ULW_ALPHA);
UnsafeNativeMethods.SelectObject(new HandleRef(null, memDC), hOldBitmap);
UnsafeNativeMethods.ReleaseDC(new HandleRef(), new HandleRef(null, memDC));
UnsafeNativeMethods.ReleaseDC(new HandleRef(), new HandleRef(null, hScreenDC));
if (result == false)
{
UnsafeNativeMethods.HRESULT.Check(Marshal.GetHRForLastWin32Error());
}
return hWnd;
}