home *** CD-ROM | disk | FTP | other *** search
/ Solo Programadores 22 / SOLO_22.iso / packages / win32ada / data.z / generic_ada.adb < prev    next >
Encoding:
Text File  |  1995-12-05  |  7.3 KB  |  202 lines

  1. -- $Source: /home/harp/1/proto/monoBANK/winnt/generic_ada.adb,v $ 
  2. -- $Revision: 1.1 $ $Date: 95/02/09 14:57:10 $ $Author: mg $ 
  3. --
  4. -- Notes: All Ada main programs should be functions so they can return exit
  5. --        status.
  6. --        Reserved names.
  7. --        Ordering of functions.
  8. --
  9. --   PROGRAM: Generic_Ada.adb  (based on Generic.c)
  10. --        (changed by MG, from TG version, to go with Xmuter)
  11. --
  12. --   PURPOSE: Generic template for Windows applications
  13. --
  14. --   FUNCTIONS:
  15. --
  16. --   Generic_Ada() - calls initialization function, processes message loop
  17. --   InitApplication() - initializes window data and registers window
  18. --   InitInstance() - saves instance handle and creates main window
  19. --   WndProc() - processes messages
  20. --   CenterWindow() - used to center the "About" box over application window
  21. --   About() - processes messages for "About" dialog box
  22. --
  23. --   COMMENTS:
  24. --
  25. --   The Windows SDK Generic Application Example is a sample application
  26. --   that you can use to get an idea of how to perform some of the simple
  27. --   functionality that all Applications written for Microsoft Windows
  28. --   should implement. You can use this application as either a starting
  29. --   point from which to build your own applications, or for quickly
  30. --   testing out functionality of an interesting Windows API.
  31.  
  32. pragma Linker_Options("-lwin32ada");
  33.  
  34.  
  35. with ma_extra;
  36. with Interfaces.C;
  37. with Interfaces.C.Strings;
  38. with Generic_Pkg; use Generic_Pkg;
  39. with Win32;    use Win32;
  40. with Win32.Winnt;
  41. with Win32.Windef;
  42. with Win32.Winuser;
  43. with Win32.Wingdi;
  44. with Win32.WinMain;
  45. with Ada.Text_IO; use Ada.Text_IO; 
  46. with Unchecked_Conversion;
  47.  
  48.  
  49. procedure Generic_Ada is
  50.  
  51. use type Interfaces.C.INT;
  52.  
  53.  
  54. SZTITLE     : Win32.LPCSTR := CP("Generic Sample Ada Application");    -- title
  55.  
  56. MSG         : Winuser.LPMSG;
  57. HACCELTABLE : Windef.HACCEL;
  58.  
  59. lResult     : Win32.LRESULT;
  60.  
  61.  
  62.  
  63.  
  64. --  FUNCTION: InitApplication(HINSTANCE)
  65. --
  66. --  PURPOSE: Initializes window data and registers window class
  67. --
  68. --  COMMENTS:
  69. --
  70. --  This function is called at initialization time only if no other
  71. --  instances of the application are running.  This function performs
  72. --  initialization tasks that can be done once for any number of running
  73. --  instances.
  74. --
  75. --  In this case, we initialize a window class by filling out a data
  76. --  structure of type WNDCLASS and calling the Windows RegisterClass()
  77. --  function.  Since all instances of this application use the same window
  78. --  class, we only need to do this when the first instance is initialized.
  79.  
  80. function InitApplication(hInstance : Windef.HINSTANCE)
  81.     return Win32.BOOL is
  82.  
  83.   WC_Ptr : Winuser.PWNDCLASSA;
  84.   ATOM   : Windef.ATOM;
  85. begin
  86.   wc := (
  87.         style       => Winuser.CS_HREDRAW or 
  88.                        Winuser.CS_VREDRAW,
  89.         lpfnWndProc => WndProc'Access,
  90.         cbClsExtra  => 0,                                  
  91.         cbWndExtra  => 0,
  92.         hInstance   => hInstance, 
  93.         hIcon       => WinUser.LoadIcon(hInstance,
  94.                                         Win32.LPCSTR(WinUser.MAKEINTRESOURCE(
  95.                                             ma_extra.IDI_APP))),
  96.         hCursor       => WinUser.LoadCursor(System.Null_Address,
  97.                                             Win32.LPCSTR(WinUser.IDC_CROSS)),
  98.         hbrBackground => WinDef.HBRUSH(WinGdi.GetStockObject(
  99.                                        WinGdi.LTGRAY_BRUSH)),
  100.         lpszMenuName  => Win32.LPCSTR(WinUser.MAKEINTRESOURCE(
  101.                                       ma_extra.IDR_GENERIC)),
  102.         lpszClassName => SZAPPNAME);
  103.  
  104.   WC_Ptr := WC'Access;
  105.   --  Register the window class and return success/failure code.
  106.   return Win32.BOOL (Winuser.RegisterClass(Winuser.ac_WNDCLASSA_t(WC_Ptr)));
  107.  
  108. end InitApplication;
  109.  
  110.  
  111. --  FUNCTION:  InitInstance(hinstance, int)
  112. --
  113. --  PURPOSE:  Saves instance handle and creates main window
  114. --
  115. --  COMMENTS:
  116. --
  117. --  This function is called at initialization time for every instance of
  118. --  this application.  This function performs initialization tasks that
  119. --  cannot be shared by multiple instances.
  120. --
  121. --  In this case, we save the instance handle in a static variable and
  122. --  create and display the main program window.
  123. function InitInstance(hinstance : Windef.HINSTANCE;
  124.                       ncmdshow  : Win32.INT) return Win32.BOOL is
  125.  
  126.   use type System.Address;
  127.  
  128.   HWND : Windef.HWND;
  129.  
  130. begin
  131.   -- // Create a main window for this application instance.
  132.   HWND := WinUser.CreateWindow (
  133.               lpClassName => SZAPPNAME,
  134.               lpWindowName=> SZTITLE,
  135.               dwStyle     => WinUser.WS_OVERLAPPEDWINDOW or 
  136.                              WinUser.WS_CLIPCHILDREN,
  137.               X           => WinUser.CW_USEDEFAULT, 
  138.               Y           => WinUser.CW_USEDEFAULT,
  139.               nWidth      => WinUser.CW_USEDEFAULT,
  140.               nHeight     => WinUser.CW_USEDEFAULT,
  141.               hWndParent  => System.Null_Address,
  142.               hMenu       => System.Null_Address,
  143.               hInstance   => hInstance,
  144.               lpParam     => System.Null_Address);
  145.  
  146.   --  // If window could not be created, return "failure"
  147.   if HWND = System.Null_Address then
  148.     return Win32.FALSE;
  149.   end if;
  150.  
  151.   -- // Make the window visible; update its client area; and return "success"
  152.   bResult := Winuser.ShowWindow(HWND, NCMDSHOW); -- Show the window
  153.   bResult := Winuser.UpdateWindow(HWND);         -- Sends WM_PAINT message
  154.  
  155.   -- /*
  156.   -- ** DEMO MODE - PostMessage used for Demonstration only
  157.   -- */
  158.   bResult := Winuser.PostMessage(HWND, Winuser.WM_COMMAND,
  159.                                  ma_extra.IDM_ABOUT, 0);
  160.   return Win32.TRUE;
  161.  
  162. end InitInstance;
  163.  
  164.  
  165. begin  -- GENERIC_ADA
  166.   HINST   := WinMain.Get_Hinstance;
  167.   bResult := InitApplication(HINST);
  168.   bResult := InitInstance(HINST, WinMain.Get_nCmdShow);
  169.  
  170.   HACCELTABLE := Winuser.LoadAccelerators(HINST, SZAPPNAME);
  171.  
  172.   -- Acquire and dispatch messages until a WM_QUIT message is received.
  173.   MSG := new Winuser.MSG;
  174.   while (Winuser.GetMessage (MSG, System.Null_Address,
  175.                              Win32.UINT(0), Win32.UINT(0)) /= 0)
  176.   loop
  177.     iResult := Winuser.TranslateAccelerator(MSG.HWND, HACCELTABLE, 
  178.                                             Winuser.ac_MSG_t(MSG));
  179.     bResult := Winuser.TranslateMessage(Winuser.ac_MSG_t(MSG));
  180.     lResult := Winuser.DispatchMessage(Winuser.ac_MSG_t(MSG));
  181.   end loop;
  182.  
  183. -------------------------------------------------------------------------------
  184. --
  185. -- THIS FILE AND ANY ASSOCIATED DOCUMENTATION IS PROVIDED "AS IS" WITHOUT 
  186. -- WARRANTY OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT 
  187. -- LIMITED TO THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR 
  188. -- A PARTICULAR PURPOSE.  The user assumes the entire risk as to the accuracy 
  189. -- and the use of this file.  This file may be used only by licensees of 
  190. -- Microsoft Corporation's WIN32 Software Development Kit in accordance with 
  191. -- the terms of the licensee's End-User License Agreement for Microsoft 
  192. -- Software for the WIN32 Development Kit.
  193. --
  194. -- Copyright (c) Intermetrics, Inc. 1995
  195. -- Portions (c) 1985-1994 Microsoft Corporation with permission.
  196. -- Microsoft is a registered trademark and Windows and Windows NT are 
  197. -- trademarks of Microsoft Corporation.
  198. --
  199. -------------------------------------------------------------------------------
  200.  
  201. end Generic_Ada;
  202.