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

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

* empty log message *

File size: 2.6 KB
Line 
1/* $Id: win32wndhandle.cpp,v 1.4 2000-01-18 20:11:03 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//******************************************************************************
23
24//Global DLL Data
25#pragma data_seg(_GLOBALDATA)
26ULONG WindowHandleTable[MAX_WINDOW_HANDLES] = {0};
27VMutex tableMutex(TRUE);
28ULONG lowestFreeIndex = 0;
29#pragma data_seg()
30
31//******************************************************************************
32//******************************************************************************
33BOOL HwAllocateWindowHandle(HWND *hwnd, DWORD dwUserData)
34{
35 tableMutex.enter();
36 if(lowestFreeIndex == -1) {
37 //oops, out of handles
38 dprintf(("USER32: HwAllocateWindowHandle OUT OF WINDOW HANDLES!!"));
39 DebugInt3();
40 tableMutex.leave();
41 return FALSE;
42 }
43 *hwnd = lowestFreeIndex;
44 *hwnd |= WNDHANDLE_MAGIC_HIGHWORD;
45 WindowHandleTable[lowestFreeIndex] = dwUserData;
46
47 lowestFreeIndex = -1;
48
49 //find next free handle
50 for(int i=0;i<MAX_WINDOW_HANDLES;i++) {
51 if(WindowHandleTable[i] == 0) {
52 lowestFreeIndex = i;
53 break;
54 }
55 }
56 tableMutex.leave();
57 return TRUE;
58}
59//******************************************************************************
60//******************************************************************************
61void HwFreeWindowHandle(HWND hwnd)
62{
63 hwnd &= WNDHANDLE_MAGIC_MASK;
64 if(hwnd < MAX_WINDOW_HANDLES) {
65 tableMutex.enter();
66 WindowHandleTable[hwnd] = 0;
67 if(lowestFreeIndex == -1 || hwnd < lowestFreeIndex)
68 lowestFreeIndex = hwnd;
69
70 tableMutex.leave();
71 }
72}
73//******************************************************************************
74//******************************************************************************
75BOOL HwGetWindowHandleData(HWND hwnd, DWORD *pdwUserData)
76{
77 if((hwnd & 0xFFFF0000) != WNDHANDLE_MAGIC_HIGHWORD) {
78 return FALSE; //unknown window (PM?)
79 }
80 hwnd &= WNDHANDLE_MAGIC_MASK;
81 if(hwnd < MAX_WINDOW_HANDLES) {
82 *pdwUserData = WindowHandleTable[hwnd];
83 return TRUE;
84 }
85 *pdwUserData = 0;
86 return FALSE;
87}
88//******************************************************************************
89//******************************************************************************
Note: See TracBrowser for help on using the repository browser.