public static extern ushort RegisterClass([In] ref WNDCLASS lpWndClass);
Exemple #2
0
 /// <summary>
 /// Runs the standard message loop. The message loop quits when it receives the WM_QUIT message.
 /// </summary>
 public static void Run()
 {
     var wc = new WNDCLASS();
     IntPtr hInstance = Process.GetCurrentProcess().Handle;
     _currentDispatcher._hInstance = hInstance;
     wc.lpfnWndProc = WindowProc;
     wc.hInstance = hInstance;
     wc.lpszClassName = string.Format(DISPATCHER_CLASS_NAME_TEMPLATE, _currentDispatcher._threadId);
     _currentDispatcher._atom = NativeMethods.RegisterClass(ref wc);
     if (_currentDispatcher._atom == 0)
     {
         throw new Win32Exception("Failed to register window");
     }
     _currentDispatcher._messageDispatcherWindow = NativeMethods.CreateWindowEx(
       0,
     new IntPtr((int)_currentDispatcher._atom),// fixes "Cannot find window class." when uses string
       string.Format(DISPATCHER_NAME_TEMPLATE, _currentDispatcher._threadId),
      WindowStyles.WS_OVERLAPPEDWINDOW,
       CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT,
       IntPtr.Zero,
       IntPtr.Zero,
       hInstance,
       IntPtr.Zero);
     if (_currentDispatcher._messageDispatcherWindow == IntPtr.Zero)
     {
         int lastError = Marshal.GetLastWin32Error();
         throw new Win32Exception(lastError);
     }
     MSG msg;
     while (NativeMethods.GetMessage(out msg, IntPtr.Zero, 0, 0))
     {
         // if wm_quit received, object gets revoked from rot as using block exits.
         // Thread (even process) can also exit.
         NativeMethods.TranslateMessage(ref msg);
         NativeMethods.DispatchMessage(ref msg);
     }
 }