1 | /* pmapp.cc
|
---|
2 | Copyright (c) 1996 Eberhard Mattes
|
---|
3 |
|
---|
4 | This file is part of pmgdb.
|
---|
5 |
|
---|
6 | pmgdb is free software; you can redistribute it and/or modify
|
---|
7 | it under the terms of the GNU General Public License as published by
|
---|
8 | the Free Software Foundation; either version 2, or (at your option)
|
---|
9 | any later version.
|
---|
10 |
|
---|
11 | pmgdb is distributed in the hope that it will be useful,
|
---|
12 | but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
14 | GNU General Public License for more details.
|
---|
15 |
|
---|
16 | You should have received a copy of the GNU General Public License
|
---|
17 | along with pmgdb; see the file COPYING. If not, write to
|
---|
18 | the Free Software Foundation, 59 Temple Place - Suite 330,
|
---|
19 | Boston, MA 02111-1307, USA. */
|
---|
20 |
|
---|
21 |
|
---|
22 | #define INCL_DOS
|
---|
23 | #define INCL_WIN
|
---|
24 | #include <os2.h>
|
---|
25 | #include <stdlib.h>
|
---|
26 | #include <string.h>
|
---|
27 | #include "string.h"
|
---|
28 | #include "pmapp.h"
|
---|
29 |
|
---|
30 |
|
---|
31 | pmapp::pmapp (const char *in_name)
|
---|
32 | {
|
---|
33 | name = in_name;
|
---|
34 | hab = WinInitialize (0);
|
---|
35 | hmq = WinCreateMsgQueue (hab, 0);
|
---|
36 | WinQueryWindowPos (HWND_DESKTOP, &swpScreen);
|
---|
37 | }
|
---|
38 |
|
---|
39 |
|
---|
40 | pmapp::~pmapp ()
|
---|
41 | {
|
---|
42 | WinDestroyMsgQueue (hmq);
|
---|
43 | WinTerminate (hab);
|
---|
44 | }
|
---|
45 |
|
---|
46 |
|
---|
47 | void pmapp::no_message_loop () const
|
---|
48 | {
|
---|
49 | WinCancelShutdown (hmq, TRUE);
|
---|
50 | }
|
---|
51 |
|
---|
52 |
|
---|
53 | void pmapp::message_loop () const
|
---|
54 | {
|
---|
55 | QMSG qmsg;
|
---|
56 |
|
---|
57 | while (WinGetMsg (hab, &qmsg, 0, 0, 0))
|
---|
58 | WinDispatchMsg (hab, &qmsg);
|
---|
59 | }
|
---|
60 |
|
---|
61 |
|
---|
62 | void pmapp::win_error () const
|
---|
63 | {
|
---|
64 | // TODO: Make thread-safe
|
---|
65 | static char buf[] = "WinGetLastError: 0x????????";
|
---|
66 |
|
---|
67 | ERRORID eid = WinGetLastError (hab);
|
---|
68 | unsigned err = ERRORIDERROR (eid);
|
---|
69 | _ltoa ((long)err, strchr (buf, 'x') + 1, 16);
|
---|
70 | if (WinMessageBox (HWND_DESKTOP, HWND_DESKTOP, (PSZ)buf, (PCSZ)name, 0,
|
---|
71 | MB_MOVEABLE | MB_OK | MB_ICONEXCLAMATION) == MBID_ERROR)
|
---|
72 | DosBeep (440, 500);
|
---|
73 | }
|
---|
74 |
|
---|
75 |
|
---|
76 | /* Remove all unwanted items from the system menu of a dialog box, as
|
---|
77 | required by SAA CUA '89. */
|
---|
78 |
|
---|
79 | void dlg_sys_menu (HWND hwnd)
|
---|
80 | {
|
---|
81 | HWND hwndSysMenu;
|
---|
82 | MENUITEM mi;
|
---|
83 | MRESULT mr;
|
---|
84 | int i, n, id;
|
---|
85 |
|
---|
86 | /* Get the window handle of the system menu. */
|
---|
87 |
|
---|
88 | hwndSysMenu = WinWindowFromID (hwnd, FID_SYSMENU);
|
---|
89 | if (hwndSysMenu == NULLHANDLE)
|
---|
90 | return;
|
---|
91 |
|
---|
92 | /* Well, actually the system menu proper is a submenu of the menu we
|
---|
93 | just got. */
|
---|
94 |
|
---|
95 | mr = WinSendMsg (hwndSysMenu, MM_QUERYITEM,
|
---|
96 | MPFROM2SHORT (SC_SYSMENU, FALSE), (MPARAM)&mi);
|
---|
97 | if (!SHORT1FROMMR (mr))
|
---|
98 | return;
|
---|
99 | hwndSysMenu = mi.hwndSubMenu;
|
---|
100 | if (hwndSysMenu == NULLHANDLE)
|
---|
101 | return;
|
---|
102 |
|
---|
103 | /* Delete all the unwanted menu items. */
|
---|
104 |
|
---|
105 | WinSendMsg (hwndSysMenu, MM_DELETEITEM,
|
---|
106 | MPFROM2SHORT (SC_MINIMIZE, FALSE), 0);
|
---|
107 | WinSendMsg (hwndSysMenu, MM_DELETEITEM,
|
---|
108 | MPFROM2SHORT (SC_MAXIMIZE, FALSE), 0);
|
---|
109 | WinSendMsg (hwndSysMenu, MM_DELETEITEM,
|
---|
110 | MPFROM2SHORT (SC_SIZE, FALSE), 0);
|
---|
111 | WinSendMsg (hwndSysMenu, MM_DELETEITEM,
|
---|
112 | MPFROM2SHORT (SC_RESTORE, FALSE), 0);
|
---|
113 | WinSendMsg (hwndSysMenu, MM_DELETEITEM,
|
---|
114 | MPFROM2SHORT (SC_TASKMANAGER, FALSE), 0);
|
---|
115 | WinSendMsg (hwndSysMenu, MM_DELETEITEM,
|
---|
116 | MPFROM2SHORT (SC_HIDE, FALSE), 0);
|
---|
117 |
|
---|
118 | /* Deleting menu items may leave two or more successive separator
|
---|
119 | lines. Now we remove all the separator lines. */
|
---|
120 |
|
---|
121 | redo:
|
---|
122 |
|
---|
123 | /* Get the number of menu items. */
|
---|
124 |
|
---|
125 | mr = WinSendMsg (hwndSysMenu, MM_QUERYITEMCOUNT, 0, 0);
|
---|
126 | n = SHORT1FROMMR (mr);
|
---|
127 |
|
---|
128 | /* Find the first one which is a separator line. */
|
---|
129 |
|
---|
130 | for (i = 0; i < n; ++i)
|
---|
131 | {
|
---|
132 | mr = WinSendMsg (hwndSysMenu, MM_ITEMIDFROMPOSITION, MPFROMSHORT (i), 0);
|
---|
133 | id = SHORT1FROMMR (mr);
|
---|
134 | if (id != MID_ERROR)
|
---|
135 | {
|
---|
136 | mr = WinSendMsg (hwndSysMenu, MM_QUERYITEM,
|
---|
137 | MPFROM2SHORT (id, FALSE), (MPARAM)&mi);
|
---|
138 | if (SHORT1FROMMR (mr) && (mi.afStyle & MIS_SEPARATOR))
|
---|
139 | {
|
---|
140 | /* We found a separator line. Delete that menu item. */
|
---|
141 |
|
---|
142 | WinSendMsg (hwndSysMenu, MM_DELETEITEM,
|
---|
143 | MPFROM2SHORT (id, FALSE), 0);
|
---|
144 |
|
---|
145 | /* Restart the loop as the menu items have been
|
---|
146 | renumbered. */
|
---|
147 |
|
---|
148 | goto redo;
|
---|
149 | }
|
---|
150 | }
|
---|
151 | }
|
---|
152 |
|
---|
153 | /* Now there's no separator line left. */
|
---|
154 | }
|
---|