The message handler of WM_STYLECHANGING is supposed to be able to
[wine] / windows / dce.c
1 /*
2  * USER DCE functions
3  *
4  * Copyright 1993 Alexandre Julliard
5  *           1996,1997 Alex Korobka
6  *
7  *
8  * Note: Visible regions of CS_OWNDC/CS_CLASSDC window DCs 
9  * have to be updated dynamically. 
10  * 
11  * Internal DCX flags:
12  *
13  * DCX_DCEEMPTY    - dce is uninitialized
14  * DCX_DCEBUSY     - dce is in use
15  * DCX_DCEDIRTY    - ReleaseDC() should wipe instead of caching
16  * DCX_KEEPCLIPRGN - ReleaseDC() should not delete the clipping region
17  * DCX_WINDOWPAINT - BeginPaint() is in effect
18  */
19
20 #include <assert.h>
21 #include "dce.h"
22 #include "win.h"
23 #include "gdi.h"
24 #include "region.h"
25 #include "user.h"
26 #include "debugtools.h"
27 #include "windef.h"
28 #include "wingdi.h"
29 #include "wine/winbase16.h"
30 #include "wine/winuser16.h"
31
32 DEFAULT_DEBUG_CHANNEL(dc);
33
34 static DCE *firstDCE;
35 static HDC defaultDCstate;
36
37 static void DCE_DeleteClipRgn( DCE* );
38 static INT DCE_ReleaseDC( DCE* );
39
40
41 /***********************************************************************
42  *           DCE_DumpCache
43  */
44 static void DCE_DumpCache(void)
45 {
46     DCE *dce;
47     
48     USER_Lock();
49     dce = firstDCE;
50     
51     DPRINTF("DCE:\n");
52     while( dce )
53     {
54         DPRINTF("\t[0x%08x] hWnd 0x%04x, dcx %08x, %s %s\n",
55              (unsigned)dce, dce->hwndCurrent, (unsigned)dce->DCXflags, 
56              (dce->DCXflags & DCX_CACHE) ? "Cache" : "Owned", 
57              (dce->DCXflags & DCX_DCEBUSY) ? "InUse" : "" );
58         dce = dce->next;
59     }
60
61     USER_Unlock();
62 }
63
64 /***********************************************************************
65  *           DCE_AllocDCE
66  *
67  * Allocate a new DCE.
68  */
69 DCE *DCE_AllocDCE( HWND hWnd, DCE_TYPE type )
70 {
71     FARPROC16 hookProc;
72     DCE * dce;
73     WND* wnd;
74     
75     if (!(dce = HeapAlloc( GetProcessHeap(), 0, sizeof(DCE) ))) return NULL;
76     if (!(dce->hDC = CreateDCA( "DISPLAY", NULL, NULL, NULL )))
77     {
78         HeapFree( GetProcessHeap(), 0, dce );
79         return 0;
80     }
81     if (!defaultDCstate) defaultDCstate = GetDCState16( dce->hDC );
82
83     wnd = WIN_FindWndPtr(hWnd);
84     
85     /* store DCE handle in DC hook data field */
86
87     hookProc = GetProcAddress16( GetModuleHandle16("USER"), (LPCSTR)362 );
88     SetDCHook( dce->hDC, hookProc, (DWORD)dce );
89
90     dce->hwndCurrent = hWnd;
91     dce->hClipRgn    = 0;
92     dce->next        = firstDCE;
93     firstDCE = dce;
94
95     if( type != DCE_CACHE_DC ) /* owned or class DC */
96     {
97         dce->DCXflags = DCX_DCEBUSY;
98         if( hWnd )
99         {
100             if( wnd->dwStyle & WS_CLIPCHILDREN ) dce->DCXflags |= DCX_CLIPCHILDREN;
101             if( wnd->dwStyle & WS_CLIPSIBLINGS ) dce->DCXflags |= DCX_CLIPSIBLINGS;
102         }
103         SetHookFlags16(dce->hDC,DCHF_INVALIDATEVISRGN);
104     }
105     else dce->DCXflags = DCX_CACHE | DCX_DCEEMPTY;
106
107     WIN_ReleaseWndPtr(wnd);
108     
109     return dce;
110 }
111
112
113 /***********************************************************************
114  *           DCE_FreeDCE
115  */
116 DCE* DCE_FreeDCE( DCE *dce )
117 {
118     DCE **ppDCE;
119
120     if (!dce) return NULL;
121
122     USER_Lock();
123
124     ppDCE = &firstDCE;
125
126     while (*ppDCE && (*ppDCE != dce)) ppDCE = &(*ppDCE)->next;
127     if (*ppDCE == dce) *ppDCE = dce->next;
128
129     SetDCHook(dce->hDC, NULL, 0L);
130
131     DeleteDC( dce->hDC );
132     if( dce->hClipRgn && !(dce->DCXflags & DCX_KEEPCLIPRGN) )
133         DeleteObject(dce->hClipRgn);
134     HeapFree( GetProcessHeap(), 0, dce );
135
136     USER_Unlock();
137     
138     return *ppDCE;
139 }
140
141 /***********************************************************************
142  *           DCE_FreeWindowDCE
143  *
144  * Remove owned DCE and reset unreleased cache DCEs.
145  */
146 void DCE_FreeWindowDCE( HWND hwnd )
147 {
148     DCE *pDCE;
149
150     USER_Lock();
151     pDCE = firstDCE;
152
153     while( pDCE )
154     {
155         if( pDCE->hwndCurrent == hwnd )
156         {
157             WND *pWnd = WIN_FindWndPtr( hwnd );
158             if( pDCE == pWnd->dce ) /* owned or Class DCE*/
159             {
160                 if (pWnd->clsStyle & CS_OWNDC)  /* owned DCE*/
161                 {
162                     pDCE = DCE_FreeDCE( pDCE );
163                     pWnd->dce = NULL;
164                     WIN_ReleaseWndPtr( pWnd );
165                     continue;
166                 }
167                 else if( pDCE->DCXflags & (DCX_INTERSECTRGN | DCX_EXCLUDERGN) ) /* Class DCE*/
168                 {
169                     DCE_DeleteClipRgn( pDCE );
170                     pDCE->hwndCurrent = 0;
171                 }
172             }
173             else
174             {
175                 if( pDCE->DCXflags & DCX_DCEBUSY ) /* shared cache DCE */
176                 {
177                     /* FIXME: AFAICS we are doing the right thing here so 
178                      * this should be a WARN. But this is best left as an ERR 
179                      * because the 'application error' is likely to come from 
180                      * another part of Wine (i.e. it's our fault after all). 
181                      * We should change this to WARN when Wine is more stable
182                      * (for 1.0?).
183                      */
184                     ERR("[%04x] GetDC() without ReleaseDC()!\n", 
185                         pWnd->hwndSelf);
186                     DCE_ReleaseDC( pDCE );
187                 }
188
189                 pDCE->DCXflags &= DCX_CACHE;
190                 pDCE->DCXflags |= DCX_DCEEMPTY;
191                 pDCE->hwndCurrent = 0;
192             }
193             WIN_ReleaseWndPtr( pWnd );
194         }
195         pDCE = pDCE->next;
196     }
197     
198     USER_Unlock();
199 }
200
201
202 /***********************************************************************
203  *   DCE_DeleteClipRgn
204  */
205 static void DCE_DeleteClipRgn( DCE* dce )
206 {
207     dce->DCXflags &= ~(DCX_EXCLUDERGN | DCX_INTERSECTRGN | DCX_WINDOWPAINT);
208
209     if( dce->DCXflags & DCX_KEEPCLIPRGN )
210         dce->DCXflags &= ~DCX_KEEPCLIPRGN;
211     else
212         if( dce->hClipRgn > 1 )
213             DeleteObject( dce->hClipRgn );
214
215     dce->hClipRgn = 0;
216
217     /* make it dirty so that the vis rgn gets recomputed next time */
218     dce->DCXflags |= DCX_DCEDIRTY;
219     SetHookFlags16( dce->hDC, DCHF_INVALIDATEVISRGN );
220 }
221
222
223 /***********************************************************************
224  *   DCE_ReleaseDC
225  */
226 static INT DCE_ReleaseDC( DCE* dce )
227 {
228     if ((dce->DCXflags & (DCX_DCEEMPTY | DCX_DCEBUSY)) != DCX_DCEBUSY) return 0;
229
230     /* restore previous visible region */
231
232     if ((dce->DCXflags & (DCX_INTERSECTRGN | DCX_EXCLUDERGN)) &&
233         (dce->DCXflags & (DCX_CACHE | DCX_WINDOWPAINT)) )
234         DCE_DeleteClipRgn( dce );
235
236     if (dce->DCXflags & DCX_CACHE)
237     {
238         SetDCState16( dce->hDC, defaultDCstate );
239         dce->DCXflags &= ~DCX_DCEBUSY;
240         if (dce->DCXflags & DCX_DCEDIRTY)
241         {
242             /* don't keep around invalidated entries 
243              * because SetDCState() disables hVisRgn updates
244              * by removing dirty bit. */
245
246             dce->hwndCurrent = 0;
247             dce->DCXflags &= DCX_CACHE;
248             dce->DCXflags |= DCX_DCEEMPTY;
249         }
250     }
251     return 1;
252 }
253
254
255 /***********************************************************************
256  *   DCE_InvalidateDCE
257  *
258  * It is called from SetWindowPos() and EVENT_MapNotify - we have to
259  * mark as dirty all busy DCEs for windows that have pWnd->parent as
260  * an ancestor and whose client rect intersects with specified update
261  * rectangle. In addition, pWnd->parent DCEs may need to be updated if
262  * DCX_CLIPCHILDREN flag is set.  */
263 BOOL DCE_InvalidateDCE(HWND hwnd, const RECT* pRectUpdate)
264 {
265     HWND hwndScope = GetAncestor( hwnd, GA_PARENT );
266     BOOL bRet = FALSE;
267
268     if( hwndScope )
269     {
270         DCE *dce;
271
272         TRACE("scope hwnd = %04x, (%i,%i - %i,%i)\n",
273                      hwndScope, pRectUpdate->left,pRectUpdate->top,
274                      pRectUpdate->right,pRectUpdate->bottom);
275         if(TRACE_ON(dc)) 
276           DCE_DumpCache();
277
278         /* walk all DCEs and fixup non-empty entries */
279
280         for (dce = firstDCE; (dce); dce = dce->next)
281         {
282             WND* wndCurrent;
283             HWND tmp;
284             INT xoffset = 0, yoffset = 0;
285
286             if (dce->DCXflags & DCX_DCEEMPTY) continue;
287             if ((dce->hwndCurrent == hwndScope) && !(dce->DCXflags & DCX_CLIPCHILDREN))
288                 continue;  /* child window positions don't bother us */
289             if (!(wndCurrent = WIN_FindWndPtr(dce->hwndCurrent))) continue;
290
291             /* check if DCE window is within the z-order scope */
292
293             for (tmp = dce->hwndCurrent; tmp; tmp = GetAncestor( tmp, GA_PARENT ))
294             {
295                 if (tmp == hwndScope )
296                 {
297                     RECT wndRect;
298
299                     wndRect = wndCurrent->rectWindow;
300
301                     OffsetRect( &wndRect, xoffset - wndCurrent->rectClient.left, 
302                                 yoffset - wndCurrent->rectClient.top);
303
304                     if (hwnd == wndCurrent->hwndSelf ||
305                         IntersectRect( &wndRect, &wndRect, pRectUpdate ))
306                     { 
307                         if( !(dce->DCXflags & DCX_DCEBUSY) )
308                         {
309                             /* Don't bother with visible regions of unused DCEs */
310
311                             TRACE("\tpurged %08x dce [%04x]\n", 
312                                   (unsigned)dce, wndCurrent->hwndSelf);
313
314                             dce->hwndCurrent = 0;
315                             dce->DCXflags &= DCX_CACHE;
316                             dce->DCXflags |= DCX_DCEEMPTY;
317                         }
318                         else
319                         {
320                             /* Set dirty bits in the hDC and DCE structs */
321
322                             TRACE("\tfixed up %08x dce [%04x]\n", 
323                                   (unsigned)dce, wndCurrent->hwndSelf);
324
325                             dce->DCXflags |= DCX_DCEDIRTY;
326                             SetHookFlags16(dce->hDC, DCHF_INVALIDATEVISRGN);
327                             bRet = TRUE;
328                         }
329                     }
330                     break;
331                 }
332                 else
333                 {
334                     WND* wnd = WIN_FindWndPtr( tmp );
335                     xoffset += wnd->rectClient.left;
336                     yoffset += wnd->rectClient.top;
337                     WIN_ReleaseWndPtr( wnd );
338                 }
339             }
340             WIN_ReleaseWndPtr(wndCurrent);
341         } /* dce list */
342     }
343     return bRet;
344 }
345
346
347 /***********************************************************************
348  *           DCE_ExcludeRgn
349  * 
350  *  Translate given region from the wnd client to the DC coordinates
351  *  and add it to the clipping region.
352  */
353 INT DCE_ExcludeRgn( HDC hDC, HWND hwnd, HRGN hRgn )
354 {
355   POINT  pt = {0, 0};
356   DCE     *dce = firstDCE;
357
358   while (dce && (dce->hDC != hDC)) dce = dce->next;
359   if (!dce) return ERROR;
360
361   MapWindowPoints( hwnd, dce->hwndCurrent, &pt, 1);
362   if( dce->DCXflags & DCX_WINDOW )
363   {
364       WND *wnd = WIN_FindWndPtr(dce->hwndCurrent);
365       pt.x += wnd->rectClient.left - wnd->rectWindow.left;
366       pt.y += wnd->rectClient.top - wnd->rectWindow.top;
367       WIN_ReleaseWndPtr(wnd);
368   }
369   OffsetRgn(hRgn, pt.x, pt.y);
370
371   return ExtSelectClipRgn( hDC, hRgn, RGN_DIFF );
372 }
373
374
375 /***********************************************************************
376  *              GetDCEx (USER.359)
377  */
378 HDC16 WINAPI GetDCEx16( HWND16 hwnd, HRGN16 hrgnClip, DWORD flags )
379 {
380     return (HDC16)GetDCEx( hwnd, hrgnClip, flags );
381 }
382
383
384 /***********************************************************************
385  *              GetDCEx (USER32.@)
386  *
387  * Unimplemented flags: DCX_LOCKWINDOWUPDATE
388  *
389  * FIXME: Full support for hrgnClip == 1 (alias for entire window).
390  */
391 HDC WINAPI GetDCEx( HWND hwnd, HRGN hrgnClip, DWORD flags )
392 {
393     HDC         hdc = 0;
394     DCE *       dce;
395     WND *       wndPtr;
396     DWORD       dcxFlags = 0;
397     BOOL        bUpdateVisRgn = TRUE;
398     BOOL        bUpdateClipOrigin = FALSE;
399     HWND parent;
400
401     TRACE("hwnd %04x, hrgnClip %04x, flags %08x\n", 
402           hwnd, hrgnClip, (unsigned)flags);
403
404     if (!hwnd) hwnd = GetDesktopWindow();
405     if (!(wndPtr = WIN_FindWndPtr( hwnd ))) return 0;
406
407     /* fixup flags */
408
409     if (flags & (DCX_WINDOW | DCX_PARENTCLIP)) flags |= DCX_CACHE;
410
411     if (flags & DCX_USESTYLE)
412     {
413         flags &= ~( DCX_CLIPCHILDREN | DCX_CLIPSIBLINGS | DCX_PARENTCLIP);
414
415         if( wndPtr->dwStyle & WS_CLIPSIBLINGS )
416             flags |= DCX_CLIPSIBLINGS;
417
418         if ( !(flags & DCX_WINDOW) )
419         {
420             if (wndPtr->clsStyle & CS_PARENTDC) flags |= DCX_PARENTCLIP;
421
422             if (wndPtr->dwStyle & WS_CLIPCHILDREN &&
423                      !(wndPtr->dwStyle & WS_MINIMIZE) ) flags |= DCX_CLIPCHILDREN;
424             if (!wndPtr->dce) flags |= DCX_CACHE;
425         }
426     }
427
428     if (flags & DCX_WINDOW) flags &= ~DCX_CLIPCHILDREN;
429
430     parent = GetAncestor( hwnd, GA_PARENT );
431     if (!parent || (parent == GetDesktopWindow()))
432         flags = (flags & ~DCX_PARENTCLIP) | DCX_CLIPSIBLINGS;
433
434     /* it seems parent clip is ignored when clipping siblings or children */
435     if (flags & (DCX_CLIPSIBLINGS | DCX_CLIPCHILDREN)) flags &= ~DCX_PARENTCLIP;
436
437     if( flags & DCX_PARENTCLIP )
438     {
439         LONG parent_style = GetWindowLongW( parent, GWL_STYLE );
440         if( (wndPtr->dwStyle & WS_VISIBLE) && (parent_style & WS_VISIBLE) )
441         {
442             flags &= ~DCX_CLIPCHILDREN;
443             if (parent_style & WS_CLIPSIBLINGS) flags |= DCX_CLIPSIBLINGS;
444         }
445     }
446
447     /* find a suitable DCE */
448
449     dcxFlags = flags & (DCX_PARENTCLIP | DCX_CLIPSIBLINGS | DCX_CLIPCHILDREN | 
450                         DCX_CACHE | DCX_WINDOW);
451
452     if (flags & DCX_CACHE)
453     {
454         DCE*    dceEmpty;
455         DCE*    dceUnused;
456
457         dceEmpty = dceUnused = NULL;
458
459         /* Strategy: First, we attempt to find a non-empty but unused DCE with
460          * compatible flags. Next, we look for an empty entry. If the cache is
461          * full we have to purge one of the unused entries.
462          */
463
464         for (dce = firstDCE; (dce); dce = dce->next)
465         {
466             if ((dce->DCXflags & (DCX_CACHE | DCX_DCEBUSY)) == DCX_CACHE )
467             {
468                 dceUnused = dce;
469
470                 if (dce->DCXflags & DCX_DCEEMPTY)
471                     dceEmpty = dce;
472                 else
473                 if ((dce->hwndCurrent == hwnd) &&
474                    ((dce->DCXflags & (DCX_CLIPSIBLINGS | DCX_CLIPCHILDREN |
475                                       DCX_CACHE | DCX_WINDOW | DCX_PARENTCLIP)) == dcxFlags))
476                 {
477                     TRACE("\tfound valid %08x dce [%04x], flags %08x\n", 
478                                         (unsigned)dce, hwnd, (unsigned)dcxFlags );
479                     bUpdateVisRgn = FALSE; 
480                     bUpdateClipOrigin = TRUE;
481                     break;
482                 }
483             }
484         }
485
486         if (!dce) dce = (dceEmpty) ? dceEmpty : dceUnused;
487         
488         /* if there's no dce empty or unused, allocate a new one */
489         if (!dce)
490         {
491             dce = DCE_AllocDCE( 0, DCE_CACHE_DC );
492         }
493     }
494     else 
495     {
496         dce = wndPtr->dce;
497         if (dce && dce->hwndCurrent == hwnd)
498         {
499             TRACE("\tskipping hVisRgn update\n");
500             bUpdateVisRgn = FALSE; /* updated automatically, via DCHook() */
501         }
502     }
503     if (!dce)
504     {
505         hdc = 0;
506         goto END;
507     }
508
509     if (!(flags & (DCX_INTERSECTRGN | DCX_EXCLUDERGN))) hrgnClip = 0;
510
511     if (((flags ^ dce->DCXflags) & (DCX_INTERSECTRGN | DCX_EXCLUDERGN)) &&
512         (dce->hClipRgn != hrgnClip))
513     {
514         /* if the extra clip region has changed, get rid of the old one */
515         DCE_DeleteClipRgn( dce );
516     }
517
518     dce->hwndCurrent = hwnd;
519     dce->hClipRgn = hrgnClip;
520     dce->DCXflags = flags & (DCX_PARENTCLIP | DCX_CLIPSIBLINGS | DCX_CLIPCHILDREN |
521                              DCX_CACHE | DCX_WINDOW | DCX_WINDOWPAINT |
522                              DCX_KEEPCLIPRGN | DCX_INTERSECTRGN | DCX_EXCLUDERGN);
523     dce->DCXflags |= DCX_DCEBUSY;
524     dce->DCXflags &= ~DCX_DCEDIRTY;
525     hdc = dce->hDC;
526
527     if (bUpdateVisRgn) SetHookFlags16( hdc, DCHF_INVALIDATEVISRGN ); /* force update */
528
529     if (!USER_Driver.pGetDC( hwnd, hdc, hrgnClip, flags )) hdc = 0;
530
531     TRACE("(%04x,%04x,0x%lx): returning %04x\n", hwnd, hrgnClip, flags, hdc);
532 END:
533     WIN_ReleaseWndPtr(wndPtr);
534     return hdc;
535 }
536
537
538 /***********************************************************************
539  *              GetDC (USER.66)
540  */
541 HDC16 WINAPI GetDC16( HWND16 hwnd )
542 {
543     return (HDC16)GetDC( hwnd );
544 }
545
546
547 /***********************************************************************
548  *              GetDC (USER32.@)
549  * RETURNS
550  *      :Handle to DC
551  *      NULL: Failure
552  */
553 HDC WINAPI GetDC(
554              HWND hwnd /* [in] handle of window */
555 ) {
556     if (!hwnd)
557         return GetDCEx( 0, 0, DCX_CACHE | DCX_WINDOW );
558     return GetDCEx( hwnd, 0, DCX_USESTYLE );
559 }
560
561
562 /***********************************************************************
563  *              GetWindowDC (USER.67)
564  */
565 HDC16 WINAPI GetWindowDC16( HWND16 hwnd )
566 {
567     return GetDCEx16( hwnd, 0, DCX_USESTYLE | DCX_WINDOW );
568 }
569
570
571 /***********************************************************************
572  *              GetWindowDC (USER32.@)
573  */
574 HDC WINAPI GetWindowDC( HWND hwnd )
575 {
576     return GetDCEx( hwnd, 0, DCX_USESTYLE | DCX_WINDOW );
577 }
578
579
580 /***********************************************************************
581  *              ReleaseDC (USER.68)
582  */
583 INT16 WINAPI ReleaseDC16( HWND16 hwnd, HDC16 hdc )
584 {
585     return (INT16)ReleaseDC( hwnd, hdc );
586 }
587
588
589 /***********************************************************************
590  *              ReleaseDC (USER32.@)
591  *
592  * RETURNS
593  *      1: Success
594  *      0: Failure
595  */
596 INT WINAPI ReleaseDC( 
597              HWND hwnd /* [in] Handle of window - ignored */, 
598              HDC hdc   /* [in] Handle of device context */
599 ) {
600     DCE * dce;
601     INT nRet = 0;
602
603     USER_Lock();
604     dce = firstDCE;
605     
606     TRACE("%04x %04x\n", hwnd, hdc );
607         
608     while (dce && (dce->hDC != hdc)) dce = dce->next;
609
610     if ( dce ) 
611         if ( dce->DCXflags & DCX_DCEBUSY )
612             nRet = DCE_ReleaseDC( dce );
613
614     USER_Unlock();
615
616     return nRet;
617 }
618
619 /***********************************************************************
620  *              DCHook (USER.362)
621  *
622  * See "Undoc. Windows" for hints (DC, SetDCHook, SetHookFlags)..  
623  */
624 BOOL16 WINAPI DCHook16( HDC16 hDC, WORD code, DWORD data, LPARAM lParam )
625 {
626     BOOL retv = TRUE;
627     DCE *dce = (DCE *)data;
628
629     TRACE("hDC = %04x, %i\n", hDC, code);
630
631     if (!dce) return 0;
632     assert(dce->hDC == hDC);
633
634     /* Grab the windows lock before doing anything else  */
635     USER_Lock();
636
637     switch( code )
638     {
639       case DCHC_INVALIDVISRGN:
640            /* GDI code calls this when it detects that the
641             * DC is dirty (usually after SetHookFlags()). This
642             * means that we have to recompute the visible region.
643             */
644            if( dce->DCXflags & DCX_DCEBUSY )
645            {
646                /* Dirty bit has been cleared by caller, set it again so that
647                 * pGetDC recomputes the visible region. */
648                SetHookFlags16( dce->hDC, DCHF_INVALIDATEVISRGN );
649                USER_Driver.pGetDC( dce->hwndCurrent, dce->hDC, dce->hClipRgn, dce->DCXflags );
650            }
651            else /* non-fatal but shouldn't happen */
652              WARN("DC is not in use!\n");
653            break;
654
655       case DCHC_DELETEDC:
656            /*
657             * Windows will not let you delete a DC that is busy
658             * (between GetDC and ReleaseDC)
659             */
660
661            if ( dce->DCXflags & DCX_DCEBUSY )
662            {
663                WARN("Application trying to delete a busy DC\n");
664                retv = FALSE;
665            }
666            break;
667
668       default:
669            FIXME("unknown code\n");
670     }
671
672   USER_Unlock();  /* Release the wnd lock */
673   return retv;
674 }
675
676
677 /**********************************************************************
678  *              WindowFromDC (USER.117)
679  */
680 HWND16 WINAPI WindowFromDC16( HDC16 hDC )
681 {
682     return (HWND16)WindowFromDC( hDC );
683 }
684
685
686 /**********************************************************************
687  *              WindowFromDC (USER32.@)
688  */
689 HWND WINAPI WindowFromDC( HDC hDC )
690 {
691     DCE *dce;
692     HWND hwnd;
693
694     USER_Lock();
695     dce = firstDCE;
696     
697     while (dce && (dce->hDC != hDC)) dce = dce->next;
698
699     hwnd = dce ? dce->hwndCurrent : 0;
700     USER_Unlock();
701     
702     return hwnd;
703 }
704
705
706 /***********************************************************************
707  *              LockWindowUpdate (USER.294)
708  */
709 BOOL16 WINAPI LockWindowUpdate16( HWND16 hwnd )
710 {
711     return LockWindowUpdate( hwnd );
712 }
713
714 /***********************************************************************
715  *              LockWindowUpdate (USER32.@)
716  */
717 BOOL WINAPI LockWindowUpdate( HWND hwnd )
718 {
719     FIXME("(%x), stub!\n",hwnd);
720     return TRUE;
721 }