update for HEAD-2003050101
[reactos.git] / subsys / win32k / ntuser / guicheck.c
1  /* $Id$
2  *
3  * COPYRIGHT:        See COPYING in the top level directory
4  * PROJECT:          ReactOS kernel
5  * PURPOSE:          GUI state check
6  * FILE:             subsys/win32k/ntuser/guicheck.c
7  * PROGRAMER:        Casper S. Hornstrup (chorns@users.sourceforge.net)
8  * NOTES:            The GuiCheck() function performs a few delayed operations:
9  *                   1) A GUI process is assigned a window station
10  *                   2) A message queue is created for a GUI thread before use
11  *                   3) The system window classes are registered for a process
12  * REVISION HISTORY:
13  *       06-06-2001  CSH  Created
14  */
15
16 /* INCLUDES ******************************************************************/
17
18 #include <ddk/ntddk.h>
19 #include <napi/teb.h>
20 #include <win32k/win32k.h>
21 #include <include/guicheck.h>
22 #include <include/msgqueue.h>
23 #include <include/object.h>
24 #include <napi/win32.h>
25 #include <include/winsta.h>
26
27 #define NDEBUG
28 #include <debug.h>
29
30 /* GLOBALS *******************************************************************/
31
32 static ULONG NrGuiApplicationsRunning = 0;
33
34 /* FUNCTIONS *****************************************************************/
35
36 VOID
37 W32kGraphicsCheck(BOOL Create)
38 {
39   if (Create)
40     {
41       if (0 == NrGuiApplicationsRunning)
42         {
43           W32kInitializeDesktopGraphics();
44         }
45       NrGuiApplicationsRunning++;
46     }
47   else
48     {
49       if (0 < NrGuiApplicationsRunning)
50         {
51           NrGuiApplicationsRunning--;
52         }
53       if (0 == NrGuiApplicationsRunning)
54         {
55           W32kEndDesktopGraphics();
56         }
57     }
58     
59 }
60
61 VOID
62 W32kGuiCheck(VOID)
63
64   if (PsGetWin32Process() == NULL)
65     {
66       NTSTATUS Status;
67
68       PsCreateWin32Process(PsGetCurrentProcess());
69
70       InitializeListHead(&PsGetWin32Process()->ClassListHead);
71       ExInitializeFastMutex(&PsGetWin32Process()->ClassListLock);      
72
73       Status = 
74         ValidateWindowStationHandle(PROCESS_WINDOW_STATION(),
75                                     UserMode,
76                                     GENERIC_ALL,
77                                     &PsGetWin32Process()->WindowStation);
78       if (!NT_SUCCESS(Status))
79         {
80           DbgPrint("W32K: Failed to reference a window station for "
81                    "process.\n");
82         }
83     }
84
85   if (PsGetWin32Thread() == NULL)
86     {
87       NTSTATUS Status;
88
89       PsCreateWin32Thread(PsGetCurrentThread());
90       PsGetWin32Thread()->MessageQueue = MsqCreateMessageQueue();
91       InitializeListHead(&PsGetWin32Thread()->WindowListHead);
92       ExInitializeFastMutex(&PsGetWin32Thread()->WindowListLock);
93
94       /* By default threads get assigned their process's desktop. */
95       PsGetWin32Thread()->Desktop = NULL;
96       Status = ObReferenceObjectByHandle(PsGetCurrentProcess()->Win32Desktop,
97                                          GENERIC_ALL,
98                                          ExDesktopObjectType,
99                                          UserMode,
100                                          (PVOID*)&PsGetWin32Thread()->Desktop,
101                                          NULL);
102       if (!NT_SUCCESS(Status))
103         {
104           DbgPrint("W32K: Failed to reference a desktop for thread.\n");
105         }
106     }
107 }
108
109 /* EOF */