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

Last change on this file since 6496 was 5685, checked in by sandervl, 24 years ago

client/frame rewrite

File size: 3.0 KB
Line 
1/* $Id: win32wndhandle.cpp,v 1.9 2001-05-11 08:39:46 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//NOTE: This must be in the local data segment -> if a shared semaphore was
28// created by a different process, the handle returned by DosOpenMutexSem
29// will be returned in hGlobalTableMutex
30HMTX hGlobalTableMutex = 0;
31
32//Global DLL Data
33#pragma data_seg(_GLOBALDATA)
34ULONG WindowHandleTable[MAX_WINDOW_HANDLES] = {0};
35VMutex tableMutex(VMUTEX_SHARED, &hGlobalTableMutex);
36ULONG lastIndex = 0;
37#pragma data_seg()
38
39//******************************************************************************
40//******************************************************************************
41BOOL HwAllocateWindowHandle(HWND *hwnd, DWORD dwUserData)
42{
43 tableMutex.enter(VMUTEX_WAIT_FOREVER, &hGlobalTableMutex);
44
45 //find next free handle
46 if(lastIndex >= MAX_WINDOW_HANDLES-1) {
47 lastIndex = 0;
48 }
49 for(int i=lastIndex;i<MAX_WINDOW_HANDLES;i++) {
50 if(WindowHandleTable[i] == 0) {
51 lastIndex = i;
52 break;
53 }
54 }
55 if(i == MAX_WINDOW_HANDLES) {
56 //oops, out of handles
57 tableMutex.leave(&hGlobalTableMutex);
58 dprintf(("ERROR: USER32: HwAllocateWindowHandle OUT OF WINDOW HANDLES!!"));
59 DebugInt3();
60 return FALSE;
61 }
62 *hwnd = lastIndex;
63 *hwnd |= WNDHANDLE_MAGIC_HIGHWORD;
64 WindowHandleTable[lastIndex] = dwUserData;
65
66 lastIndex++;
67 tableMutex.leave(&hGlobalTableMutex);
68 return TRUE;
69}
70//******************************************************************************
71//******************************************************************************
72void HwFreeWindowHandle(HWND hwnd)
73{
74 hwnd &= WNDHANDLE_MAGIC_MASK;
75 if(hwnd < MAX_WINDOW_HANDLES) {
76 tableMutex.enter(VMUTEX_WAIT_FOREVER, &hGlobalTableMutex);
77 WindowHandleTable[hwnd] = 0;
78 tableMutex.leave(&hGlobalTableMutex);
79 }
80}
81//******************************************************************************
82//******************************************************************************
83BOOL HwGetWindowHandleData(HWND hwnd, DWORD *pdwUserData)
84{
85 if((hwnd & 0xFFFF0000) != WNDHANDLE_MAGIC_HIGHWORD) {
86 return FALSE; //unknown window (PM?)
87 }
88 hwnd &= WNDHANDLE_MAGIC_MASK;
89 if(hwnd < MAX_WINDOW_HANDLES) {
90 *pdwUserData = WindowHandleTable[hwnd];
91 return TRUE;
92 }
93 *pdwUserData = 0;
94 return FALSE;
95}
96//******************************************************************************
97//******************************************************************************
Note: See TracBrowser for help on using the repository browser.