2
/* ** This is part of the FreeType/2 project! ** */
3
/* A small utility to display online memory usage stats for FreeType/2 */
5
/* The method used to keep the window float on top may be completely */
6
/* stupid but I found no other way (except putting WinSetWindowPos() */
7
/* in the timer code which looks odd). */
9
/* Copyright (C) 1998 by M. Necasek */
21
/* name of shared memory used for memory usage reporting */
22
#define MEM_NAME "\\sharemem\\freetype"
24
typedef struct _INFOSTRUCT {
25
ULONG signature; /* signature (0x46524545, 'FREE') */
26
ULONG used; /* bytes actually used */
27
ULONG maxused; /* maximum amount ever used */
28
ULONG num_err; /* number of (de)allocation errors */
29
} INFOSTRUCT, *PINFOSTRUCT;
31
/* structure (in named shared memory) pointing to the above struct */
32
typedef struct _INFOPTR {
33
PINFOSTRUCT address; /* pointer to actual memory info */
43
VOID AddFloat(HWND hwndFrame) {
48
/* add Float option to system menu */
49
hwndSysMenu = WinWindowFromID(hwndFrame, FID_SYSMENU);
50
sMenuID = (SHORT)WinSendMsg(hwndSysMenu, MM_ITEMIDFROMPOSITION,
51
MPFROMSHORT(0), MPVOID);
52
WinSendMsg(hwndSysMenu, MM_QUERYITEM, MPFROMSHORT(sMenuID),
54
hwndSysSubmenu = mi.hwndSubMenu;
55
mi.iPosition = MIT_END;
56
mi.afStyle = MIS_SEPARATOR;
61
WinSendMsg(hwndSysSubmenu, MM_INSERTITEM, MPFROMP (&mi), NULL);
62
mi.afStyle = MIS_TEXT;
63
mi.afAttribute = MIA_CHECKED;
65
WinSendMsg(hwndSysSubmenu, MM_INSERTITEM, MPFROMP (&mi), "~Float on top");
68
MRESULT EXPENTRY ClientWndProc(HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2)
78
/* use smaller text */
79
WinSetPresParam(hwnd, PP_FONTNAMESIZE, 7, (PVOID)"8.Helv");
80
/* start the timer (ticks each 0.5 sec.) */
81
AddFloat(WinQueryWindow(hwnd, QW_PARENT));
82
WinStartTimer(hab, hwnd, ID_TIMER, 500);
85
/* make window always stay on top (if desired) */
88
WinSetWindowPos(hwndFrame, HWND_TOP, 0, 0, 0, 0, SWP_ZORDER);
91
case WM_COMMAND: /* why doesn't WM_SYSCOMMAND work? */
92
if (LOUSHORT(mp1) == IDM_FLOAT) {
94
WinCheckMenuItem(hwndSysSubmenu, IDM_FLOAT, bFloat);
101
WinInvalidateRect(hwnd, NULL, FALSE);
105
hps = WinBeginPaint(hwnd, NULLHANDLE, &rcl);
106
/* necessary to avoid incorrectly repainting window */
107
WinQueryWindowRect(hwnd, &rcl);
109
/* sprintf(szBuf, " Current use %dK Maximum ever used %dK Errors %d",
110
meminfo->used / 1024,
111
meminfo->maxused / 1024, meminfo->num_err);*/
112
sprintf(szBuf, " Current use %dB Maximum ever used %dK Errors %d",
114
meminfo->maxused / 1024, meminfo->num_err);
115
WinDrawText(hps, -1, szBuf, &rcl, CLR_BLACK, CLR_WHITE,
116
DT_CENTER | DT_VCENTER | DT_ERASERECT);
122
return WinDefWindowProc(hwnd, msg, mp1, mp2);
133
hmq = WinCreateMsgQueue(hab, 0);
135
/* get access to shared memory */
136
DosGetNamedSharedMem((PVOID*)&memptr, MEM_NAME, PAG_READ);
138
WinMessageBox(HWND_DESKTOP, HWND_DESKTOP,
139
" FreeType/2 is not running!",
140
"Error", 0, MB_OK | MB_ERROR);
143
meminfo = memptr->address;
144
if (meminfo->signature != 0x46524545)
145
WinMessageBox(HWND_DESKTOP, HWND_DESKTOP,
146
" FreeType/2 is not running!",
147
"Error", 0, MB_OK | MB_ERROR);
149
flFrameFlags = FCF_TITLEBAR | FCF_SYSMENU |
152
WinRegisterClass(hab, "MyClass",
153
(PFNWP) ClientWndProc,
156
hwndFrame = WinCreateStdWindow(HWND_DESKTOP,
159
"MyClass", "FreeType/2 Heap Usage",
163
WinSetVisibleRegionNotify(hwndClient, TRUE);
165
/* make titlebar text look better */
166
WinSetPresParam(WinWindowFromID(hwndFrame, FID_TITLEBAR),
167
PP_FONTNAMESIZE, 9, (PVOID)"8.Helv");
169
WinSetWindowPos(hwndFrame, NULLHANDLE, 0, 0, 350, 42,
170
SWP_MOVE | SWP_SIZE | SWP_SHOW);
172
while (WinGetMsg(hab, &qmsg, (HWND) NULL, 0, 0))
173
WinDispatchMsg(hab, &qmsg);
175
WinSetVisibleRegionNotify(hwndClient, FALSE);
178
/* free shared memory block */
181
WinDestroyWindow(hwndFrame);
182
WinDestroyMsgQueue(hmq);