MWMAIN_D.MOD 5.3 KB

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