MWMAIN.MOD 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  1. (*# check(stack=>off,
  2. index=>off,
  3. range=>off,
  4. overflow=>off,
  5. nil_ptr=>off) *)
  6. IMPLEMENTATION MODULE MWMain;
  7. IMPORT Windows;
  8. CONST
  9. (* String table constants *)
  10. IDSNAME = 100;
  11. IDSABOUT = 200;
  12. IDSTITLE = 300;
  13. (* About Dialog box resource id *)
  14. ABOUTBOX = 1;
  15. VAR
  16. szAppName: ARRAY [0..9] OF CHAR;
  17. szAbout: ARRAY [0..9] OF CHAR;
  18. szMessage: ARRAY [0..25] OF CHAR;
  19. MessageLength: CARDINAL;
  20. hInst: Windows.HANDLE;
  21. lpprocAbout: Windows.FARPROC;
  22. PROCEDURE MessagePaint(hdc: Windows.HDC);
  23. BEGIN
  24. Windows.TextOut(hdc, 10, 10, szMessage, MessageLength );
  25. END MessagePaint;
  26. (* Procedures which make up the window class. *)
  27. PROCEDURE WndProc(hWnd: Windows.HWND; message: CARDINAL; wParam: CARDINAL; lParam: LONGINT ): LONGINT;
  28. VAR
  29. ps: Windows.PAINTSTRUCT;
  30. BEGIN
  31. CASE message OF
  32. | Windows.WM_SYSCOMMAND:
  33. CASE wParam OF
  34. | IDSABOUT:
  35. Windows.DialogBox( hInst, FarADDRESS(LONGCARD(ABOUTBOX)), hWnd, lpprocAbout );
  36. ELSE
  37. RETURN Windows.DefWindowProc( hWnd, message, wParam, lParam);
  38. END;
  39. | Windows.WM_DESTROY:
  40. Windows.PostQuitMessage(0);
  41. | Windows.WM_PAINT:
  42. Windows.BeginPaint(hWnd, ps);
  43. MessagePaint(ps.hdc);
  44. Windows.EndPaint(hWnd, ps);
  45. ELSE
  46. RETURN Windows.DefWindowProc( hWnd, message, wParam, lParam);
  47. END;
  48. RETURN 0;
  49. END WndProc;
  50. PROCEDURE About ( hDlg : Windows.HWND;
  51. message : CARDINAL;
  52. wParam : WORD;
  53. lParam : LONGINT ) : Windows.BOOL ;
  54. BEGIN
  55. IF message = Windows.WM_COMMAND THEN
  56. Windows.EndDialog( hDlg, CARDINAL(TRUE) );
  57. RETURN INTEGER(TRUE);
  58. ELSIF message = Windows.WM_INITDIALOG THEN
  59. RETURN INTEGER(TRUE);
  60. ELSE
  61. RETURN INTEGER(FALSE);
  62. END;
  63. END About;
  64. (* This procedure called when the program is loaded for the first time *)
  65. PROCEDURE DemoInit(hInstance: Windows.HANDLE): BOOLEAN;
  66. VAR
  67. DemoClass: Windows.WNDCLASS;
  68. BEGIN
  69. (* Load strings from resource *)
  70. Windows.LoadString(hInstance, IDSNAME, szAppName, 10);
  71. Windows.LoadString(hInstance, IDSABOUT, szAbout, 10);
  72. MessageLength:=Windows.LoadString(hInstance, IDSTITLE, szMessage, 25);
  73. DemoClass.hCursor := Windows.LoadCursor(Windows.HANDLE(0), FarADDRESS(Windows.IDC_ARROW));
  74. DemoClass.hIcon := Windows.LoadIcon(hInstance, FarADR("wdemo"));
  75. DemoClass.lpszMenuName := FarNIL;
  76. DemoClass.lpszClassName := Windows.LPSTR(FarADR(szAppName));
  77. DemoClass.hbrBackground := Windows.HBRUSH(Windows.GetStockObject(Windows.WHITE_BRUSH));
  78. DemoClass.hInstance:=hInstance;
  79. DemoClass.style := Windows.CS_HREDRAW + Windows.CS_VREDRAW;
  80. DemoClass.lpfnWndProc := FarADR(WndProc);
  81. DemoClass.cbClsExtra := 0;
  82. DemoClass.cbWndExtra := 0;
  83. IF Windows.RegisterClass(DemoClass) = 0 THEN
  84. RETURN FALSE; (* Initialization failed. *)
  85. END;
  86. RETURN TRUE; (* Success *)
  87. END DemoInit;
  88. PROCEDURE WinMain(hInstance: Windows.HANDLE; hPrevInstance: Windows.HANDLE; lpszCmdLine: Windows.LPSTR; cmdShow: INTEGER): Windows.BOOL;
  89. VAR
  90. msg: Windows.MSG;
  91. hWnd: Windows.HWND;
  92. hMenu: Windows.HMENU;
  93. BEGIN
  94. IF hPrevInstance = Windows.HANDLE(0) THEN
  95. (* Call initialization procedure if this is the first instance *)
  96. IF NOT DemoInit(hInstance) THEN
  97. RETURN INTEGER(FALSE);
  98. END;
  99. ELSE
  100. (* Copy data from previous instance *)
  101. Windows.GetInstanceData(hPrevInstance, NearADR(szAppName), 10);
  102. Windows.GetInstanceData(hPrevInstance, NearADR(szAbout), 10);
  103. Windows.GetInstanceData(hPrevInstance, NearADR(szMessage), 25);
  104. Windows.GetInstanceData(hPrevInstance, NearADR(MessageLength),SIZE(CARDINAL));
  105. END;
  106. hWnd := Windows.CreateWindow(FarADR(szAppName),
  107. szMessage,
  108. Windows.WS_TILEDWINDOW ,
  109. Windows.CW_USEDEFAULT,
  110. Windows.CW_USEDEFAULT,
  111. Windows.CW_USEDEFAULT,
  112. Windows.CW_USEDEFAULT,
  113. Windows.HWND(0), (* no parent *)
  114. Windows.HMENU(0), (* use class menu *)
  115. hInstance, (* handle to window instance *)
  116. FarNIL (* no params to pass on *)
  117. );
  118. (* Save instance handle for DialogBox *)
  119. hInst := hInstance;
  120. lpprocAbout := Windows.MakeProcInstance( Windows.FARPROC(FarADR(About)), hInstance );
  121. (* Insert About *)
  122. hMenu:= Windows.GetSystemMenu(hWnd, Windows.False);
  123. Windows.ChangeMenu(hMenu, 0, FarNIL, 999, Windows.MF_APPEND + Windows.MF_SEPARATOR);
  124. Windows.ChangeMenu(hMenu, 0, FarADR(szAbout), IDSABOUT, Windows.MF_APPEND + Windows.MF_STRING);
  125. (* Make window visible according to the way the app is activated *)
  126. Windows.ShowWindow(hWnd, cmdShow);
  127. Windows.UpdateWindow(hWnd);
  128. (* Polling messages from event queue *)
  129. WHILE (Windows.GetMessage(msg, Windows.HWND(0), 0, 0)) # 0 DO
  130. Windows.TranslateMessage(msg);
  131. Windows.DispatchMessage(msg);
  132. END;
  133. RETURN msg.wParam;
  134. END WinMain;
  135. END MWMain.
  136.