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

Last change on this file since 8202 was 8202, checked in by sandervl, 23 years ago

changed vmutex usage

File size: 3.5 KB
Line 
1/* $Id: win32wndhandle.cpp,v 1.11 2002-04-07 14:37:00 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};
30CRITICAL_SECTION_OS2 globalwhandlecritsect = {0};
31ULONG lastIndex = 0;
32#pragma data_seg()
33
34//******************************************************************************
35//******************************************************************************
36void InitializeWindowHandles()
37{
38 if(globalwhandlecritsect.hmtxLock == 0) {
39 DosInitializeCriticalSection(&globalwhandlecritsect, WINHANDLE_CRITSECTION_NAME);
40 }
41 else {
42 dprintf(("InitializeWindowHandles -> access shared critical section"));
43 DosAccessCriticalSection(&globalwhandlecritsect, WINHANDLE_CRITSECTION_NAME);
44 }
45}
46//******************************************************************************
47//******************************************************************************
48BOOL HwAllocateWindowHandle(HWND *hwnd, DWORD dwUserData)
49{
50 DosEnterCriticalSection(&globalwhandlecritsect);
51
52 //find next free handle
53 if(lastIndex >= MAX_WINDOW_HANDLES-1) {
54 lastIndex = 0;
55 }
56 for(int i=lastIndex;i<MAX_WINDOW_HANDLES;i++) {
57 if(WindowHandleTable[i] == 0) {
58 lastIndex = i;
59 break;
60 }
61 }
62 if(i == MAX_WINDOW_HANDLES) {
63 //oops, out of handles
64 DosLeaveCriticalSection(&globalwhandlecritsect);
65 dprintf(("ERROR: USER32: HwAllocateWindowHandle OUT OF WINDOW HANDLES!!"));
66 DebugInt3();
67 return FALSE;
68 }
69 *hwnd = lastIndex;
70 *hwnd |= WNDHANDLE_MAGIC_HIGHWORD;
71 WindowHandleTable[lastIndex] = dwUserData;
72
73 lastIndex++;
74 DosLeaveCriticalSection(&globalwhandlecritsect);
75 return TRUE;
76}
77//******************************************************************************
78//******************************************************************************
79void HwFreeWindowHandle(HWND hwnd)
80{
81 hwnd &= WNDHANDLE_MAGIC_MASK;
82 if(hwnd < MAX_WINDOW_HANDLES) {
83 DosEnterCriticalSection(&globalwhandlecritsect);
84 WindowHandleTable[hwnd] = 0;
85 DosLeaveCriticalSection(&globalwhandlecritsect);
86 }
87}
88//******************************************************************************
89//******************************************************************************
90/* 2001-10-17 PH
91 * Note: this function is repeated as "inline macro" in win32wbase.cpp.
92 * Changes here must be reflected there, tool.
93 */
94BOOL HwGetWindowHandleData(HWND hwnd, DWORD *pdwUserData)
95{
96 if((hwnd & 0xFFFF0000) != WNDHANDLE_MAGIC_HIGHWORD) {
97 return FALSE; //unknown window (PM?)
98 }
99 hwnd &= WNDHANDLE_MAGIC_MASK;
100 if(hwnd < MAX_WINDOW_HANDLES) {
101 *pdwUserData = WindowHandleTable[hwnd];
102 return TRUE;
103 }
104 *pdwUserData = 0;
105 return FALSE;
106}
107//******************************************************************************
108//******************************************************************************
Note: See TracBrowser for help on using the repository browser.