muihelloworld.pas 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. program muihelloworld;
  2. // Example Source for MUIHelper, Simple Window and Button
  3. uses
  4. {$if defined(MorphOS) or defined(Amiga)}
  5. amigalib,
  6. {$endif}
  7. Exec, Utility, intuition, AmigaDos, mui, muihelper;
  8. procedure StartMe;
  9. var
  10. App, Window, Button, NLabel: PObject_;
  11. Sigs: LongInt;
  12. begin
  13. App := MH_Application([
  14. MUIA_Application_Title, AsTag('MUIHelloWorld'),
  15. MUIA_Application_Version, AsTag('$VER: MUIHelloWorld 1.0 (18.12.2016)'),
  16. MUIA_Application_Copyright, AsTag('©2016, FreePascal Developer'),
  17. MUIA_Application_Author, AsTag('FreePascal Developer'),
  18. MUIA_Application_Description, AsTag('Hello World Demo for MUI Helper'),
  19. MUIA_Application_Base, AsTag('HELLOWORLD'),
  20. SubWindow, AsTag(MH_Window(Window, [
  21. MUIA_Window_Title, AsTag('Hello World'),
  22. MUIA_Window_ID, MAKE_ID('H','E','W','O'),
  23. WindowContents, AsTag(MH_VGroup([
  24. Child, AsTag(MH_CLabel(NLabel, 'Hello')),
  25. Child, AsTag(MH_CLabel(NLabel, 'World')),
  26. Child, AsTag(MH_Button(Button, 'Click me')),
  27. TAG_END])), // MH_VGroup()
  28. TAG_END])), // MH_Window()
  29. TAG_END]); // MH_Application()
  30. //
  31. // Check if successfully Created
  32. if not Assigned(App) then
  33. begin
  34. WriteLn('Failed to create Application');
  35. Exit;
  36. end;
  37. // Connect Close Event
  38. DoMethod(Window, [MUIM_Notify, MUIA_Window_CloseRequest, MUI_TRUE,
  39. AsTag(App), 2, AsTag(MUIM_Application_ReturnID), AsTag(MUIV_Application_ReturnID_Quit)]);
  40. // Change Label on Button Click
  41. DoMethod(Button, [MUIM_Notify, MUIA_Pressed, MUI_FALSE,
  42. AsTag(NLabel), 3, AsTag(MUIM_SET), AsTag(MUIA_Text_Contents), AsTag('FreePascal')]);
  43. // Open the Window
  44. MH_Set(Window, MUIA_Window_Open, AsTag(True));
  45. // Main Loop
  46. if MH_Get(Window, MUIA_Window_Open) <> 0 then
  47. begin
  48. while Integer(DoMethod(app, [MUIM_Application_NewInput, AsTag(@sigs)])) <> MUIV_Application_ReturnID_Quit do
  49. begin
  50. if Sigs <> 0 then
  51. begin
  52. Sigs := Wait(sigs or SIGBREAKF_CTRL_C);
  53. if (Sigs and SIGBREAKF_CTRL_C) <>0 then
  54. Break;
  55. end;
  56. end;
  57. end;
  58. // Close Window
  59. MH_Set(Window, MUIA_Window_Open, AsTag(True));
  60. // Free MUI Objects
  61. MUI_DisposeObject(app);
  62. end;
  63. begin
  64. StartMe;
  65. end.