home *** CD-ROM | disk | FTP | other *** search
- -- $Source: /home/harp/1/proto/monoBANK/winnt/aliaspkg.adb,v $
- -- $Revision: 1.2 $ $Date: 95/12/20 17:22:16 $ $Author: mg $
- -- $Id: pcx.adb 1.5 1995/02/08 18:30:27 mps Exp mps $
- --
- -- PROGRAM: pcx.adb
- --
- -- PURPOSE: Provide display of PCX files
- --
- -- COMMENTS:
- -- The LabTek PCX Application Example is a sample application
- -- that you can use to get an idea of how to perform some of the simple
- -- functionality that the Windows GDI API implements.
- -- Note that no 'use' clauses were used to help get a better idea on where
- -- various type are located in the binding. Readability improves greatly
- -- once a 'use Win32;' is used.
- --
- -- NOTES:
- -- There is currently no help file.
- -- pcxops.adb uses Unix style opens and reads instead of the Win32 variants.
- --
-
- with Ada.Unchecked_Conversion;
- with File;
- with PcxOps;
-
- package body AliasPkg is
-
- use type Interfaces.C.INT;
- use type Interfaces.C.UNSIGNED_SHORT;
- use type Win32.BOOL;
- --
- -- These are declared in pcx.h as well. If these are modified, then pcx.h must
- -- be modified as well!
- --
- IDM_NEW : constant := 100;
- IDM_OPEN : constant := 101;
- IDM_SAVE : constant := 102;
- IDM_SAVEAS : constant := 103;
- IDM_PRINT : constant := 104;
- IDM_PRINTSETUP : constant := 105;
- IDM_EXIT : constant := 106;
- IDM_UNDO : constant := 200;
- IDM_CUT : constant := 201;
- IDM_COPY : constant := 202;
- IDM_PASTE : constant := 203;
- IDM_LINK : constant := 204;
- IDM_LINKS : constant := 205;
- IDM_HELPCONTENTS : constant := 300;
- IDM_HELPSEARCH : constant := 301;
- IDM_HELPHELP : constant := 302;
- IDM_ABOUT : constant := 303;
- DLG_VERFIRST : constant := 400;
- DLG_VERLAST : constant := 401;
-
-
- function CP(S : Win32.CHAR_Array) return Win32.LPCSTR is
- function UC is new Ada.Unchecked_Conversion(System.Address,Win32.LPCSTR);
- begin
- return UC(S(S'First)'Address);
- end CP;
-
- function To_CA (S: String) return Win32.CHAR_Array is
- begin
- return Win32.To_Win(Interfaces.C.To_C(S));
- end To_CA;
-
- function To_DWORD is new Ada.Unchecked_Conversion(
- Win32.WPARAM, Win32.DWORD);
-
- -- Standard "About" box display.
- --
- function About(HDLG : Win32.WinDef.HWND;
- MESSAGE : Win32.UINT;
- WPARAM : Win32.WPARAM;
- LPARAM : Win32.LPARAM) return Win32.BOOL is
-
- CMDID : Win32.WORD;
- BRESULT : Win32.BOOL;
-
- begin
- case MESSAGE is
-
- when Win32.WinUser.WM_COMMAND =>
- CMDID := Win32.Utils.LoWord(To_DWORD(WPARAM));
- if ((CMDID = Win32.WinUser.IDOK) or
- (CMDID = Win32.WinUser.IDCANCEL)) then
- BRESULT := Win32.WinUser.EndDialog (HDLG, 1);
- return Win32.TRUE;
- end if;
-
- when others =>
- return Win32.FALSE;
-
- end case;
- return Win32.FALSE;
-
- end About;
-
-
-
- --
- -- This is the standard windows procedure which accepts and handles
- -- the various messages.
- --
- function WndProc(HWND : Win32.WinDef.HWND;
- MESSAGE : Win32.UINT;
- WPARAM : Win32.WPARAM;
- LPARAM : Win32.LPARAM) return Win32.LRESULT is
-
- use type Win32.LONG;
-
-
- WMID : Win32.WORD;
- WMEVENT : Win32.WORD;
- BRESULT : Win32.BOOL;
- LRESULT : Win32.LONG;
- PREVMIXMODE : Win32.INT;
- CURSOR : Win32.WinDef.HCURSOR;
- HELP_PTR : Win32.LPCSTR;
-
- begin
- case MESSAGE is
-
- when Win32.WinUser.WM_COMMAND =>
- WMID := Win32.Utils.LoWord(To_DWORD(WPARAM));
- WMEVENT := Win32.Utils.HiWord(To_DWORD(WPARAM));
-
- case WMID is
-
- --
- -- This message implies that the user wants to select a pcx file. Obtain the
- -- filename and begin the display.
- --
- when IDM_OPEN =>
- PCXFILENAME := File.ReadFile;
- --
- -- Change to the hourglass in the upper left corner while displaying. TL_POINT
- -- is the Top & Left corner of the client window (which is used to compute
- -- the "resting" position of the mouse while a redraw is taking place).
- -- The BR_POINT is used to save the original position of the mouse.
- --
- BRESULT := Win32.WinUser.GetWindowRect(HWND, CURSOR_RECT'access);
- TL_POINT.X := CURSOR_RECT.LEFT;
- TL_POINT.Y := CURSOR_RECT.TOP;
- BRESULT := Win32.WinUser.SetCursorPos(Win32.INT(TL_POINT.X + 10),
- Win32.INT(TL_POINT.Y + 10));
- CURSOR := Win32.WinUser.LoadCursor(
- System.Null_Address,
- Win32.LPCSTR(Win32.WinUser.IDC_WAIT));
- CURSOR := Win32.WinUser.SetCursor(CURSOR);
- PcxOps.Initial_Display(HINST, HWND, PCXFILENAME);
- CURSOR := Win32.WinUser.SetCursor(CURSOR);-- set cursor back to arrow
- FILE_DISPLAYED := TRUE;
-
- when IDM_ABOUT =>
- IRESULT := Win32.WinUser.DialogBox(HINST, CP(aboutbox),
- HWND, About'Access);
-
- when IDM_EXIT =>
- BRESULT := Win32.WinUser.DestroyWindow(HWND);
-
- --
- -- Although we could have declared the help strings as constants
- -- (for example 'aboutbox' above) , they are created at runtime for
- -- demonstration.
- --
- when IDM_HELPCONTENTS =>
- HELP_STR(0..7) := To_CA("pcx.hlp");
- HELP_PTR := CP(HELP_STR);
- BRESULT := Win32.WinUser.WinHelp(HWND,
- HELP_PTR,
- Win32.WinUser.HELP_CONTENTS,
- 0);
- if BRESULT = Win32.FALSE then
- HELP_STR(0..23) := To_CA("Unable to activate help");
- HELP_PTR := CP(HELP_STR);
- IRESULT := Win32.WinUser.MessageBox(Win32.WinUser.GetFocus,
- HELP_PTR,
- szappname,
- (Win32.WinUser.MB_SYSTEMMODAL or
- Win32.WinUser.MB_OK or
- Win32.WinUser.MB_ICONHAND));
- end if;
-
- when IDM_HELPSEARCH =>
- HELP_STR(0..7) := To_CA("pcx.hlp");
- HELP_PTR := CP(HELP_STR);
- BRESULT := Win32.WinUser.WinHelp(HWND,
- HELP_PTR,
- Win32.WinUser.HELP_PARTIALKEY,
- 0);
- if BRESULT = Win32.FALSE then
- HELP_STR(0..23) := To_CA("Unable to activate help");
- HELP_PTR := CP(HELP_STR);
- IRESULT := Win32.WinUser.MessageBox (Win32.WinUser.GetFocus,
- HELP_PTR,
- szappname,
- (Win32.WinUser.MB_SYSTEMMODAL or
- Win32.WinUser.MB_OK or
- Win32.WinUser.MB_ICONHAND));
- end if;
-
- when IDM_HELPHELP =>
- BRESULT := Win32.WinUser.WinHelp(HWND,
- null,
- Win32.WinUser.HELP_HELPONHELP,
- 0);
- if BRESULT = Win32.FALSE then
- HELP_STR(0..23) := To_CA("Unable to activate help");
- HELP_PTR := CP(HELP_STR);
- IRESULT := Win32.WinUser.MessageBox(Win32.WinUser.GetFocus,
- HELP_PTR,
- szappname,
- (Win32.WinUser.MB_SYSTEMMODAL or
- Win32.WinUser.MB_OK or
- Win32.WinUser.MB_ICONHAND));
- end if;
-
- when others =>
- return Win32.WinUser.DefWindowProc(HWND, MESSAGE, WPARAM, LPARAM);
-
- end case;
-
- when Win32.WinUser.WM_DESTROY =>
- Win32.WinUser.PostQuitMessage(0);
-
- when others =>
- return Win32.WinUser.DefWindowProc(HWND, MESSAGE, WPARAM, LPARAM);
-
- end case;
- return Win32.FALSE;
-
- end WndProc;
-
- -------------------------------------------------------------------------------
- --
- -- THIS FILE AND ANY ASSOCIATED DOCUMENTATION IS FURNISHED "AS IS" WITHOUT
- -- WARRANTY OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
- -- TO THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR
- -- PURPOSE. The user assumes the entire risk as to the accuracy and the
- -- use of this file.
- --
- -- Copyright (c) Intermetrics, Inc. 1995
- -- Royalty-free, unlimited, worldwide, non-exclusive use, modification,
- -- reproduction and further distribution of this file is permitted.
- --
- -------------------------------------------------------------------------------
-
- end AliasPkg;
-