:pserver:cvsanon@mok.lvcm.com:/CVS/ReactOS reactos
[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(VOID)
38 {
39   if (NrGuiApplicationsRunning == 0)
40     {
41       W32kInitializeDesktopGraphics();
42     }
43   NrGuiApplicationsRunning++;
44 }
45
46 VOID
47 W32kGuiCheck(VOID)
48
49   if (PsGetWin32Process() == NULL)
50     {
51       NTSTATUS Status;
52
53       PsCreateWin32Process(PsGetCurrentProcess());
54
55       InitializeListHead(&PsGetWin32Process()->ClassListHead);
56       ExInitializeFastMutex(&PsGetWin32Process()->ClassListLock);      
57
58       Status = 
59         ValidateWindowStationHandle(PROCESS_WINDOW_STATION(),
60                                     UserMode,
61                                     GENERIC_ALL,
62                                     &PsGetWin32Process()->WindowStation);
63       if (!NT_SUCCESS(Status))
64         {
65           DbgPrint("W32K: Failed to reference a window station for "
66                    "process.\n");
67         }
68     }
69
70   if (PsGetWin32Thread() == NULL)
71     {
72       NTSTATUS Status;
73
74       PsCreateWin32Thread(PsGetCurrentThread());
75       PsGetWin32Thread()->MessageQueue = MsqCreateMessageQueue();
76       InitializeListHead(&PsGetWin32Thread()->WindowListHead);
77       ExInitializeFastMutex(&PsGetWin32Thread()->WindowListLock);
78
79       /* By default threads get assigned their process's desktop. */
80       PsGetWin32Thread()->Desktop = NULL;
81       Status = ObReferenceObjectByHandle(PsGetCurrentProcess()->Win32Desktop,
82                                          GENERIC_ALL,
83                                          ExDesktopObjectType,
84                                          UserMode,
85                                          (PVOID*)&PsGetWin32Thread()->Desktop,
86                                          NULL);
87       if (!NT_SUCCESS(Status))
88         {
89           DbgPrint("W32K: Failed to reference a desktop for thread.\n");
90         }
91     }
92 }
93
94 /* EOF */