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

  1. -- $Source: /home/harp/1/proto/monoBANK/winnt/ddemo.adb,v $ 
  2. -- $Revision: 1.1 $ $Date: 95/02/10 16:53:30 $ $Author: mg $ 
  3.  
  4. --/****************************************************************************\
  5. --*
  6. --* DDEMO.ADB
  7. --*
  8. --* This file implements a simple DDEML sample application that demonstrates
  9. --* some of the ways the DDEML APIs can be used.
  10. --*
  11. --* Each instance of this application becomes both a DDE client and a DDE
  12. --* server with any other instances of this application that are found.
  13. --*
  14. --* Since it assumes it is talking to itself, this program takes some liberties
  15. --* to simplify things.  For instance, this application does not support the
  16. --* standard SysTopic topic and does not use any standard formats.
  17. --*
  18. --* The basic concepts this application will show you are:
  19. --*                                             
  20. --*   How to handle links            
  21. --*   How to use lists of conversations properly
  22. --*   How to handle simple asynchronous transactions
  23. --*   How to use your own custom formats
  24. --*
  25. -- ------------------------------------------------------------------
  26. -- To use this demo:
  27. -- From a command prompt, type "start ddemo" multiple times.
  28. -- Each instance of ddemo represents one counter, and the counters of all
  29. --    active instances of the application show in every window.
  30. -- You start the counter for an instance by pushing the left mouse button on its
  31. --    window, and stop it by pressing the right mouse button.  Typing 'b' in a 
  32. --    window will cause it to throw an unhandled exception (verifying that the
  33. --    other instances handle that correctly).
  34. --
  35. -- ------------------------------------------------------------------
  36.  
  37.  
  38. pragma Linker_Options("-lwin32ada");
  39.  
  40.  
  41. with Win32;    use Win32;
  42. with Win32.Windef;
  43. with Win32.Winuser;
  44. with Win32.WinMain;
  45. with Win32.DDEML;
  46.  
  47. with Ada.Unchecked_Conversion;
  48. with Interfaces.C;
  49. with Interfaces.C.Strings;
  50. with Text_IO;
  51. with DDEmoPkg; use DDEmoPkg;
  52.  
  53. use type Interfaces.C.INT;
  54. use type Interfaces.C.LONG;
  55. use type Win32.Windef.HWND;
  56.  
  57.  
  58. procedure DDEMO is
  59.  
  60.     -- define dummy variables to hold results of function calls
  61.     lResult : Win32.LONG;
  62.  
  63.     hdc:   Windef.HDC;
  64.     hInst: WinDef.HINSTANCE;            -- our instance/module handle
  65.     MSG:   Winuser.LPMSG;
  66.  
  67.  
  68.  
  69. --  FUNCTION: InitApplication(HINSTANCE)
  70. --
  71. --  PURPOSE: Initializes window data and registers window class
  72. --
  73. --  COMMENTS:
  74. --
  75. --  This function is called at initialization time only if no other
  76. --  instances of the application are running.  This function performs
  77. --  initialization tasks that can be done once for any number of running
  78. --  instances.
  79. --
  80. --  In this case, we initialize a window class by filling out a data
  81. --  structure of type WNDCLASS and calling the Windows RegisterClass()
  82. --  function.  Since all instances of this application use the same window
  83. --  class, we only need to do this when the first instance is initialized.
  84.  
  85. function InitApplication(hInstance : Windef.HINSTANCE)
  86.     return Win32.BOOL is
  87.  
  88.   ATOM   : Windef.ATOM;
  89.   WC_Ptr : Win32.Winuser.PWNDCLASSA;
  90. begin
  91.   wc :=(
  92.         style         => 0,
  93.         lpfnWndProc   => MainWndProc'Access,
  94.         cbClsExtra    => 0,                      
  95.         cbWndExtra    => 0,
  96.         hInstance     => hInstance, 
  97.         hIcon         => System.Null_Address,
  98.         hCursor       => WinUser.LoadCursor(System.Null_Address,
  99.                                           Win32.LPCSTR(WinUser.IDC_ARROW)),
  100.         hbrBackground => System.Null_Address,
  101.         lpszMenuName  => null,
  102.         lpszClassName => szTitle);
  103.   WC_Ptr := WC'Access;
  104.   --  Register the window class and return success/failure code.
  105.   return Win32.BOOL (Winuser.RegisterClass
  106.                            (Winuser.ac_WNDCLASSA_t(WC_Ptr)));
  107.  
  108. end InitApplication;
  109.  
  110.  
  111.  
  112. begin  -- DDemo
  113.      HINST := WinMain.Get_Hinstance;
  114.      bResult := InitApplication(HINST);
  115.  
  116.      -- Here we tell DDEML what we will be doing.
  117.      --
  118.      -- 1) We let it know our callback proc address - MakeProcInstance
  119.      --      is called just to be more portable.
  120.      -- 2) Filter-inits - don't accept any WM_DDE_INITIATE messages for
  121.      --      anything but our registered service name.
  122.      -- 3) Don't bother to notify us of confirmed connections
  123.      -- 4) Don't allow connections with ourselves.
  124.      -- 5) Don't bother us with XTYP_POKE transactions.
  125.  
  126.     uResult := DDEML.DdeInitialize(idInst'Access, DdeCallback'Access,
  127.                             DDEML.APPCMD_FILTERINITS or
  128.                             DDEML.CBF_SKIP_CONNECT_CONFIRMS or
  129.                             DDEML.CBF_FAIL_SELFCONNECTIONS or
  130.                             DDEML.CBF_FAIL_POKES,
  131.                             0);
  132.  
  133.      --  Create a main window for this application instance.
  134.      hwndMain := WinUser.CreateWindow (
  135.             lpClassName  => szTitle,
  136.             lpWindowName => szTitle,
  137.             dwStyle      => WinUser.WS_CAPTION or 
  138.                             WinUser.WS_BORDER or 
  139.                             WinUser.WS_SYSMENU,
  140.             X            => WinUser.CW_USEDEFAULT, 
  141.             Y            => WinUser.CW_USEDEFAULT,
  142.             nWidth       => 0,
  143.             nHeight      => 0,
  144.             hWndParent   => System.Null_Address,
  145.             hMenu        => System.Null_Address,
  146.             hInstance    => HINST,
  147.             lpParam      => System.Null_Address);
  148.  
  149.      --   If window could not be created, return "failure"
  150.      if hwndMain = System.Null_Address then
  151.           bResult := DDEML.DdeUninitialize(idInst);
  152.           return;
  153.      end if;
  154.  
  155.      hdc := WinUser.GetDC(hwndMain);
  156.      bResult := Wingdi.GetTextMetrics(hdc, metrics'Access);
  157.  
  158.     cyText := Win32.INT(metrics.tmHeight + metrics.tmExternalLeading);
  159.     cxText := Win32.INT(metrics.tmMaxCharWidth * 8);
  160.     cyTitle := WinUser.GetSystemMetrics(WinUser.SM_CYCAPTION);
  161.     iResult := WinUser.ReleaseDC(hwndMain, hdc);
  162.  
  163.     bResult := WinUser.SetWindowPos(hwndMain, System.Null_Address, 0, 0, 
  164.                         cxText, cyText + cyTitle,
  165.                     WinUser.SWP_NOMOVE or WinUser.SWP_NOZORDER or
  166.                     WinUser.SWP_NOREDRAW or WinUser.SWP_NOACTIVATE);
  167.     bResult := WinUser.ShowWindow(hwndMain, WinMain.Get_nCmdShow);
  168.     bResult := WinUser.UpdateWindow(hwndMain);
  169.  
  170.  
  171.      -- Initialize all our string handles for lookups later
  172.     hszAppName := DDEML.DdeCreateStringHandle(idInst, Win32.LPSTR(szApp), 0);
  173.  
  174.      -- Register our formats
  175.     OurFormat := WinUser.RegisterClipboardFormat(Win32.LPCSTR(szApp));
  176.  
  177.      -- Connect to any other instances of ourselves that may already be
  178.      -- running.
  179.     hConvList := DDEML.DdeConnectList(idInst, hszAppName, hszAppName, 
  180.                                       hConvList, NULL);
  181.  
  182.      -- Register our service -
  183.      --  This will cause DDEML to notify DDEML clients about the existance
  184.      --  of a new DDE service.
  185.     hddeResult := DDEML.DdeNameService(idInst, hszAppName, 0, 
  186.                                        DDEML.DNS_REGISTER);
  187.  
  188.     -- Acquire and dispatch messages until a WM_QUIT message is received.
  189.     MSG := new Winuser.MSG;
  190.     while (Winuser.GetMessage (MSG, System.Null_Address, 
  191.                                Win32.UINT(0), Win32.UINT(0)) /= 0)
  192.         loop
  193.             bResult := Winuser.TranslateMessage(Winuser.ac_MSG_t(MSG));
  194.             lResult := Winuser.DispatchMessage(Winuser.ac_MSG_t(MSG));
  195.         end loop;
  196.  
  197.     bResult := Winuser.DestroyWindow(hwndMain);
  198.     bResult := Winuser.UnregisterClass(szTitle, hInst);
  199.  
  200. -------------------------------------------------------------------------------
  201. --
  202. -- THIS FILE AND ANY ASSOCIATED DOCUMENTATION IS PROVIDED "AS IS" WITHOUT 
  203. -- WARRANTY OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT 
  204. -- LIMITED TO THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR 
  205. -- A PARTICULAR PURPOSE.  The user assumes the entire risk as to the accuracy 
  206. -- and the use of this file.  This file may be used only by licensees of 
  207. -- Microsoft Corporation's WIN32 Software Development Kit in accordance with 
  208. -- the terms of the licensee's End-User License Agreement for Microsoft 
  209. -- Software for the WIN32 Development Kit.
  210. --
  211. -- Copyright (c) Intermetrics, Inc. 1995
  212. -- Portions (c) 1985-1994 Microsoft Corporation with permission.
  213. -- Microsoft is a registered trademark and Windows and Windows NT are 
  214. -- trademarks of Microsoft Corporation.
  215. --
  216. -------------------------------------------------------------------------------
  217.  
  218. end DDEMO;
  219.