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

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

fixed double handle allocated for desktop window + made EnumWindows a bit safer

File size: 3.5 KB
Line 
1/* $Id: win32wndhandle.cpp,v 1.12 2002-04-07 21:37:35 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 dprintf2(("HwAllocateWindowHandle %x", *hwnd));
76 return TRUE;
77}
78//******************************************************************************
79//******************************************************************************
80void HwFreeWindowHandle(HWND hwnd)
81{
82 hwnd &= WNDHANDLE_MAGIC_MASK;
83 if(hwnd < MAX_WINDOW_HANDLES) {
84 DosEnterCriticalSection(&globalwhandlecritsect);
85 WindowHandleTable[hwnd] = 0;
86 DosLeaveCriticalSection(&globalwhandlecritsect);
87 }
88 dprintf2(("HwFreeWindowHandle %x", hwnd));
89}
90//******************************************************************************
91//******************************************************************************
92/* 2001-10-17 PH
93 * Note: this function is repeated as "inline macro" in win32wbase.cpp.
94 * Changes here must be reflected there, tool.
95 */
96BOOL HwGetWindowHandleData(HWND hwnd, DWORD *pdwUserData)
97{
98 if((hwnd & 0xFFFF0000) != WNDHANDLE_MAGIC_HIGHWORD) {
99 return FALSE; //unknown window (PM?)
100 }
101 hwnd &= WNDHANDLE_MAGIC_MASK;
102 if(hwnd < MAX_WINDOW_HANDLES) {
103 *pdwUserData = WindowHandleTable[hwnd];
104 return TRUE;
105 }
106 *pdwUserData = 0;
107 return FALSE;
108}
109//******************************************************************************
110//******************************************************************************
Note: See TracBrowser for help on using the repository browser.