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

Last change on this file since 5087 was 4866, checked in by sandervl, 25 years ago

more logging, rewrote window handle management, don't export odin external functions by name

File size: 3.0 KB
Line 
1/* $Id: win32wndhandle.cpp,v 1.8 2001-01-02 18:14:59 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 tableMutex.leave(&hGlobalTableMutex);
67 return TRUE;
68}
69//******************************************************************************
70//******************************************************************************
71void HwFreeWindowHandle(HWND hwnd)
72{
73 hwnd &= WNDHANDLE_MAGIC_MASK;
74 if(hwnd < MAX_WINDOW_HANDLES) {
75 tableMutex.enter(VMUTEX_WAIT_FOREVER, &hGlobalTableMutex);
76 WindowHandleTable[hwnd] = 0;
77 tableMutex.leave(&hGlobalTableMutex);
78 }
79}
80//******************************************************************************
81//******************************************************************************
82BOOL HwGetWindowHandleData(HWND hwnd, DWORD *pdwUserData)
83{
84 if((hwnd & 0xFFFF0000) != WNDHANDLE_MAGIC_HIGHWORD) {
85 return FALSE; //unknown window (PM?)
86 }
87 hwnd &= WNDHANDLE_MAGIC_MASK;
88 if(hwnd < MAX_WINDOW_HANDLES) {
89 *pdwUserData = WindowHandleTable[hwnd];
90 return TRUE;
91 }
92 *pdwUserData = 0;
93 return FALSE;
94}
95//******************************************************************************
96//******************************************************************************
Note: See TracBrowser for help on using the repository browser.