home *** CD-ROM | disk | FTP | other *** search
- -- $Source: /home/harp/1/proto/monoBANK/winnt/generic_pkg.adb,v $
- -- $Revision: 1.2 $ $Date: 95/12/15 16:49:40 $ $Author: mg $
-
-
- with Ada.Unchecked_Conversion;
- with Interfaces.C;
- with Interfaces.C.Strings;
- with ma_extra;
-
-
- package body Generic_Pkg is
-
- use Win32;
-
- Help_Ptr : Win32.LPCSTR := CP("generic.hlp" & Nul);
- No_Help_Ptr : Win32.LPCSTR := CP("Unable to activate help" & Nul);
-
-
- function CP(C_Str : Win32.CHAR_Array) return Win32.LPCSTR is
- function UC is new Ada.Unchecked_Conversion
- (System.Address,Win32.LPCSTR);
- begin
- return UC(C_Str(C_Str'First)'Address);
- end CP;
-
-
- -- FUNCTION: CenterWindow (HWND, HWND)
- --
- -- PURPOSE: Center one window over another
- --
- -- COMMENTS:
- --
- -- Dialog boxes take on the screen position that they were designed at,
- -- which is not always appropriate. Centering the dialog over a particular
- -- window usually results in a better position.
-
- function CenterWindow(hWndChild, hWndParent : Windef.HWND) return
- Win32.BOOL is
-
- rChild_Ptr : Windef.LPRECT;
- rParent_Ptr : Windef.LPRECT;
-
- wChild : Win32.LONG;
- hChild : Win32.LONG;
- wParent : Win32.LONG;
- hParent : Win32.LONG;
- wScreen : Win32.LONG;
- hScreen : Win32.LONG;
- xNew : Win32.LONG;
- yNew : Win32.LONG;
- HDC : Windef.HDC;
-
- use type Interfaces.C.Long; -- to get '-'
-
- begin
- -- // Get the Height and Width of the child window
- rChild_Ptr := rChild'Access;
- bResult := Winuser.GetWindowRect(hWndChild, rChild_Ptr);
- wChild := rChild.RIGHT - rChild.LEFT;
- hChild := rChild.BOTTOM - rChild.TOP;
-
- -- // Get the Height and Width of the parent window
- rParent_Ptr := rParent'Access;
- bResult := Winuser.GetWindowRect(hWndParent, rParent_Ptr);
- wParent := rParent.RIGHT - rParent.LEFT;
- hParent := rParent.BOTTOM - rParent.TOP;
-
- -- // Get the display limits
- HDC := Winuser.GetDC(hWndChild);
- wScreen := Win32.LONG(Wingdi.GetDeviceCaps(HDC, Wingdi.HORZRES));
- hScreen := Win32.LONG(Wingdi.GetDeviceCaps(HDC, Wingdi.VERTRES));
- iResult := Winuser.ReleaseDC(hWndChild, HDC);
-
- -- // Calculate new X position, then adjust for screen
- xNew := rParent.LEFT + ((wParent - wChild) / 2);
- if xNew < 0 then
- xNew := 0;
- elsif (xNew + wChild) > wScreen then
- xNew := wScreen - wChild;
- end if;
-
- -- // Calculate new Y position, then adjust for screen
- yNew := rParent.TOP + ((hParent - hChild) / 2);
- if yNew < 0 then
- yNew := 0;
- elsif (yNew + hChild) > hScreen then
- yNew := hScreen - hChild;
- end if;
-
- -- // Set it, and return
- return Winuser.SetWindowPos(hWndChild,
- System.Null_Address,
- Win32.INT(xNew), Win32.INT(yNew), 0, 0,
- Winuser.SWP_NOSIZE or Winuser.SWP_NOZORDER);
- end CenterWindow;
-
-
-
- -- FUNCTION: About(HWND, UINT, WPARAM, LPARAM)
- --
- -- PURPOSE: Processes messages for "About" dialog box
- --
- -- MESSAGES:
- --
- -- WM_INITDIALOG - initialize dialog box
- -- WM_COMMAND - Input received
- --
- -- COMMENTS:
- --
- -- Display version information from the version section of the
- -- application resource.
-
- -- Wait for user to click on "Ok" button, then close the dialog box.
-
- function About(hDlg : Win32.Windef.HWND;
- MESSAGE : Win32.UINT;
- WPARAM : Win32.WPARAM;
- LPARAM : Win32.LPARAM) return Win32.BOOL is
-
- use type Interfaces.C.UNSIGNED_SHORT;
-
- cmdId : Win32.WORD;
- Dummy : Win32.BOOL;
-
- begin
- case MESSAGE is
-
- when Win32.Winuser.WM_INITDIALOG =>
- -- Center the dialog over the application window
- bResult := CenterWindow(hDlg, Win32.Winuser.GetWindow
- (hDlg, Win32.Winuser.GW_OWNER));
- return Win32.TRUE;
- -- create a font to use
-
- when Winuser.WM_COMMAND =>
- cmdId := WinDef.LOWORD(Win32.DWORD(WPARAM));
- if ((cmdId = Winuser.IDOK) or (cmdId = Winuser.IDCANCEL)) then
- Dummy := Winuser.EndDialog (hDlg, 1);
- return Win32.TRUE;
- end if;
-
- when others =>
- return Win32.FALSE;
-
- end case;
- return Win32.FALSE;
-
- end About;
-
-
-
- -- FUNCTION: WndProc(HWND, UINT, WPARAM, LPARAM)
- --
- -- PURPOSE: Processes messages
- --
- -- MESSAGES:
- --
- -- WM_COMMAND - application menu (About dialog box)
- -- WM_DESTROY - destroy window
- --
- -- COMMENTS:
- --
- -- To process the IDM_ABOUT message, call MakeProcInstance() to get the
- -- current instance address of the About() function. Then call Dialog
- -- box which will create the box according to the information in your
- -- generic.rc file and turn control over to the About() function. When
- -- it returns, free the intance address.
- --
- function WndProc (hwnd : Win32.Windef.HWND;
- message : Win32.UINT;
- wParam : Win32.WPARAM;
- lParam : Win32.LPARAM) return Win32.LRESULT is
-
- use type Interfaces.C.INT;
-
- wmID: Win32.WORD;
- wmEvent: Win32.WORD;
- begin
- case message is
- when Winuser.WM_COMMAND =>
- wmID := WinDef.LOWORD(Win32.DWORD(WPARAM));
- wmEvent := WinDef.HIWORD(Win32.DWORD(WPARAM));
-
- case wmID is
-
- when ma_extra.IDM_ABOUT =>
- iResult := Winuser.DialogBox(HINST,
- Win32.LPCSTR(WinUser.MAKEINTRESOURCE(
- ma_extra.IDD_ABOUTBOX)),
- HWND, About'Access);
-
- when ma_extra.IDM_EXIT =>
- bResult := Winuser.DestroyWindow(HWND);
-
- when ma_extra.IDM_HELPCONTENTS =>
- bResult := Winuser.WinHelp(HWND,
- Help_Ptr,
- Winuser.HELP_CONTENTS,
- 0);
- if bResult = Win32.FALSE then
- iResult := Winuser.MessageBox(Winuser.GetFocus,
- No_Help_Ptr,
- SZAPPNAME,
- (Winuser.MB_SYSTEMMODAL or
- Winuser.MB_OK or
- Winuser.MB_ICONHAND));
- end if;
-
- when ma_extra.IDM_HELPSEARCH =>
- bResult := Winuser.WinHelp(HWND,
- Help_Ptr,
- Winuser.HELP_PARTIALKEY,
- LPCSTR_To_DWORD(CP("CONTENTS" & Nul)));
- if bResult = Win32.FALSE then
- iResult := Winuser.MessageBox (Winuser.GetFocus,
- No_Help_Ptr,
- SZAPPNAME,
- (Winuser.MB_SYSTEMMODAL or
- Winuser.MB_OK or
- Winuser.MB_ICONHAND));
- end if;
-
- when ma_extra.IDM_HELPHELP =>
- bResult := Winuser.WinHelp(HWND,
- null,
- Winuser.HELP_HELPONHELP, 0);
- if bResult = Win32.FALSE then
- iResult := Winuser.MessageBox(Winuser.GetFocus,
- No_Help_Ptr,
- SZAPPNAME,
- (Winuser.MB_SYSTEMMODAL or
- Winuser.MB_OK or
- Winuser.MB_ICONHAND));
- end if;
-
- when others =>
- return Winuser.DefWindowProc(HWND, MESSAGE, WPARAM, LPARAM);
-
- end case;
-
- when Winuser.WM_DESTROY =>
- Winuser.PostQuitMessage(0);
-
- when others =>
- return Winuser.DefWindowProc(HWND, MESSAGE, WPARAM, LPARAM);
-
- end case;
- return (0);
-
- end WndProc;
-
- -------------------------------------------------------------------------------
- --
- -- THIS FILE AND ANY ASSOCIATED DOCUMENTATION IS PROVIDED "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. This file may be used only by licensees of
- -- Microsoft Corporation's WIN32 Software Development Kit in accordance with
- -- the terms of the licensee's End-User License Agreement for Microsoft
- -- Software for the WIN32 Development Kit.
- --
- -- Copyright (c) Intermetrics, Inc. 1995
- -- Portions (c) 1985-1994 Microsoft Corporation with permission.
- -- Microsoft is a registered trademark and Windows and Windows NT are
- -- trademarks of Microsoft Corporation.
- --
- -------------------------------------------------------------------------------
-
- end Generic_Pkg;
-