NativeWindowTest.cs 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. using System;
  2. using System.Runtime.InteropServices;
  3. using System.Windows.Forms;
  4. public class NativeWindowTest : NativeWindow {
  5. protected override void WndProc (ref Message m)
  6. {
  7. Console.WriteLine ("in NativeWindowTest WndProc");
  8. m.Result = (IntPtr) 0;
  9. if (m.Msg == Win32.WM_DESTROY) {
  10. Console.WriteLine ("posting quit message");
  11. Win32.PostQuitMessage (0);
  12. } else
  13. DefWndProc (ref m);
  14. }
  15. static public void Main () {
  16. Console.WriteLine ("NativeWindow sample application begin");
  17. Console.WriteLine ("Creating NativeWindow");
  18. NativeWindowTest nw = new NativeWindowTest ();
  19. Console.WriteLine ("Creating CreateParams");
  20. CreateParams cp = new CreateParams ();
  21. Console.WriteLine ("setting up CreateParams");
  22. cp.Caption = "Mono Native Window Test";
  23. cp.ClassName = "mono_native_window";
  24. cp.X = 10;
  25. cp.Y = 10;
  26. cp.Width = 640;
  27. cp.Height = 480;
  28. cp.ClassStyle = 0;
  29. cp.ExStyle = 0;
  30. cp.Param = 0;
  31. cp.Param = 0;
  32. cp.Style = (int) (
  33. Win32.WS_OVERLAPPEDWINDOW | Win32.WS_HSCROLL|
  34. Win32.WS_VSCROLL);
  35. Console.WriteLine ("creating handle");
  36. nw.CreateHandle (cp);
  37. Console.WriteLine ("showing window");
  38. Win32.ShowWindow (nw.Handle, (int) Win32.SW_SHOW);
  39. Win32.MSG msg = new Win32.MSG();
  40. while (Win32.GetMessageA (ref msg, 0, 0, 0) != 0) {
  41. Win32.TranslateMessage (ref msg);
  42. Win32.DispatchMessageA (ref msg);
  43. }
  44. }
  45. }