예제 #1
1
        protected override HandleRef BuildWindowCore(HandleRef hwndParent)
        {
            if (m_classAtom == 0)
            {
                WNDCLASS wind_class = new WNDCLASS
                {
                    lpszClassName = ClassName,
                    lpfnWndProc = WndProcPtr,
                };

                m_classAtom = Import.RegisterClassW(ref wind_class);
            }

            // create window
            Hwnd = Import.CreateWindowExW(
                0, // ex flag
                ClassName,
                "EmptyHwndTitle",
                WS.WS_CHILD,
                Import.CW_USEDEFAULT,
                Import.CW_USEDEFAULT,
                Import.CW_USEDEFAULT,
                Import.CW_USEDEFAULT,
                hwndParent.Handle,
                IntPtr.Zero,
                IntPtr.Zero,
                IntPtr.Zero
            );

            LostMouseCapture += EmptyHwnd_LostMouseCapture;

            return new HandleRef(this, Hwnd);
        }
예제 #2
0
 public static extern int RegisterClass(ref WNDCLASS Class);
예제 #3
0
 public static extern int GetClassInfo(HANDLE hInstance, string lpClassName, out WNDCLASS lpWndClass);
예제 #4
0
파일: Win32.cs 프로젝트: wj-wong/csharp
 public static extern System.UInt16 RegisterClassW([In] ref WNDCLASS lpWndClass);
예제 #5
0
파일: Program.cs 프로젝트: wj-wong/csharp
        static void Main()
        {
            //var f = new Form();
            //var btn = new Button();
            //btn.Parent = f;
            //btn.Text = "OK";
            //btn.Left = btn.Top = 20;

            //btn.Click += (o, e) =>
            //{
            //    System.Windows.Forms.MessageBox.Show("234234");
            //};

            //Application.Run(f);

            WndProc  wndProc = WndProc2;
            WNDCLASS wnd     = new WNDCLASS();

            wnd.hIcon = LoadIcon(IntPtr.Zero,
                                 (int)SystemIcons.IDI_ASTERISK);
            wnd.hCursor = LoadCursor(IntPtr.Zero,
                                     (int)StandardCursors.IDC_NO);

            wnd.style = (uint)ClassStyles.HorizontalRedraw
                        | (uint)ClassStyles.VerticalRedraw;
            wnd.lpfnWndProc   = Marshal.GetFunctionPointerForDelegate(wndProc);
            wnd.lpszClassName = "C#_Win32";
            wnd.hbrBackground = GetStockObject(StockObjects.WHITE_BRUSH);

            var res = RegisterClassW(ref wnd);

            if (res == 0)
            {
                return;
            }

            IntPtr hwnd = CreateWindowEx(
                WindowStylesEx.WS_EX_APPWINDOW,
                "C#_Win32", "Form",
                WindowStyles.WS_OVERLAPPEDWINDOW,
                100, 100, 600, 400,
                IntPtr.Zero, IntPtr.Zero,
                IntPtr.Zero, IntPtr.Zero
                );

            IntPtr btn = CreateWindowEx(
                0,
                "BUTTON", "OK",
                WindowStyles.WS_CHILD |
                WindowStyles.WS_VISIBLE,
                40, 40, 80, 23,
                hwnd, new IntPtr(1001),
                IntPtr.Zero, IntPtr.Zero
                );

            btn = CreateWindowEx(
                0,
                "BUTTON", "Cancel",
                WindowStyles.WS_CHILD |
                WindowStyles.WS_VISIBLE,
                160, 40, 80, 23,
                hwnd, new IntPtr(1002),
                IntPtr.Zero, IntPtr.Zero
                );

            if (hwnd == IntPtr.Zero)
            {
                int err = Marshal.GetLastWin32Error();
            }

            ShowWindow(hwnd, ShowWindowCommands.Normal);

            MSG msg;

            while (GetMessage(out msg, IntPtr.Zero, 0, 0) != 0)
            {
                DispatchMessage(ref msg);
            }
        }
예제 #6
0
파일: Program.cs 프로젝트: cleverxy/csharp
        static void Main(string[] args)
        {
            IntPtr hInstance = System.Diagnostics.Process.GetCurrentProcess().Handle;
            WNDCLASS wndclass = new WNDCLASS();
            string szAppName = "HelloWin";
            wndclass.style = (uint)ClassStyles.HorizontalRedraw | (uint)ClassStyles.VerticalRedraw;
            WndProc wndproc = WndProc2;
            wndclass.lpfnWndProc = Marshal.GetFunctionPointerForDelegate(wndproc);

            //wndclass.cbClsExtra = 0;
            //wndclass.cbWndExtra = 0;
            wndclass.hInstance = hInstance;
            wndclass.hIcon = LoadIcon(
            IntPtr.Zero, new IntPtr((int)SystemIcons.IDI_EXCLAMATION));
            wndclass.hCursor = LoadCursor(
            IntPtr.Zero, (int)StandardCursors.IDC_CROSS);
            wndclass.hbrBackground = GetStockObject(StockObjects.WHITE_BRUSH);
            //wndclass.lpszMenuName = null;
            wndclass.lpszClassName = szAppName;

            //WindowStylesEx.WS_EX_OVERLAPPEDWINDOW
            ushort regResult = RegisterClassW(ref wndclass);
            if (regResult == 0)
            {
                MessageBox(IntPtr.Zero, "This program requires Windows NT!",
                        szAppName, (int)MessageBoxOptions.IconError);
                return;
            }

            IntPtr hwnd = CreateWindowEx(
                WindowStylesEx.WS_EX_APPWINDOW,
                szAppName,
                "Win32 from C#",
                //(uint)Native.WindowStyles.WS_CHILD |
                WindowStyles.WS_OVERLAPPEDWINDOW |
                WindowStyles.WS_VISIBLE,
                100,100,500,200,
                IntPtr.Zero,IntPtr.Zero,IntPtr.Zero,IntPtr.Zero
            );

            IntPtr btn = CreateWindowEx(
                0,
                "BUTTON",
                "OK",
                WindowStyles.WS_CHILD |
                WindowStyles.WS_VISIBLE,
                10, 10, 50, 20,
                hwnd, IntPtr.Zero, IntPtr.Zero, IntPtr.Zero
            );

            if (hwnd == IntPtr.Zero)
            {
                int lastError = Marshal.GetLastWin32Error();
                string errorMessage = new Win32Exception(lastError).Message;
            }

            ShowWindow(hwnd, ShowWindowCommands.Normal);
            UpdateWindow(hwnd);
            MSG msg;

            while (GetMessage(out msg, IntPtr.Zero, 0, 0) != 0)
            {
                TranslateMessage(ref msg);
                DispatchMessage(ref msg);
            }

            return;
        }
예제 #7
0
        static void Main(string[] args)
        {
            IntPtr   hInstance = System.Diagnostics.Process.GetCurrentProcess().Handle;
            WNDCLASS wndclass  = new WNDCLASS();
            string   szAppName = "HelloWin";

            wndclass.style = (uint)ClassStyles.HorizontalRedraw | (uint)ClassStyles.VerticalRedraw;
            WndProc wndproc = WndProc2;

            wndclass.lpfnWndProc = Marshal.GetFunctionPointerForDelegate(wndproc);

            //wndclass.cbClsExtra = 0;
            //wndclass.cbWndExtra = 0;
            wndclass.hInstance = hInstance;
            wndclass.hIcon     = LoadIcon(
                IntPtr.Zero, new IntPtr((int)SystemIcons.IDI_EXCLAMATION));
            wndclass.hCursor = LoadCursor(
                IntPtr.Zero, (int)StandardCursors.IDC_CROSS);
            wndclass.hbrBackground = GetStockObject(StockObjects.WHITE_BRUSH);
            //wndclass.lpszMenuName = null;
            wndclass.lpszClassName = szAppName;

            //WindowStylesEx.WS_EX_OVERLAPPEDWINDOW
            ushort regResult = RegisterClassW(ref wndclass);

            if (regResult == 0)
            {
                MessageBox(IntPtr.Zero, "This program requires Windows NT!",
                           szAppName, (int)MessageBoxOptions.IconError);
                return;
            }

            IntPtr hwnd = CreateWindowEx(
                WindowStylesEx.WS_EX_APPWINDOW,
                szAppName,
                "Win32 from C#",
                //(uint)Native.WindowStyles.WS_CHILD |
                WindowStyles.WS_OVERLAPPEDWINDOW |
                WindowStyles.WS_VISIBLE,
                100, 100, 500, 200,
                IntPtr.Zero, IntPtr.Zero, IntPtr.Zero, IntPtr.Zero
                );

            IntPtr btn = CreateWindowEx(
                0,
                "BUTTON",
                "OK",
                WindowStyles.WS_CHILD |
                WindowStyles.WS_VISIBLE,
                10, 10, 50, 20,
                hwnd, IntPtr.Zero, IntPtr.Zero, IntPtr.Zero
                );

            if (hwnd == IntPtr.Zero)
            {
                int    lastError    = Marshal.GetLastWin32Error();
                string errorMessage = new Win32Exception(lastError).Message;
            }

            ShowWindow(hwnd, ShowWindowCommands.Normal);
            UpdateWindow(hwnd);
            MSG msg;

            while (GetMessage(out msg, IntPtr.Zero, 0, 0) != 0)
            {
                TranslateMessage(ref msg);
                DispatchMessage(ref msg);
            }

            return;
        }
예제 #8
0
파일: Program.cs 프로젝트: cleverxy/csharp
        static void Main()
        {
            //var f = new Form();
            //var btn = new Button();
            //btn.Parent = f;
            //btn.Text = "OK";
            //btn.Left = btn.Top = 20;

            //btn.Click += (o, e) =>
            //{
            //    System.Windows.Forms.MessageBox.Show("234234");
            //};

            //Application.Run(f);

            WndProc wndProc = WndProc2; 
            WNDCLASS wnd = new WNDCLASS();
            
            wnd.hIcon = LoadIcon(IntPtr.Zero, 
                (int)SystemIcons.IDI_ASTERISK);
            wnd.hCursor = LoadCursor(IntPtr.Zero,
                (int)StandardCursors.IDC_NO);

            wnd.style = (uint)ClassStyles.HorizontalRedraw
                | (uint)ClassStyles.VerticalRedraw;
            wnd.lpfnWndProc = Marshal.GetFunctionPointerForDelegate(wndProc);
            wnd.lpszClassName = "C#_Win32";
            wnd.hbrBackground = GetStockObject(StockObjects.WHITE_BRUSH);

            var res = RegisterClassW(ref wnd);

            if (res == 0)
                return;

            IntPtr hwnd = CreateWindowEx(
                WindowStylesEx.WS_EX_APPWINDOW,
                "C#_Win32", "Form",
                WindowStyles.WS_OVERLAPPEDWINDOW,
                100, 100, 600, 400,
                IntPtr.Zero, IntPtr.Zero, 
                IntPtr.Zero, IntPtr.Zero
            );

            IntPtr btn = CreateWindowEx(
                0,
                "BUTTON", "OK",
                WindowStyles.WS_CHILD |
                    WindowStyles.WS_VISIBLE,
                40, 40, 80, 23,
                hwnd, new IntPtr(1001),
                IntPtr.Zero, IntPtr.Zero
            );

            btn = CreateWindowEx(
                0,
                "BUTTON", "Cancel",
                WindowStyles.WS_CHILD |
                    WindowStyles.WS_VISIBLE,
                160, 40, 80, 23,
                hwnd, new IntPtr(1002),
                IntPtr.Zero, IntPtr.Zero
            );

            if (hwnd == IntPtr.Zero)
            {
                int err = Marshal.GetLastWin32Error();
            }

            ShowWindow(hwnd, ShowWindowCommands.Normal);

            MSG msg;

            while(GetMessage(out msg, IntPtr.Zero, 0, 0) != 0)
            {
                DispatchMessage(ref msg);
            }
        }