Fixed some issues found by winapi_check.
[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     WIN_LockWnds();
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     WIN_UnlockWnds();
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     WIN_LockWnds();
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     WIN_UnlockWnds();
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( WND* pWnd )
147 {
148     DCE *pDCE;
149
150     WIN_LockWnds();
151     pDCE = firstDCE;
152
153     while( pDCE )
154     {
155         if( pDCE->hwndCurrent == pWnd->hwndSelf )
156         {
157             if( pDCE == pWnd->dce ) /* owned or Class DCE*/
158             {
159                 if (pWnd->clsStyle & CS_OWNDC)  /* owned DCE*/
160                 {
161                     pDCE = DCE_FreeDCE( pDCE );
162                     pWnd->dce = NULL;
163                     continue;
164                 }
165                 else if( pDCE->DCXflags & (DCX_INTERSECTRGN | DCX_EXCLUDERGN) ) /* Class DCE*/
166                 {
167                     DCE_DeleteClipRgn( pDCE );
168                     pDCE->hwndCurrent = 0;
169                 }
170             }
171             else
172             {
173                 if( pDCE->DCXflags & DCX_DCEBUSY ) /* shared cache DCE */
174                 {
175                     /* FIXME: AFAICS we are doing the right thing here so 
176                      * this should be a WARN. But this is best left as an ERR 
177                      * because the 'application error' is likely to come from 
178                      * another part of Wine (i.e. it's our fault after all). 
179                      * We should change this to WARN when Wine is more stable
180                      * (for 1.0?).
181                      */
182                     ERR("[%04x] GetDC() without ReleaseDC()!\n", 
183                         pWnd->hwndSelf);
184                     DCE_ReleaseDC( pDCE );
185                 }
186
187                 pDCE->DCXflags &= DCX_CACHE;
188                 pDCE->DCXflags |= DCX_DCEEMPTY;
189                 pDCE->hwndCurrent = 0;
190             }
191         }
192         pDCE = pDCE->next;
193     }
194     
195     WIN_UnlockWnds();
196 }
197
198
199 /***********************************************************************
200  *   DCE_DeleteClipRgn
201  */
202 static void DCE_DeleteClipRgn( DCE* dce )
203 {
204     dce->DCXflags &= ~(DCX_EXCLUDERGN | DCX_INTERSECTRGN | DCX_WINDOWPAINT);
205
206     if( dce->DCXflags & DCX_KEEPCLIPRGN )
207         dce->DCXflags &= ~DCX_KEEPCLIPRGN;
208     else
209         if( dce->hClipRgn > 1 )
210             DeleteObject( dce->hClipRgn );
211
212     dce->hClipRgn = 0;
213
214     /* make it dirty so that the vis rgn gets recomputed next time */
215     dce->DCXflags |= DCX_DCEDIRTY;
216     SetHookFlags16( dce->hDC, DCHF_INVALIDATEVISRGN );
217 }
218
219
220 /***********************************************************************
221  *   DCE_ReleaseDC
222  */
223 static INT DCE_ReleaseDC( DCE* dce )
224 {
225     if ((dce->DCXflags & (DCX_DCEEMPTY | DCX_DCEBUSY)) != DCX_DCEBUSY) return 0;
226
227     /* restore previous visible region */
228
229     if ((dce->DCXflags & (DCX_INTERSECTRGN | DCX_EXCLUDERGN)) &&
230         (dce->DCXflags & (DCX_CACHE | DCX_WINDOWPAINT)) )
231         DCE_DeleteClipRgn( dce );
232
233     if (dce->DCXflags & DCX_CACHE)
234     {
235         SetDCState16( dce->hDC, defaultDCstate );
236         dce->DCXflags &= ~DCX_DCEBUSY;
237         if (dce->DCXflags & DCX_DCEDIRTY)
238         {
239             /* don't keep around invalidated entries 
240              * because SetDCState() disables hVisRgn updates
241              * by removing dirty bit. */
242
243             dce->hwndCurrent = 0;
244             dce->DCXflags &= DCX_CACHE;
245             dce->DCXflags |= DCX_DCEEMPTY;
246         }
247     }
248     return 1;
249 }
250
251
252 /***********************************************************************
253  *   DCE_InvalidateDCE
254  *
255  * It is called from SetWindowPos() and EVENT_MapNotify - we have to
256  * mark as dirty all busy DCEs for windows that have pWnd->parent as
257  * an ancestor and whose client rect intersects with specified update
258  * rectangle. In addition, pWnd->parent DCEs may need to be updated if
259  * DCX_CLIPCHILDREN flag is set.  */
260 BOOL DCE_InvalidateDCE(WND* pWnd, const RECT* pRectUpdate)
261 {
262     WND* wndScope = WIN_LockWndPtr(pWnd->parent);
263     BOOL bRet = FALSE;
264
265     if( wndScope )
266     {
267         DCE *dce;
268
269         TRACE("scope hwnd = %04x, (%i,%i - %i,%i)\n",
270                      wndScope->hwndSelf, pRectUpdate->left,pRectUpdate->top,
271                      pRectUpdate->right,pRectUpdate->bottom);
272         if(TRACE_ON(dc)) 
273           DCE_DumpCache();
274
275         /* walk all DCEs and fixup non-empty entries */
276
277         for (dce = firstDCE; (dce); dce = dce->next)
278         {
279             if( !(dce->DCXflags & DCX_DCEEMPTY) )
280             {
281                 WND* wndCurrent = WIN_FindWndPtr(dce->hwndCurrent);
282
283                 if( wndCurrent )
284                 {
285                     WND* wnd = NULL;
286                     INT xoffset = 0, yoffset = 0;
287
288                     if( (wndCurrent == wndScope) && !(dce->DCXflags & DCX_CLIPCHILDREN) )
289                     {
290                         /* child window positions don't bother us */
291                         WIN_ReleaseWndPtr(wndCurrent);
292                         continue;
293                     }
294
295                     /* check if DCE window is within the z-order scope */
296
297                     for( wnd = WIN_LockWndPtr(wndCurrent); wnd; WIN_UpdateWndPtr(&wnd,wnd->parent))
298                     {
299                         if( wnd == wndScope )
300                         {
301                             RECT wndRect;
302
303                             wndRect = wndCurrent->rectWindow;
304
305                             OffsetRect( &wndRect, xoffset - wndCurrent->rectClient.left, 
306                                                     yoffset - wndCurrent->rectClient.top);
307
308                             if (pWnd == wndCurrent ||
309                                 IntersectRect( &wndRect, &wndRect, pRectUpdate ))
310                             { 
311                                 if( !(dce->DCXflags & DCX_DCEBUSY) )
312                                 {
313                                     /* Don't bother with visible regions of unused DCEs */
314
315                                     TRACE("\tpurged %08x dce [%04x]\n", 
316                                                 (unsigned)dce, wndCurrent->hwndSelf);
317
318                                     dce->hwndCurrent = 0;
319                                     dce->DCXflags &= DCX_CACHE;
320                                     dce->DCXflags |= DCX_DCEEMPTY;
321                                 }
322                                 else
323                                 {
324                                     /* Set dirty bits in the hDC and DCE structs */
325
326                                     TRACE("\tfixed up %08x dce [%04x]\n", 
327                                                 (unsigned)dce, wndCurrent->hwndSelf);
328
329                                     dce->DCXflags |= DCX_DCEDIRTY;
330                                     SetHookFlags16(dce->hDC, DCHF_INVALIDATEVISRGN);
331                                     bRet = TRUE;
332                                 }
333                             }
334                             WIN_ReleaseWndPtr(wnd);
335                             break;
336                         }
337                         xoffset += wnd->rectClient.left;
338                         yoffset += wnd->rectClient.top;
339                     }
340                 }
341                 WIN_ReleaseWndPtr(wndCurrent);
342             }
343         } /* dce list */
344         WIN_ReleaseWndPtr(wndScope);
345     }
346     return bRet;
347 }
348
349
350 /***********************************************************************
351  *           DCE_ExcludeRgn
352  * 
353  *  Translate given region from the wnd client to the DC coordinates
354  *  and add it to the clipping region.
355  */
356 INT DCE_ExcludeRgn( HDC hDC, WND* wnd, HRGN hRgn )
357 {
358   POINT  pt = {0, 0};
359   DCE     *dce = firstDCE;
360
361   while (dce && (dce->hDC != hDC)) dce = dce->next;
362   if( dce )
363   {
364       MapWindowPoints( wnd->hwndSelf, dce->hwndCurrent, &pt, 1);
365       if( dce->DCXflags & DCX_WINDOW )
366       { 
367           wnd = WIN_FindWndPtr(dce->hwndCurrent);
368           pt.x += wnd->rectClient.left - wnd->rectWindow.left;
369           pt.y += wnd->rectClient.top - wnd->rectWindow.top;
370           WIN_ReleaseWndPtr(wnd);
371       }
372   }
373   else return ERROR;
374   OffsetRgn(hRgn, pt.x, pt.y);
375
376   return ExtSelectClipRgn( hDC, hRgn, RGN_DIFF );
377 }
378
379
380 /***********************************************************************
381  *              GetDCEx (USER.359)
382  */
383 HDC16 WINAPI GetDCEx16( HWND16 hwnd, HRGN16 hrgnClip, DWORD flags )
384 {
385     return (HDC16)GetDCEx( hwnd, hrgnClip, flags );
386 }
387
388
389 /***********************************************************************
390  *              GetDCEx (USER32.@)
391  *
392  * Unimplemented flags: DCX_LOCKWINDOWUPDATE
393  *
394  * FIXME: Full support for hrgnClip == 1 (alias for entire window).
395  */
396 HDC WINAPI GetDCEx( HWND hwnd, HRGN hrgnClip, DWORD flags )
397 {
398     HDC         hdc = 0;
399     DCE *       dce;
400     WND *       wndPtr;
401     DWORD       dcxFlags = 0;
402     BOOL        bUpdateVisRgn = TRUE;
403     BOOL        bUpdateClipOrigin = FALSE;
404
405     TRACE("hwnd %04x, hrgnClip %04x, flags %08x\n", 
406           hwnd, hrgnClip, (unsigned)flags);
407
408     if (!hwnd) hwnd = GetDesktopWindow();
409     if (!(wndPtr = WIN_FindWndPtr( hwnd ))) return 0;
410
411     /* fixup flags */
412
413     if (!wndPtr->dce) flags |= DCX_CACHE;
414
415     if (flags & DCX_USESTYLE)
416     {
417         flags &= ~( DCX_CLIPCHILDREN | DCX_CLIPSIBLINGS | DCX_PARENTCLIP);
418
419         if( wndPtr->dwStyle & WS_CLIPSIBLINGS )
420             flags |= DCX_CLIPSIBLINGS;
421
422         if ( !(flags & DCX_WINDOW) )
423         {
424             if (wndPtr->clsStyle & CS_PARENTDC) flags |= DCX_PARENTCLIP;
425
426             if (wndPtr->dwStyle & WS_CLIPCHILDREN &&
427                      !(wndPtr->dwStyle & WS_MINIMIZE) ) flags |= DCX_CLIPCHILDREN;
428         }
429         else flags |= DCX_CACHE;
430     }
431
432     if (flags & DCX_WINDOW) 
433         flags = (flags & ~DCX_CLIPCHILDREN) | DCX_CACHE;
434
435     if (!wndPtr->parent || (wndPtr->parent->hwndSelf == GetDesktopWindow()))
436         flags = (flags & ~DCX_PARENTCLIP) | DCX_CLIPSIBLINGS;
437     else if( flags & DCX_PARENTCLIP )
438     {
439         flags |= DCX_CACHE;
440         if( !(flags & (DCX_CLIPSIBLINGS | DCX_CLIPCHILDREN)) )
441             if( (wndPtr->dwStyle & WS_VISIBLE) && (wndPtr->parent->dwStyle & WS_VISIBLE) )
442             {
443                 flags &= ~DCX_CLIPCHILDREN;
444                 if( wndPtr->parent->dwStyle & WS_CLIPSIBLINGS )
445                     flags |= DCX_CLIPSIBLINGS;
446             }
447     }
448
449     /* find a suitable DCE */
450
451     dcxFlags = flags & (DCX_PARENTCLIP | DCX_CLIPSIBLINGS | DCX_CLIPCHILDREN | 
452                         DCX_CACHE | DCX_WINDOW);
453
454     if (flags & DCX_CACHE)
455     {
456         DCE*    dceEmpty;
457         DCE*    dceUnused;
458
459         dceEmpty = dceUnused = NULL;
460
461         /* Strategy: First, we attempt to find a non-empty but unused DCE with
462          * compatible flags. Next, we look for an empty entry. If the cache is
463          * full we have to purge one of the unused entries.
464          */
465
466         for (dce = firstDCE; (dce); dce = dce->next)
467         {
468             if ((dce->DCXflags & (DCX_CACHE | DCX_DCEBUSY)) == DCX_CACHE )
469             {
470                 dceUnused = dce;
471
472                 if (dce->DCXflags & DCX_DCEEMPTY)
473                     dceEmpty = dce;
474                 else
475                 if ((dce->hwndCurrent == hwnd) &&
476                    ((dce->DCXflags & (DCX_CLIPSIBLINGS | DCX_CLIPCHILDREN |
477                                       DCX_CACHE | DCX_WINDOW | DCX_PARENTCLIP)) == dcxFlags))
478                 {
479                     TRACE("\tfound valid %08x dce [%04x], flags %08x\n", 
480                                         (unsigned)dce, hwnd, (unsigned)dcxFlags );
481                     bUpdateVisRgn = FALSE; 
482                     bUpdateClipOrigin = TRUE;
483                     break;
484                 }
485             }
486         }
487
488         if (!dce) dce = (dceEmpty) ? dceEmpty : dceUnused;
489         
490         /* if there's no dce empty or unused, allocate a new one */
491         if (!dce)
492         {
493             dce = DCE_AllocDCE( 0, DCE_CACHE_DC );
494         }
495     }
496     else 
497     {
498         dce = wndPtr->dce;
499         if( dce->hwndCurrent == hwnd )
500         {
501             TRACE("\tskipping hVisRgn update\n");
502             bUpdateVisRgn = FALSE; /* updated automatically, via DCHook() */
503         }
504     }
505     if (!dce)
506     {
507         hdc = 0;
508         goto END;
509     }
510
511     if (!(flags & (DCX_INTERSECTRGN | DCX_EXCLUDERGN))) hrgnClip = 0;
512
513     if (((flags ^ dce->DCXflags) & (DCX_INTERSECTRGN | DCX_EXCLUDERGN)) &&
514         (dce->hClipRgn != hrgnClip))
515     {
516         /* if the extra clip region has changed, get rid of the old one */
517         DCE_DeleteClipRgn( dce );
518     }
519
520     dce->hwndCurrent = hwnd;
521     dce->hClipRgn = hrgnClip;
522     dce->DCXflags = flags & (DCX_PARENTCLIP | DCX_CLIPSIBLINGS | DCX_CLIPCHILDREN |
523                              DCX_CACHE | DCX_WINDOW | DCX_WINDOWPAINT |
524                              DCX_KEEPCLIPRGN | DCX_INTERSECTRGN | DCX_EXCLUDERGN);
525     dce->DCXflags |= DCX_DCEBUSY;
526     dce->DCXflags &= ~DCX_DCEDIRTY;
527     hdc = dce->hDC;
528
529     if (bUpdateVisRgn) SetHookFlags16( hdc, DCHF_INVALIDATEVISRGN ); /* force update */
530
531     if (!USER_Driver.pGetDC( hwnd, hdc, hrgnClip, flags )) hdc = 0;
532
533     TRACE("(%04x,%04x,0x%lx): returning %04x\n", hwnd, hrgnClip, flags, hdc);
534 END:
535     WIN_ReleaseWndPtr(wndPtr);
536     return hdc;
537 }
538
539
540 /***********************************************************************
541  *              GetDC (USER.66)
542  */
543 HDC16 WINAPI GetDC16( HWND16 hwnd )
544 {
545     return (HDC16)GetDC( hwnd );
546 }
547
548
549 /***********************************************************************
550  *              GetDC (USER32.@)
551  * RETURNS
552  *      :Handle to DC
553  *      NULL: Failure
554  */
555 HDC WINAPI GetDC(
556              HWND hwnd /* [in] handle of window */
557 ) {
558     if (!hwnd)
559         return GetDCEx( 0, 0, DCX_CACHE | DCX_WINDOW );
560     return GetDCEx( hwnd, 0, DCX_USESTYLE );
561 }
562
563
564 /***********************************************************************
565  *              GetWindowDC (USER.67)
566  */
567 HDC16 WINAPI GetWindowDC16( HWND16 hwnd )
568 {
569     return GetDCEx16( hwnd, 0, DCX_USESTYLE | DCX_WINDOW );
570 }
571
572
573 /***********************************************************************
574  *              GetWindowDC (USER32.@)
575  */
576 HDC WINAPI GetWindowDC( HWND hwnd )
577 {
578     return GetDCEx( hwnd, 0, DCX_USESTYLE | DCX_WINDOW );
579 }
580
581
582 /***********************************************************************
583  *              ReleaseDC (USER.68)
584  */
585 INT16 WINAPI ReleaseDC16( HWND16 hwnd, HDC16 hdc )
586 {
587     return (INT16)ReleaseDC( hwnd, hdc );
588 }
589
590
591 /***********************************************************************
592  *              ReleaseDC (USER32.@)
593  *
594  * RETURNS
595  *      1: Success
596  *      0: Failure
597  */
598 INT WINAPI ReleaseDC( 
599              HWND hwnd /* [in] Handle of window - ignored */, 
600              HDC hdc   /* [in] Handle of device context */
601 ) {
602     DCE * dce;
603     INT nRet = 0;
604
605     WIN_LockWnds();
606     dce = firstDCE;
607     
608     TRACE("%04x %04x\n", hwnd, hdc );
609         
610     while (dce && (dce->hDC != hdc)) dce = dce->next;
611
612     if ( dce ) 
613         if ( dce->DCXflags & DCX_DCEBUSY )
614             nRet = DCE_ReleaseDC( dce );
615
616     WIN_UnlockWnds();
617
618     return nRet;
619 }
620
621 /***********************************************************************
622  *              DCHook (USER.362)
623  *
624  * See "Undoc. Windows" for hints (DC, SetDCHook, SetHookFlags)..  
625  */
626 BOOL16 WINAPI DCHook16( HDC16 hDC, WORD code, DWORD data, LPARAM lParam )
627 {
628     BOOL retv = TRUE;
629     DCE *dce = (DCE *)data;
630
631     TRACE("hDC = %04x, %i\n", hDC, code);
632
633     if (!dce) return 0;
634     assert(dce->hDC == hDC);
635
636     /* Grab the windows lock before doing anything else  */
637     WIN_LockWnds();
638
639     switch( code )
640     {
641       case DCHC_INVALIDVISRGN:
642            /* GDI code calls this when it detects that the
643             * DC is dirty (usually after SetHookFlags()). This
644             * means that we have to recompute the visible region.
645             */
646            if( dce->DCXflags & DCX_DCEBUSY )
647            {
648                /* Dirty bit has been cleared by caller, set it again so that
649                 * pGetDC recomputes the visible region. */
650                SetHookFlags16( dce->hDC, DCHF_INVALIDATEVISRGN );
651                USER_Driver.pGetDC( dce->hwndCurrent, dce->hDC, dce->hClipRgn, dce->DCXflags );
652            }
653            else /* non-fatal but shouldn't happen */
654              WARN("DC is not in use!\n");
655            break;
656
657       case DCHC_DELETEDC:
658            /*
659             * Windows will not let you delete a DC that is busy
660             * (between GetDC and ReleaseDC)
661             */
662
663            if ( dce->DCXflags & DCX_DCEBUSY )
664            {
665                WARN("Application trying to delete a busy DC\n");
666                retv = FALSE;
667            }
668            break;
669
670       default:
671            FIXME("unknown code\n");
672     }
673
674   WIN_UnlockWnds();  /* Release the wnd lock */
675   return retv;
676 }
677
678
679 /**********************************************************************
680  *              WindowFromDC (USER.117)
681  */
682 HWND16 WINAPI WindowFromDC16( HDC16 hDC )
683 {
684     return (HWND16)WindowFromDC( hDC );
685 }
686
687
688 /**********************************************************************
689  *              WindowFromDC (USER32.@)
690  */
691 HWND WINAPI WindowFromDC( HDC hDC )
692 {
693     DCE *dce;
694     HWND hwnd;
695
696     WIN_LockWnds();
697     dce = firstDCE;
698     
699     while (dce && (dce->hDC != hDC)) dce = dce->next;
700
701     hwnd = dce ? dce->hwndCurrent : 0;
702     WIN_UnlockWnds();
703     
704     return hwnd;
705 }
706
707
708 /***********************************************************************
709  *              LockWindowUpdate (USER.294)
710  */
711 BOOL16 WINAPI LockWindowUpdate16( HWND16 hwnd )
712 {
713     return LockWindowUpdate( hwnd );
714 }
715
716
717 /***********************************************************************
718  *              LockWindowUpdate (USER32.@)
719  */
720 BOOL WINAPI LockWindowUpdate( HWND hwnd )
721 {
722     FIXME("DCX_LOCKWINDOWUPDATE is unimplemented\n");
723     return TRUE;
724 }