source: trunk/src/user32/win32wndhandle.cpp@ 2803

Last change on this file since 2803 was 2803, checked in by sandervl, 26 years ago

Added new logging feature

File size: 2.7 KB
Line 
1/* $Id: win32wndhandle.cpp,v 1.5 2000-02-16 14:28:25 sandervl Exp $ */
2/*
3 * Win32 Handle Management Code for OS/2
4 *
5 *
6 * Copyright 1998 Sander van Leeuwen (sandervl@xs4all.nl)
7 *
8 *
9 * TODO: The table should be dynamically increased when necessary
10 * This is just a quick and dirty implementation
11 * TODO: Probably need to clean up the table when app closes
12 * (also store PID and remove all handles with PID of terminating app)
13 *
14 * Project Odin Software License can be found in LICENSE.TXT
15 *
16 */
17
18#include <os2win.h>
19#include <vmutex.h>
20#include "win32wndhandle.h"
21
22#define DBG_LOCALLOG DBG_win32wndhandle
23#include "dbglocal.h"
24
25//******************************************************************************
26
27//Global DLL Data
28#pragma data_seg(_GLOBALDATA)
29ULONG WindowHandleTable[MAX_WINDOW_HANDLES] = {0};
30VMutex tableMutex(TRUE);
31ULONG lowestFreeIndex = 0;
32#pragma data_seg()
33
34//******************************************************************************
35//******************************************************************************
36BOOL HwAllocateWindowHandle(HWND *hwnd, DWORD dwUserData)
37{
38 tableMutex.enter();
39 if(lowestFreeIndex == -1) {
40 //oops, out of handles
41 dprintf(("USER32: HwAllocateWindowHandle OUT OF WINDOW HANDLES!!"));
42 DebugInt3();
43 tableMutex.leave();
44 return FALSE;
45 }
46 *hwnd = lowestFreeIndex;
47 *hwnd |= WNDHANDLE_MAGIC_HIGHWORD;
48 WindowHandleTable[lowestFreeIndex] = dwUserData;
49
50 lowestFreeIndex = -1;
51
52 //find next free handle
53 for(int i=0;i<MAX_WINDOW_HANDLES;i++) {
54 if(WindowHandleTable[i] == 0) {
55 lowestFreeIndex = i;
56 break;
57 }
58 }
59 tableMutex.leave();
60 return TRUE;
61}
62//******************************************************************************
63//******************************************************************************
64void HwFreeWindowHandle(HWND hwnd)
65{
66 hwnd &= WNDHANDLE_MAGIC_MASK;
67 if(hwnd < MAX_WINDOW_HANDLES) {
68 tableMutex.enter();
69 WindowHandleTable[hwnd] = 0;
70 if(lowestFreeIndex == -1 || hwnd < lowestFreeIndex)
71 lowestFreeIndex = hwnd;
72
73 tableMutex.leave();
74 }
75}
76//******************************************************************************
77//******************************************************************************
78BOOL HwGetWindowHandleData(HWND hwnd, DWORD *pdwUserData)
79{
80 if((hwnd & 0xFFFF0000) != WNDHANDLE_MAGIC_HIGHWORD) {
81 return FALSE; //unknown window (PM?)
82 }
83 hwnd &= WNDHANDLE_MAGIC_MASK;
84 if(hwnd < MAX_WINDOW_HANDLES) {
85 *pdwUserData = WindowHandleTable[hwnd];
86 return TRUE;
87 }
88 *pdwUserData = 0;
89 return FALSE;
90}
91//******************************************************************************
92//******************************************************************************
Note: See TracBrowser for help on using the repository browser.