[WIN32K:NTUSER]
[reactos.git] / reactos / win32ss / user / ntuser / guicheck.c
1 /*
2 * COPYRIGHT: See COPYING in the top level directory
3 * PROJECT: ReactOS kernel
4 * PURPOSE: GUI state check
5 * FILE: win32ss/user/ntuser/guicheck.c
6 * PROGRAMER: Casper S. Hornstrup (chorns@users.sourceforge.net)
7 * NOTES: The GuiCheck() function performs a few delayed operations:
8 * 1) A GUI process is assigned a window station
9 * 2) A message queue is created for a GUI thread before use
10 * 3) The system window classes are registered for a process
11 */
12
13 #include <win32k.h>
14
15 /* GLOBALS *******************************************************************/
16
17 static LONG NrGuiAppsRunning = 0;
18
19 /* FUNCTIONS *****************************************************************/
20
21 static BOOL FASTCALL
22 co_AddGuiApp(PPROCESSINFO W32Data)
23 {
24 W32Data->W32PF_flags |= W32PF_CREATEDWINORDC;
25 if (InterlockedIncrement(&NrGuiAppsRunning) == 1)
26 {
27 BOOL Initialized;
28
29 Initialized = co_IntInitializeDesktopGraphics();
30
31 if (!Initialized)
32 {
33 W32Data->W32PF_flags &= ~W32PF_CREATEDWINORDC;
34 InterlockedDecrement(&NrGuiAppsRunning);
35 return FALSE;
36 }
37 }
38 return TRUE;
39 }
40
41 static void FASTCALL
42 RemoveGuiApp(PPROCESSINFO W32Data)
43 {
44 W32Data->W32PF_flags &= ~W32PF_CREATEDWINORDC;
45 if (InterlockedDecrement(&NrGuiAppsRunning) == 0)
46 {
47 IntEndDesktopGraphics();
48 }
49 }
50
51 BOOL FASTCALL
52 co_IntGraphicsCheck(BOOL Create)
53 {
54 PPROCESSINFO W32Data;
55
56 W32Data = PsGetCurrentProcessWin32Process();
57 if (Create)
58 {
59 if (! (W32Data->W32PF_flags & W32PF_CREATEDWINORDC) && ! (W32Data->W32PF_flags & W32PF_MANUALGUICHECK))
60 {
61 return co_AddGuiApp(W32Data);
62 }
63 }
64 else
65 {
66 if ((W32Data->W32PF_flags & W32PF_CREATEDWINORDC) && ! (W32Data->W32PF_flags & W32PF_MANUALGUICHECK))
67 {
68 RemoveGuiApp(W32Data);
69 }
70 }
71
72 return TRUE;
73 }
74
75 VOID
76 FASTCALL
77 co_IntUserManualGuiCheck(BOOL Create)
78 {
79 PPROCESSINFO W32Data = (PPROCESSINFO)PsGetCurrentProcessWin32Process();
80 W32Data->W32PF_flags |= W32PF_MANUALGUICHECK;
81
82 if (Create)
83 {
84 co_AddGuiApp(W32Data);
85 }
86 else
87 {
88 RemoveGuiApp(W32Data);
89 }
90 }
91
92 /* EOF */