home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / vp21beta.zip / ORTLSRC.RAR / PMOBJ.PAS < prev   
Pascal/Delphi Source File  |  2000-08-15  |  4KB  |  193 lines

  1. {█▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀█}
  2. {█                                                       █}
  3. {█      Virtual Pascal Examples. Version 2.1.            █}
  4. {█      Simple base objects for Presentation Manager.    █}
  5. {█      ─────────────────────────────────────────────────█}
  6. {█      Copyright (C) 1995-2000 vpascal.com              █}
  7. {█                                                       █}
  8. {▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀}
  9.  
  10. unit PmObj;
  11.  
  12. {&Use32+}
  13.  
  14. interface
  15.  
  16. uses Os2Def, Os2PmApi;
  17.  
  18. { Resource ID for main client window }
  19.  
  20. const
  21.   idClientWindow = 11000;
  22.  
  23. { Base PM object }
  24.  
  25. type
  26.   PPMObject = ^PMObject;
  27.   PMObject = object
  28.     constructor Init;
  29.     procedure Free;
  30.     destructor Done; virtual;
  31.   end;
  32.  
  33. { PM Application }
  34.  
  35.   PPMApplication = ^PMApplication;
  36.   PMApplication = object(PMObject)
  37.     constructor Init;
  38.     procedure   Run;
  39.     destructor  Done; virtual;
  40.   end;
  41.  
  42.  { PM Window }
  43.  
  44.   PPMWindow = ^PMWindow;
  45.   PMWindow  = object(PMObject)
  46.     ClassName: PChar;                   { Name of then window class }
  47.     Title: PChar;
  48.     FrameWindow,ClientWindow: HWnd;
  49.     constructor Init(ATitle,AClassName: PChar; ACreateFlags: Longint);
  50.     procedure Register;
  51.     function HandleMessage(Window: HWnd; Msg: ULong; Mp1,Mp2 : MParam): MResult; virtual;
  52.     procedure StartupAction; virtual;
  53.     destructor Done; virtual;
  54.   end;
  55.  
  56. { Type cast records }
  57.  
  58.   WordRec = record
  59.    Lo,Hi: Byte;
  60.   end;
  61.  
  62.   LongRec = record
  63.    Lo,Hi: SmallWord;
  64.   end;
  65.  
  66. { Public variables }
  67.  
  68. var
  69.   Anchor: HAB;
  70.   MsgQue: HMQ;
  71.   DesktopSize: PointL;
  72.  
  73. const
  74.   HWndParent: HWnd = hwnd_Desktop;
  75.  
  76. function ClientWndProc(Window: HWnd; Msg: ULong; Mp1,Mp2: MParam): MResult; cdecl; export;
  77.  
  78. implementation
  79.  
  80. { Private variables }
  81.  
  82. var
  83.   TempSelf: PPMWindow;
  84.  
  85. { Client Window Procedure }
  86.  
  87. function ClientWndProc(Window: HWnd; Msg: ULong; Mp1,Mp2: MParam): MResult;
  88. var
  89.   PWindow: PPMWindow;
  90.   Exist: Boolean;
  91. begin
  92.   Exist := False;
  93.   PWindow := PPMWindow(WinQueryWindowULong(Window, 0));
  94.   if (PWindow = nil) then
  95.   begin
  96.     if (Msg = wm_Create) then
  97.     begin
  98.       PWindow := TempSelf;
  99.       WinSetWindowULong(Window, 0, Longint(PWindow));
  100.       Exist := True;
  101.     end
  102.   end else Exist := True;
  103.   if Exist then ClientWndProc := PWindow^.HandleMessage(Window, Msg, Mp1, Mp2)
  104.     else ClientWndProc := WinDefWindowProc(Window, Msg, Mp1, Mp2);
  105. end;
  106.  
  107. { PMObject }
  108.  
  109. constructor PMObject.Init;
  110. type
  111.   Image = record
  112.     Link: Longint;
  113.     Data: record end;
  114.   end;
  115. begin
  116.   FillChar(Image(Self).Data, SizeOf(Self) - SizeOf(PMObject), 0);
  117. end;
  118.  
  119. destructor PMObject.Done;
  120. begin
  121. end;
  122.  
  123. { Shorthand procedure for a Done/Dispose }
  124.  
  125. procedure PMObject.Free;
  126. begin
  127.   Dispose(PPMObject(@Self), Done);
  128. end;
  129.  
  130. { PMApplication }
  131.  
  132. constructor PMApplication.Init;
  133. begin
  134.   inherited Init;
  135.   Anchor := WinInitialize(0);
  136.   { It might be beneficial to set the second parameter of the following }
  137.   { call to something large, such as 1000.  The OS/2 documentation does }
  138.   { not recommend this, however }
  139.   MsgQue := WinCreateMsgQueue(Anchor, 0);
  140.   if MsgQue = 0 then Halt(254);
  141.   DesktopSize.X := WinQuerySysValue(hwnd_Desktop, sv_CxScreen);
  142.   DesktopSize.Y := WinQuerySysValue(hwnd_Desktop, sv_CyScreen);
  143. end;
  144.  
  145. destructor PMApplication.Done;
  146. begin
  147.   WinDestroyMsgQueue(MsgQue);
  148.   WinTerminate(Anchor);
  149.   inherited Done;
  150. end;
  151.  
  152. procedure PMApplication.Run;
  153. var
  154.   Message: QMsg;
  155. begin
  156.   while WinGetMsg(Anchor, Message, 0, 0, 0) do WinDispatchMsg(Anchor, Message);
  157. end;
  158.  
  159. { PMWindow }
  160.  
  161. constructor PMWindow.Init(ATitle,AClassName: PChar; ACreateFlags: Longint);
  162. begin
  163.   inherited Init;
  164.   Title := ATitle;
  165.   ClassName := AClassName;
  166.   TempSelf := @Self;
  167.   Register;
  168.   FrameWindow := WinCreateStdWindow(HWndParent, 0, ACreateFlags, ClassName,
  169.     Title, 0, 0, idClientWindow, @ClientWindow);
  170.   StartupAction;
  171. end;
  172.  
  173. procedure PMWindow.Register;
  174. begin
  175.   WinRegisterClass(Anchor, ClassName, ClientWndProc, cs_SizeRedraw, SizeOf(Pointer));
  176. end;
  177.  
  178. function PMWindow.HandleMessage(Window: HWnd; Msg: ULong; Mp1,Mp2 : MParam): MResult;
  179. begin
  180. end;
  181.  
  182. procedure PMWindow.StartupAction;
  183. begin
  184. end;
  185.  
  186. destructor PMWindow.Done;
  187. begin
  188.   WinDestroyWindow(FrameWindow);
  189.   inherited Done;
  190. end;
  191.  
  192. end.
  193.