3 * COPYRIGHT: See COPYING in the top level directory
4 * PROJECT: ReactOS system libraries
5 * FILE: subsys/csrss/win32csr/guiconsole.c
6 * PURPOSE: Implementation of gui-mode consoles
9 /* INCLUDES ******************************************************************/
16 /* Not defined in any header file */
17 extern VOID STDCALL
PrivateCsrssManualGuiCheck(LONG Check
);
19 /* GLOBALS *******************************************************************/
21 typedef struct GUI_CONSOLE_DATA_TAG
29 CRITICAL_SECTION Lock
;
33 HMODULE ConsoleLibrary
;
35 WCHAR FontName
[LF_FACESIZE
];
44 } GUI_CONSOLE_DATA
, *PGUI_CONSOLE_DATA
;
49 #define PM_CREATE_CONSOLE (WM_APP + 1)
50 #define PM_DESTROY_CONSOLE (WM_APP + 2)
52 #define CURSOR_BLINK_TIME 500
54 static BOOL ConsInitialized
= FALSE
;
55 static HWND NotifyWnd
;
57 /* FUNCTIONS *****************************************************************/
60 GuiConsoleGetDataPointers(HWND hWnd
, PCSRSS_CONSOLE
*Console
, PGUI_CONSOLE_DATA
*GuiData
)
62 *Console
= (PCSRSS_CONSOLE
) GetWindowLongPtrW(hWnd
, GWL_USERDATA
);
63 *GuiData
= (NULL
== *Console
? NULL
: (*Console
)->PrivateData
);
67 GuiConsoleOpenUserRegistryPathPerProcessId(DWORD ProcessId
, PHANDLE hProcHandle
, PHKEY hResult
, REGSAM samDesired
)
69 HANDLE hProcessToken
= NULL
;
74 UNICODE_STRING SidName
;
78 hProcess
= OpenProcess(PROCESS_QUERY_INFORMATION
| PROCESS_VM_READ
| READ_CONTROL
, FALSE
, ProcessId
);
81 DPRINT("Error: OpenProcess failed(0x%x)\n", GetLastError());
85 if (!OpenProcessToken(hProcess
, TOKEN_QUERY
, &hProcessToken
))
87 DPRINT("Error: OpenProcessToken failed(0x%x)\n", GetLastError());
88 CloseHandle(hProcess
);
92 if (!GetTokenInformation(hProcessToken
, TokenUser
, (PVOID
)Buffer
, sizeof(Buffer
), &Length
))
94 DPRINT("Error: GetTokenInformation failed(0x%x)\n",GetLastError());
95 CloseHandle(hProcess
);
96 CloseHandle(hProcessToken
);
100 TokUser
= ((PTOKEN_USER
)Buffer
)->User
.Sid
;
101 if (!NT_SUCCESS(RtlConvertSidToUnicodeString(&SidName
, TokUser
, TRUE
)))
103 DPRINT("Error: RtlConvertSidToUnicodeString failed(0x%x)\n", GetLastError());
107 res
= RegOpenKeyExW(HKEY_USERS
, SidName
.Buffer
, 0, samDesired
, hResult
);
108 RtlFreeUnicodeString(&SidName
);
110 CloseHandle(hProcessToken
);
112 *hProcHandle
= hProcess
;
114 CloseHandle(hProcess
);
116 if (res
!= ERROR_SUCCESS
)
123 GuiConsoleOpenUserSettings(HWND hWnd
, DWORD ProcessId
, PHKEY hSubKey
, REGSAM samDesired
)
125 WCHAR szProcessName
[MAX_PATH
];
126 WCHAR szBuffer
[MAX_PATH
];
127 UINT fLength
, wLength
;
128 DWORD dwBitmask
, dwLength
;
129 WCHAR CurDrive
[] = { 'A',':', 0 };
133 static const WCHAR szSystemRoot
[] = { '%','S','y','s','t','e','m','R','o','o','t','%', 0 };
137 * console properties are stored under
140 * There are 3 ways to store console properties
142 * 1. use console title as subkey name
145 * 2. use application name as subkey name
147 * 3. use unexpanded path to console application.
148 * i.e. %SystemRoot%_system32_cmd.exe
151 if (!GuiConsoleOpenUserRegistryPathPerProcessId(ProcessId
, &hProcess
, &hKey
, samDesired
))
154 fLength
= GetProcessImageFileNameW(hProcess
, szProcessName
, MAX_PATH
);
155 CloseHandle(hProcess
);
159 DPRINT1("GetProcessImageFileNameW failed(0x%x)ProcessId %d\n", GetLastError(),hProcess
);
164 ptr
= wcsrchr(szProcessName
, L
'\\');
165 swprintf(szBuffer
, L
"Console%s",ptr
);
167 if (RegOpenKeyExW(hKey
, szBuffer
, 0, samDesired
, hSubKey
) == ERROR_SUCCESS
)
173 dwBitmask
= GetLogicalDrives();
178 dwLength
= QueryDosDeviceW(CurDrive
, szBuffer
, MAX_PATH
);
181 if (!memcmp(szBuffer
, szProcessName
, (dwLength
-2)*sizeof(WCHAR
)))
183 wcscpy(szBuffer
, CurDrive
);
184 wcscat(&szBuffer
[(sizeof(CurDrive
)/sizeof(WCHAR
))-1], &szProcessName
[dwLength
-2]);
189 dwBitmask
= (dwBitmask
>> 1);
193 wLength
= GetWindowsDirectoryW(szProcessName
, MAX_PATH
);
195 if (!wcsncmp(szProcessName
, szBuffer
, wLength
))
197 wcscpy(szProcessName
, szSystemRoot
);
198 wcscpy(&szProcessName
[(sizeof(szSystemRoot
) / sizeof(WCHAR
))-1], &szBuffer
[wLength
]);
199 ptr
= res
= szProcessName
;
203 ptr
= res
= szBuffer
;
206 while((ptr
= wcschr(szProcessName
, L
'\\')))
209 if (RegOpenKeyExW(hKey
, res
, 0, samDesired
, hSubKey
) == ERROR_SUCCESS
)
218 GuiConsoleReadUserSettings(HKEY hKey
, PGUI_CONSOLE_DATA GuiData
)
220 DWORD dwNumSubKeys
= 0;
225 WCHAR szValueName
[MAX_PATH
];
226 WCHAR szValue
[MAX_PATH
];
229 RegQueryInfoKey(hKey
, NULL
, NULL
, NULL
, &dwNumSubKeys
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
);
231 for (dwIndex
= 0; dwIndex
< dwNumSubKeys
; dwIndex
++)
233 dwValue
= sizeof(Value
);
234 dwValueName
= MAX_PATH
;
236 if (RegEnumValueW(hKey
, dwIndex
, szValueName
, &dwValueName
, NULL
, &dwType
, (BYTE
*)&Value
, &dwValue
) != ERROR_SUCCESS
)
238 if (dwType
== REG_SZ
)
241 * retry in case of string value
243 dwValue
= sizeof(szValue
);
244 dwValueName
= MAX_PATH
;
245 if (RegEnumValueW(hKey
, dwIndex
, szValueName
, &dwValueName
, NULL
, NULL
, (BYTE
*)szValue
, &dwValue
) != ERROR_SUCCESS
)
252 if (!wcscmp(szValueName
, L
"CursorSize"))
255 GuiData
->CursorSize
= Value
;
256 else if (Value
== 0x64)
257 GuiData
->CursorSize
= Value
;
259 else if (!wcscmp(szValueName
, L
"FaceName"))
261 wcscpy(GuiData
->FontName
, szValue
);
263 else if (!wcscmp(szValueName
, L
"FontSize"))
265 GuiData
->FontSize
= Value
;
267 else if (!wcscmp(szValueName
, L
"FontWeight"))
269 GuiData
->FontWeight
= Value
;
271 else if (!wcscmp(szValueName
, L
"HistoryNoDup"))
273 GuiData
->HistoryNoDup
= Value
;
275 else if (!wcscmp(szValueName
, L
"WindowSize"))
277 GuiData
->WindowSize
= Value
;
279 else if (!wcscmp(szValueName
, L
"FullScreen"))
281 GuiData
->FullScreen
= Value
;
283 else if (!wcscmp(szValueName
, L
"QuickEdit"))
285 GuiData
->QuickEdit
= Value
;
287 else if (!wcscmp(szValueName
, L
"InsertMode"))
289 GuiData
->InsertMode
= Value
;
294 GuiConsoleUseDefaults(PGUI_CONSOLE_DATA GuiData
)
297 * init guidata with default properties
300 wcscpy(GuiData
->FontName
, L
"Bitstream Vera Sans Mono");
301 GuiData
->FontSize
= 0x0008000C; // font is 8x12
302 GuiData
->WindowSize
= 0x00190050; // default window size is 25x80
303 GuiData
->FontWeight
= FW_NORMAL
;
304 GuiData
->CursorSize
= 0;
305 GuiData
->HistoryNoDup
= FALSE
;
306 GuiData
->FullScreen
= FALSE
;
307 GuiData
->QuickEdit
= FALSE
;
308 GuiData
->InsertMode
= TRUE
;
314 GuiConsoleHandleNcCreate(HWND hWnd
, CREATESTRUCTW
*Create
)
317 PCSRSS_CONSOLE Console
= (PCSRSS_CONSOLE
) Create
->lpCreateParams
;
318 PGUI_CONSOLE_DATA GuiData
= (PGUI_CONSOLE_DATA
)Console
->PrivateData
;
322 PCSRSS_PROCESS_DATA ProcessData
;
327 DPRINT1("GuiConsoleNcCreate: HeapAlloc failed\n");
331 GuiConsoleUseDefaults(GuiData
);
332 if (Console
->ProcessList
.Flink
!= &Console
->ProcessList
)
334 ProcessData
= CONTAINING_RECORD(Console
->ProcessList
.Flink
, CSRSS_PROCESS_DATA
, ProcessEntry
);
335 if (GuiConsoleOpenUserSettings(hWnd
, PtrToUlong(ProcessData
->ProcessId
), &hKey
, KEY_READ
))
337 GuiConsoleReadUserSettings(hKey
, GuiData
);
342 Console
->Size
.X
= LOWORD(GuiData
->WindowSize
);
343 Console
->Size
.Y
= HIWORD(GuiData
->WindowSize
);
345 InitializeCriticalSection(&GuiData
->Lock
);
347 GuiData
->LineBuffer
= (PWCHAR
)HeapAlloc(Win32CsrApiHeap
, HEAP_ZERO_MEMORY
,
348 Console
->Size
.X
* sizeof(WCHAR
));
350 GuiData
->Font
= CreateFontW(LOWORD(GuiData
->FontSize
),
351 0, //HIWORD(GuiData->FontSize),
359 OUT_DEFAULT_PRECIS
, CLIP_DEFAULT_PRECIS
,
360 NONANTIALIASED_QUALITY
, FIXED_PITCH
| FF_DONTCARE
,
362 if (NULL
== GuiData
->Font
)
364 DPRINT1("GuiConsoleNcCreate: CreateFont failed\n");
365 DeleteCriticalSection(&GuiData
->Lock
);
366 HeapFree(Win32CsrApiHeap
, 0, GuiData
);
372 DPRINT1("GuiConsoleNcCreate: GetDC failed\n");
373 DeleteObject(GuiData
->Font
);
374 DeleteCriticalSection(&GuiData
->Lock
);
375 HeapFree(Win32CsrApiHeap
, 0, GuiData
);
378 OldFont
= SelectObject(Dc
, GuiData
->Font
);
381 DPRINT1("GuiConsoleNcCreate: SelectObject failed\n");
383 DeleteObject(GuiData
->Font
);
384 DeleteCriticalSection(&GuiData
->Lock
);
385 HeapFree(Win32CsrApiHeap
, 0, GuiData
);
388 if (! GetTextMetricsW(Dc
, &Metrics
))
390 DPRINT1("GuiConsoleNcCreate: GetTextMetrics failed\n");
391 SelectObject(Dc
, OldFont
);
393 DeleteObject(GuiData
->Font
);
394 DeleteCriticalSection(&GuiData
->Lock
);
395 HeapFree(Win32CsrApiHeap
, 0, GuiData
);
398 GuiData
->CharWidth
= Metrics
.tmMaxCharWidth
;
399 GuiData
->CharHeight
= Metrics
.tmHeight
+ Metrics
.tmExternalLeading
;
400 SelectObject(Dc
, OldFont
);
403 GuiData
->CursorBlinkOn
= TRUE
;
404 GuiData
->ForceCursorOff
= FALSE
;
406 GuiData
->Selection
.left
= -1;
407 DPRINT("Console %p GuiData %p\n", Console
, GuiData
);
408 Console
->PrivateData
= GuiData
;
409 SetWindowLongPtrW(hWnd
, GWL_USERDATA
, (DWORD_PTR
) Console
);
411 GetWindowRect(hWnd
, &Rect
);
412 Rect
.right
= Rect
.left
+ Console
->Size
.X
* GuiData
->CharWidth
+
413 2 * GetSystemMetrics(SM_CXFIXEDFRAME
);
414 Rect
.bottom
= Rect
.top
+ Console
->Size
.Y
* GuiData
->CharHeight
+
415 2 * GetSystemMetrics(SM_CYFIXEDFRAME
) + GetSystemMetrics(SM_CYCAPTION
);
416 MoveWindow(hWnd
, Rect
.left
, Rect
.top
, Rect
.right
- Rect
.left
,
417 Rect
.bottom
- Rect
.top
, FALSE
);
419 SetTimer(hWnd
, 1, CURSOR_BLINK_TIME
, NULL
);
420 SetEvent(GuiData
->hGuiInitEvent
);
422 return (BOOL
) DefWindowProcW(hWnd
, WM_NCCREATE
, 0, (LPARAM
) Create
);
425 static COLORREF FASTCALL
426 GuiConsoleRGBFromAttribute(BYTE Attribute
)
428 int Red
= (Attribute
& 0x04 ? (Attribute
& 0x08 ? 0xff : 0x80) : 0x00);
429 int Green
= (Attribute
& 0x02 ? (Attribute
& 0x08 ? 0xff : 0x80) : 0x00);
430 int Blue
= (Attribute
& 0x01 ? (Attribute
& 0x08 ? 0xff : 0x80) : 0x00);
432 return RGB(Red
, Green
, Blue
);
436 GuiConsoleSetTextColors(HDC Dc
, BYTE Attribute
)
438 SetTextColor(Dc
, GuiConsoleRGBFromAttribute(Attribute
& 0x0f));
439 SetBkColor(Dc
, GuiConsoleRGBFromAttribute((Attribute
& 0xf0) >> 4));
443 GuiConsoleGetLogicalCursorPos(PCSRSS_SCREEN_BUFFER Buff
, ULONG
*CursorX
, ULONG
*CursorY
)
445 *CursorX
= Buff
->CurrentX
;
446 if (Buff
->CurrentY
< Buff
->ShowY
)
448 *CursorY
= Buff
->MaxY
- Buff
->ShowY
+ Buff
->CurrentY
;
452 *CursorY
= Buff
->CurrentY
- Buff
->ShowY
;
458 GuiConsoleUpdateSelection(HWND hWnd
, PRECT rc
, PGUI_CONSOLE_DATA GuiData
)
460 RECT oldRect
= GuiData
->Selection
;
464 RECT changeRect
= *rc
;
466 GuiData
->Selection
= *rc
;
468 changeRect
.left
*= GuiData
->CharWidth
;
469 changeRect
.top
*= GuiData
->CharHeight
;
470 changeRect
.right
*= GuiData
->CharWidth
;
471 changeRect
.bottom
*= GuiData
->CharHeight
;
473 if(rc
->left
!= oldRect
.left
||
474 rc
->top
!= oldRect
.top
||
475 rc
->right
!= oldRect
.right
||
476 rc
->bottom
!= oldRect
.bottom
)
478 if(oldRect
.left
!= -1)
482 oldRect
.left
*= GuiData
->CharWidth
;
483 oldRect
.top
*= GuiData
->CharHeight
;
484 oldRect
.right
*= GuiData
->CharWidth
;
485 oldRect
.bottom
*= GuiData
->CharHeight
;
487 /* calculate the region that needs to be updated */
488 if((rgn1
= CreateRectRgnIndirect(&oldRect
)))
490 if((rgn2
= CreateRectRgnIndirect(&changeRect
)))
492 if(CombineRgn(rgn1
, rgn2
, rgn1
, RGN_XOR
) != ERROR
)
494 InvalidateRgn(hWnd
, rgn1
, FALSE
);
504 InvalidateRect(hWnd
, &changeRect
, FALSE
);
508 else if(oldRect
.left
!= -1)
510 /* clear the selection */
511 GuiData
->Selection
.left
= -1;
512 oldRect
.left
*= GuiData
->CharWidth
;
513 oldRect
.top
*= GuiData
->CharHeight
;
514 oldRect
.right
*= GuiData
->CharWidth
;
515 oldRect
.bottom
*= GuiData
->CharHeight
;
516 InvalidateRect(hWnd
, &oldRect
, FALSE
);
522 GuiConsolePaint(PCSRSS_CONSOLE Console
,
523 PGUI_CONSOLE_DATA GuiData
,
527 PCSRSS_SCREEN_BUFFER Buff
;
528 ULONG TopLine
, BottomLine
, LeftChar
, RightChar
;
529 ULONG Line
, Char
, Start
;
532 BYTE LastAttribute
, Attribute
;
533 ULONG CursorX
, CursorY
, CursorHeight
;
534 HBRUSH CursorBrush
, OldBrush
;
537 Buff
= Console
->ActiveBuffer
;
539 TopLine
= rc
->top
/ GuiData
->CharHeight
;
540 BottomLine
= (rc
->bottom
+ (GuiData
->CharHeight
- 1)) / GuiData
->CharHeight
- 1;
541 LeftChar
= rc
->left
/ GuiData
->CharWidth
;
542 RightChar
= (rc
->right
+ (GuiData
->CharWidth
- 1)) / GuiData
->CharWidth
- 1;
543 LastAttribute
= Buff
->Buffer
[(TopLine
* Buff
->MaxX
+ LeftChar
) * 2 + 1];
545 GuiConsoleSetTextColors(hDC
,
548 EnterCriticalSection(&Buff
->Header
.Lock
);
550 OldFont
= SelectObject(hDC
,
553 for (Line
= TopLine
; Line
<= BottomLine
; Line
++)
555 if (Line
+ Buff
->ShowY
< Buff
->MaxY
)
557 From
= Buff
->Buffer
+ ((Line
+ Buff
->ShowY
) * Buff
->MaxX
+ LeftChar
) * 2;
561 From
= Buff
->Buffer
+
562 ((Line
- (Buff
->MaxY
- Buff
->ShowY
)) * Buff
->MaxX
+ LeftChar
) * 2;
565 To
= GuiData
->LineBuffer
;
567 for (Char
= LeftChar
; Char
<= RightChar
; Char
++)
569 if (*(From
+ 1) != LastAttribute
)
572 Start
* GuiData
->CharWidth
,
573 Line
* GuiData
->CharHeight
,
577 To
= GuiData
->LineBuffer
;
578 Attribute
= *(From
+ 1);
579 if (Attribute
!= LastAttribute
)
581 GuiConsoleSetTextColors(hDC
,
583 LastAttribute
= Attribute
;
587 MultiByteToWideChar(Console
->OutputCodePage
,
598 Start
* GuiData
->CharWidth
,
599 Line
* GuiData
->CharHeight
,
601 RightChar
- Start
+ 1);
604 if (Buff
->CursorInfo
.bVisible
&& GuiData
->CursorBlinkOn
&&
605 !GuiData
->ForceCursorOff
)
607 GuiConsoleGetLogicalCursorPos(Buff
,
610 if (LeftChar
<= CursorX
&& CursorX
<= RightChar
&&
611 TopLine
<= CursorY
&& CursorY
<= BottomLine
)
613 CursorHeight
= (GuiData
->CharHeight
* Buff
->CursorInfo
.dwSize
) / 100;
614 if (CursorHeight
< 1)
618 From
= Buff
->Buffer
+ (Buff
->CurrentY
* Buff
->MaxX
+ Buff
->CurrentX
) * 2 + 1;
619 CursorBrush
= CreateSolidBrush(GuiConsoleRGBFromAttribute(*From
));
620 OldBrush
= SelectObject(hDC
,
623 CursorX
* GuiData
->CharWidth
,
624 CursorY
* GuiData
->CharHeight
+ (GuiData
->CharHeight
- CursorHeight
),
630 DeleteObject(CursorBrush
);
634 LeaveCriticalSection(&Buff
->Header
.Lock
);
641 GuiConsoleHandlePaint(HWND hWnd
, HDC hDCPaint
)
645 PCSRSS_CONSOLE Console
;
646 PGUI_CONSOLE_DATA GuiData
;
648 hDC
= BeginPaint(hWnd
, &ps
);
650 ps
.rcPaint
.left
< ps
.rcPaint
.right
&&
651 ps
.rcPaint
.top
< ps
.rcPaint
.bottom
)
653 GuiConsoleGetDataPointers(hWnd
,
656 if (Console
!= NULL
&& GuiData
!= NULL
&&
657 Console
->ActiveBuffer
!= NULL
)
659 EnterCriticalSection(&GuiData
->Lock
);
661 GuiConsolePaint(Console
,
666 if (GuiData
->Selection
.left
!= -1)
668 RECT rc
= GuiData
->Selection
;
670 rc
.left
*= GuiData
->CharWidth
;
671 rc
.top
*= GuiData
->CharHeight
;
672 rc
.right
*= GuiData
->CharWidth
;
673 rc
.bottom
*= GuiData
->CharHeight
;
675 /* invert the selection */
676 if (IntersectRect(&rc
,
689 LeaveCriticalSection(&GuiData
->Lock
);
697 GuiConsoleHandleKey(HWND hWnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
699 PCSRSS_CONSOLE Console
;
700 PGUI_CONSOLE_DATA GuiData
;
703 GuiConsoleGetDataPointers(hWnd
, &Console
, &GuiData
);
705 Message
.message
= msg
;
706 Message
.wParam
= wParam
;
707 Message
.lParam
= lParam
;
709 if(msg
== WM_CHAR
|| msg
== WM_SYSKEYDOWN
)
711 /* clear the selection */
712 GuiConsoleUpdateSelection(hWnd
, NULL
, GuiData
);
715 ConioProcessKey(&Message
, Console
, FALSE
);
719 GuiIntDrawRegion(PGUI_CONSOLE_DATA GuiData
, HWND Wnd
, RECT
*Region
)
723 RegionRect
.left
= Region
->left
* GuiData
->CharWidth
;
724 RegionRect
.top
= Region
->top
* GuiData
->CharHeight
;
725 RegionRect
.right
= (Region
->right
+ 1) * GuiData
->CharWidth
;
726 RegionRect
.bottom
= (Region
->bottom
+ 1) * GuiData
->CharHeight
;
728 InvalidateRect(Wnd
, &RegionRect
, FALSE
);
732 GuiDrawRegion(PCSRSS_CONSOLE Console
, RECT
*Region
)
734 PGUI_CONSOLE_DATA GuiData
= (PGUI_CONSOLE_DATA
) Console
->PrivateData
;
736 if (NULL
!= Console
->hWindow
&& NULL
!= GuiData
)
738 GuiIntDrawRegion(GuiData
, Console
->hWindow
, Region
);
743 GuiInvalidateCell(PGUI_CONSOLE_DATA GuiData
, HWND Wnd
, UINT x
, UINT y
)
752 GuiIntDrawRegion(GuiData
, Wnd
, &CellRect
);
756 GuiWriteStream(PCSRSS_CONSOLE Console
, RECT
*Region
, LONG CursorStartX
, LONG CursorStartY
,
757 UINT ScrolledLines
, CHAR
*Buffer
, UINT Length
)
759 PGUI_CONSOLE_DATA GuiData
= (PGUI_CONSOLE_DATA
) Console
->PrivateData
;
760 PCSRSS_SCREEN_BUFFER Buff
= Console
->ActiveBuffer
;
761 LONG CursorEndX
, CursorEndY
;
764 if (NULL
== Console
->hWindow
|| NULL
== GuiData
)
769 if (0 != ScrolledLines
)
773 ScrollRect
.right
= Console
->Size
.X
* GuiData
->CharWidth
;
774 ScrollRect
.bottom
= Region
->top
* GuiData
->CharHeight
;
776 if (GuiData
->Selection
.left
!= -1)
778 /* scroll the selection */
779 if (GuiData
->Selection
.top
> ScrolledLines
)
781 GuiData
->Selection
.top
-= ScrolledLines
;
782 GuiData
->Selection
.bottom
-= ScrolledLines
;
784 else if (GuiData
->Selection
.bottom
< ScrolledLines
)
786 GuiData
->Selection
.left
= -1;
790 GuiData
->Selection
.top
= 0;
791 GuiData
->Selection
.bottom
-= ScrolledLines
;
795 ScrollWindowEx(Console
->hWindow
,
797 -(ScrolledLines
* GuiData
->CharHeight
),
805 GuiIntDrawRegion(GuiData
, Console
->hWindow
, Region
);
807 if (CursorStartX
< Region
->left
|| Region
->right
< CursorStartX
808 || CursorStartY
< Region
->top
|| Region
->bottom
< CursorStartY
)
810 GuiInvalidateCell(GuiData
, Console
->hWindow
, CursorStartX
, CursorStartY
);
813 ConioPhysicalToLogical(Buff
, Buff
->CurrentX
, Buff
->CurrentY
,
814 &CursorEndX
, &CursorEndY
);
815 if ((CursorEndX
< Region
->left
|| Region
->right
< CursorEndX
816 || CursorEndY
< Region
->top
|| Region
->bottom
< CursorEndY
)
817 && (CursorEndX
!= CursorStartX
|| CursorEndY
!= CursorStartY
))
819 GuiInvalidateCell(GuiData
, Console
->hWindow
, CursorEndX
, CursorEndY
);
824 GuiSetCursorInfo(PCSRSS_CONSOLE Console
, PCSRSS_SCREEN_BUFFER Buff
)
828 if (Console
->ActiveBuffer
== Buff
)
830 ConioPhysicalToLogical(Buff
, Buff
->CurrentX
, Buff
->CurrentY
,
831 &UpdateRect
.left
, &UpdateRect
.top
);
832 UpdateRect
.right
= UpdateRect
.left
;
833 UpdateRect
.bottom
= UpdateRect
.top
;
834 ConioDrawRegion(Console
, &UpdateRect
);
841 GuiSetScreenInfo(PCSRSS_CONSOLE Console
, PCSRSS_SCREEN_BUFFER Buff
, UINT OldCursorX
, UINT OldCursorY
)
845 if (Console
->ActiveBuffer
== Buff
)
847 /* Redraw char at old position (removes cursor) */
848 UpdateRect
.left
= OldCursorX
;
849 UpdateRect
.top
= OldCursorY
;
850 UpdateRect
.right
= OldCursorX
;
851 UpdateRect
.bottom
= OldCursorY
;
852 ConioDrawRegion(Console
, &UpdateRect
);
853 /* Redraw char at new position (shows cursor) */
854 ConioPhysicalToLogical(Buff
, Buff
->CurrentX
, Buff
->CurrentY
,
855 &(UpdateRect
.left
), &(UpdateRect
.top
));
856 UpdateRect
.right
= UpdateRect
.left
;
857 UpdateRect
.bottom
= UpdateRect
.top
;
858 ConioDrawRegion(Console
, &UpdateRect
);
865 GuiConsoleHandleTimer(HWND hWnd
)
867 PCSRSS_CONSOLE Console
;
868 PGUI_CONSOLE_DATA GuiData
;
870 ULONG CursorX
, CursorY
;
872 GuiConsoleGetDataPointers(hWnd
, &Console
, &GuiData
);
873 GuiData
->CursorBlinkOn
= ! GuiData
->CursorBlinkOn
;
875 GuiConsoleGetLogicalCursorPos(Console
->ActiveBuffer
, &CursorX
, &CursorY
);
876 CursorRect
.left
= CursorX
;
877 CursorRect
.top
= CursorY
;
878 CursorRect
.right
= CursorX
;
879 CursorRect
.bottom
= CursorY
;
880 GuiDrawRegion(Console
, &CursorRect
);
884 GuiConsoleHandleClose(HWND hWnd
)
886 PCSRSS_CONSOLE Console
;
887 PGUI_CONSOLE_DATA GuiData
;
888 PLIST_ENTRY current_entry
;
889 PCSRSS_PROCESS_DATA current
;
891 GuiConsoleGetDataPointers(hWnd
, &Console
, &GuiData
);
893 EnterCriticalSection(&Console
->Header
.Lock
);
895 current_entry
= Console
->ProcessList
.Flink
;
896 while (current_entry
!= &Console
->ProcessList
)
898 current
= CONTAINING_RECORD(current_entry
, CSRSS_PROCESS_DATA
, ProcessEntry
);
899 current_entry
= current_entry
->Flink
;
901 ConioConsoleCtrlEvent(CTRL_CLOSE_EVENT
, current
);
904 LeaveCriticalSection(&Console
->Header
.Lock
);
908 GuiConsoleHandleNcDestroy(HWND hWnd
)
910 PCSRSS_CONSOLE Console
;
911 PGUI_CONSOLE_DATA GuiData
;
913 GuiConsoleGetDataPointers(hWnd
, &Console
, &GuiData
);
915 Console
->PrivateData
= NULL
;
916 DeleteCriticalSection(&GuiData
->Lock
);
917 GetSystemMenu(hWnd
, TRUE
);
918 if (GuiData
->ConsoleLibrary
)
919 FreeLibrary(GuiData
->ConsoleLibrary
);
921 HeapFree(Win32CsrApiHeap
, 0, GuiData
);
925 GuiConsoleLeftMouseDown(HWND hWnd
, LPARAM lParam
)
927 PCSRSS_CONSOLE Console
;
928 PGUI_CONSOLE_DATA GuiData
;
932 GuiConsoleGetDataPointers(hWnd
, &Console
, &GuiData
);
933 if (Console
== NULL
|| GuiData
== NULL
) return;
935 pt
= MAKEPOINTS(lParam
);
937 rc
.left
= pt
.x
/ GuiData
->CharWidth
;
938 rc
.top
= pt
.y
/ GuiData
->CharHeight
;
939 rc
.right
= rc
.left
+ 1;
940 rc
.bottom
= rc
.top
+ 1;
942 GuiData
->SelectionStart
.x
= rc
.left
;
943 GuiData
->SelectionStart
.y
= rc
.top
;
947 GuiData
->MouseDown
= TRUE
;
949 GuiConsoleUpdateSelection(hWnd
, &rc
, GuiData
);
953 GuiConsoleLeftMouseUp(HWND hWnd
, LPARAM lParam
)
955 PCSRSS_CONSOLE Console
;
956 PGUI_CONSOLE_DATA GuiData
;
960 GuiConsoleGetDataPointers(hWnd
, &Console
, &GuiData
);
961 if (Console
== NULL
|| GuiData
== NULL
) return;
962 if (GuiData
->Selection
.left
== -1 || !GuiData
->MouseDown
) return;
964 pt
= MAKEPOINTS(lParam
);
966 rc
.left
= GuiData
->SelectionStart
.x
;
967 rc
.top
= GuiData
->SelectionStart
.y
;
968 rc
.right
= (pt
.x
>= 0 ? (pt
.x
/ GuiData
->CharWidth
) + 1 : 0);
969 rc
.bottom
= (pt
.y
>= 0 ? (pt
.y
/ GuiData
->CharHeight
) + 1 : 0);
971 /* exchange left/top with right/bottom if required */
972 if(rc
.left
>= rc
.right
)
976 rc
.left
= max(rc
.right
- 1, 0);
979 if(rc
.top
>= rc
.bottom
)
983 rc
.top
= max(rc
.bottom
- 1, 0);
987 GuiData
->MouseDown
= FALSE
;
989 GuiConsoleUpdateSelection(hWnd
, &rc
, GuiData
);
995 GuiConsoleMouseMove(HWND hWnd
, WPARAM wParam
, LPARAM lParam
)
997 PCSRSS_CONSOLE Console
;
998 PGUI_CONSOLE_DATA GuiData
;
1002 if (!(wParam
& MK_LBUTTON
)) return;
1004 GuiConsoleGetDataPointers(hWnd
, &Console
, &GuiData
);
1005 if (Console
== NULL
|| GuiData
== NULL
|| !GuiData
->MouseDown
) return;
1007 pt
= MAKEPOINTS(lParam
);
1009 rc
.left
= GuiData
->SelectionStart
.x
;
1010 rc
.top
= GuiData
->SelectionStart
.y
;
1011 rc
.right
= (pt
.x
>= 0 ? (pt
.x
/ GuiData
->CharWidth
) + 1 : 0);
1012 if (Console
->Size
.X
< rc
.right
)
1014 rc
.right
= Console
->Size
.X
;
1016 rc
.bottom
= (pt
.y
>= 0 ? (pt
.y
/ GuiData
->CharHeight
) + 1 : 0);
1017 if (Console
->Size
.Y
< rc
.bottom
)
1019 rc
.bottom
= Console
->Size
.Y
;
1022 /* exchange left/top with right/bottom if required */
1023 if(rc
.left
>= rc
.right
)
1027 rc
.left
= max(rc
.right
- 1, 0);
1030 if(rc
.top
>= rc
.bottom
)
1034 rc
.top
= max(rc
.bottom
- 1, 0);
1035 rc
.bottom
= tmp
+ 1;
1038 GuiConsoleUpdateSelection(hWnd
, &rc
, GuiData
);
1041 static VOID FASTCALL
1042 GuiConsoleRightMouseDown(HWND hWnd
)
1044 PCSRSS_CONSOLE Console
;
1045 PGUI_CONSOLE_DATA GuiData
;
1047 GuiConsoleGetDataPointers(hWnd
, &Console
, &GuiData
);
1048 if (Console
== NULL
|| GuiData
== NULL
) return;
1050 if (GuiData
->Selection
.left
== -1)
1052 /* FIXME - paste text from clipboard */
1056 /* FIXME - copy selection to clipboard */
1058 GuiConsoleUpdateSelection(hWnd
, NULL
, GuiData
);
1064 GuiConsoleShowConsoleProperties(HWND hWnd
, BOOL Defaults
)
1066 PCSRSS_CONSOLE Console
;
1067 PGUI_CONSOLE_DATA GuiData
;
1068 APPLET_PROC CPLFunc
;
1069 TCHAR szBuffer
[MAX_PATH
];
1071 GuiConsoleGetDataPointers(hWnd
, &Console
, &GuiData
);
1073 if (GuiData
== NULL
)
1075 DPRINT1("GuiConsoleGetDataPointers failed\n");
1078 if (GuiData
->ConsoleLibrary
== NULL
)
1080 GetWindowsDirectory(szBuffer
,MAX_PATH
);
1081 _tcscat(szBuffer
, _T("\\system32\\console.dll"));
1082 GuiData
->ConsoleLibrary
= LoadLibrary(szBuffer
);
1084 if (GuiData
->ConsoleLibrary
== NULL
)
1086 DPRINT1("failed to load console.dll");
1091 CPLFunc
= (APPLET_PROC
) GetProcAddress(GuiData
->ConsoleLibrary
, _T("CPlApplet"));
1094 DPRINT("Error: Console.dll misses CPlApplet export\n");
1098 if (!CPLFunc(hWnd
, CPL_INIT
, 0, 0))
1100 DPRINT("Error: failed to initialize console.dll\n");
1104 if (CPLFunc(hWnd
, CPL_GETCOUNT
, 0, 0) != 1)
1106 DPRINT("Error: console.dll returned unexpected CPL count\n");
1110 CPLFunc(hWnd
, CPL_DBLCLK
, 0, Defaults
);
1114 // read back the changes from console.dll
1116 // if the changes are system-wide then
1117 // console.dll should have written it to
1120 // if the changes only apply to this session
1121 // then exchange this info with console.dll in
1124 static LRESULT FASTCALL
1125 GuiConsoleHandleSysMenuCommand(HWND hWnd
, WPARAM wParam
, LPARAM lParam
)
1127 DPRINT1("GuiConsoleHandleSysMenuCommand entered %d\n", wParam
);
1140 GuiConsoleShowConsoleProperties(hWnd
, TRUE
);
1142 case IDS_PROPERTIES
:
1143 GuiConsoleShowConsoleProperties(hWnd
, FALSE
);
1151 static BOOLEAN FASTCALL
1152 InsertItem(HMENU hMenu
, INT fType
, INT fMask
, INT fState
, HMENU hSubMenu
, INT ResourceId
)
1154 MENUITEMINFO MenuItemInfo
;
1155 TCHAR szBuffer
[MAX_PATH
];
1157 memset(&MenuItemInfo
, 0x0, sizeof(MENUITEMINFO
));
1158 MenuItemInfo
.cbSize
= sizeof (MENUITEMINFO
);
1159 MenuItemInfo
.fMask
= fMask
;
1160 MenuItemInfo
.fType
= fType
;
1161 MenuItemInfo
.fState
= fState
;
1162 MenuItemInfo
.hSubMenu
= hSubMenu
;
1163 MenuItemInfo
.wID
= ResourceId
;
1165 if (fType
!= MFT_SEPARATOR
)
1167 MenuItemInfo
.cch
= LoadString(Win32CsrDllHandle
, ResourceId
, szBuffer
, MAX_PATH
);
1168 if (!MenuItemInfo
.cch
)
1170 DPRINT("LoadString failed ResourceId %d Error %x\n", ResourceId
, GetLastError());
1173 MenuItemInfo
.dwTypeData
= szBuffer
;
1176 if (InsertMenuItem(hMenu
, ResourceId
, FALSE
, &MenuItemInfo
))
1179 DPRINT("InsertMenuItem failed Last error %x\n", GetLastError());
1185 static VOID FASTCALL
1186 GuiConsoleCreateSysMenu(HWND hWnd
)
1192 hMenu
= GetSystemMenu(hWnd
, FALSE
);
1195 DPRINT("GetSysMenu failed\n");
1198 /* insert seperator */
1199 InsertItem(hMenu
, MFT_SEPARATOR
, MIIM_FTYPE
, 0, NULL
, -1);
1201 /* create submenu */
1202 hSubMenu
= CreatePopupMenu();
1203 InsertItem(hSubMenu
, MIIM_STRING
, MIIM_ID
| MIIM_FTYPE
| MIIM_STRING
, 0, NULL
, IDS_MARK
);
1204 InsertItem(hSubMenu
, MIIM_STRING
, MIIM_ID
| MIIM_FTYPE
| MIIM_STRING
| MIIM_STATE
, MFS_GRAYED
, NULL
, IDS_COPY
);
1205 InsertItem(hSubMenu
, MIIM_STRING
, MIIM_ID
| MIIM_FTYPE
| MIIM_STRING
, 0, NULL
, IDS_PASTE
);
1206 InsertItem(hSubMenu
, MIIM_STRING
, MIIM_ID
| MIIM_FTYPE
| MIIM_STRING
, 0, NULL
, IDS_SELECTALL
);
1207 InsertItem(hSubMenu
, MIIM_STRING
, MIIM_ID
| MIIM_FTYPE
| MIIM_STRING
, 0, NULL
, IDS_SCROLL
);
1208 InsertItem(hSubMenu
, MIIM_STRING
, MIIM_ID
| MIIM_FTYPE
| MIIM_STRING
, 0, NULL
, IDS_FIND
);
1209 InsertItem(hMenu
, MIIM_STRING
, MIIM_ID
| MIIM_FTYPE
| MIIM_STRING
| MIIM_SUBMENU
, 0, hSubMenu
, IDS_EDIT
);
1211 /* create default/properties item */
1212 InsertItem(hMenu
, MIIM_STRING
, MIIM_ID
| MIIM_FTYPE
| MIIM_STRING
, 0, NULL
, IDS_DEFAULTS
);
1213 InsertItem(hMenu
, MIIM_STRING
, MIIM_ID
| MIIM_FTYPE
| MIIM_STRING
, 0, NULL
, IDS_PROPERTIES
);
1217 static LRESULT CALLBACK
1218 GuiConsoleWndProc(HWND hWnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
1225 Result
= (LRESULT
) GuiConsoleHandleNcCreate(hWnd
, (CREATESTRUCTW
*) lParam
);
1228 GuiConsoleHandlePaint(hWnd
, (HDC
)wParam
);
1235 GuiConsoleHandleKey(hWnd
, msg
, wParam
, lParam
);
1238 GuiConsoleHandleTimer(hWnd
);
1241 GuiConsoleHandleClose(hWnd
);
1244 GuiConsoleHandleNcDestroy(hWnd
);
1246 case WM_LBUTTONDOWN
:
1247 GuiConsoleLeftMouseDown(hWnd
, lParam
);
1250 GuiConsoleLeftMouseUp(hWnd
, lParam
);
1252 case WM_RBUTTONDOWN
:
1253 GuiConsoleRightMouseDown(hWnd
);
1256 GuiConsoleMouseMove(hWnd
, wParam
, lParam
);
1259 return GuiConsoleHandleSysMenuCommand(hWnd
, wParam
, lParam
);
1261 Result
= DefWindowProcW(hWnd
, msg
, wParam
, lParam
);
1268 static LRESULT CALLBACK
1269 GuiConsoleNotifyWndProc(HWND hWnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
1274 PWCHAR Buffer
, Title
;
1275 PCSRSS_CONSOLE Console
= (PCSRSS_CONSOLE
) lParam
;
1282 SetWindowLongW(hWnd
, GWL_USERDATA
, 0);
1284 case PM_CREATE_CONSOLE
:
1285 Buffer
= HeapAlloc(Win32CsrApiHeap
, 0,
1286 Console
->Title
.Length
+ sizeof(WCHAR
));
1289 memcpy(Buffer
, Console
->Title
.Buffer
, Console
->Title
.Length
);
1290 Buffer
[Console
->Title
.Length
/ sizeof(WCHAR
)] = L
'\0';
1297 NewWindow
= CreateWindowW(L
"ConsoleWindowClass",
1299 WS_OVERLAPPED
| WS_CAPTION
| WS_SYSMENU
| WS_MINIMIZEBOX
, // | WS_HSCROLL | WS_VSCROLL,
1306 (HINSTANCE
) GetModuleHandleW(NULL
),
1310 HeapFree(Win32CsrApiHeap
, 0, Buffer
);
1312 Console
->hWindow
= NewWindow
;
1313 if (NULL
!= NewWindow
)
1315 GuiConsoleCreateSysMenu(NewWindow
);
1316 //ShowScrollBar(NewWindow, SB_VERT, FALSE);
1317 //ShowScrollBar(NewWindow, SB_HORZ, FALSE);
1318 SetWindowLongW(hWnd
, GWL_USERDATA
, GetWindowLongW(hWnd
, GWL_USERDATA
) + 1);
1319 ShowWindow(NewWindow
, SW_SHOW
);
1321 return (LRESULT
) NewWindow
;
1322 case PM_DESTROY_CONSOLE
:
1323 /* Window creation is done using a PostMessage(), so it's possible that the
1324 * window that we want to destroy doesn't exist yet. So first empty the message
1326 while(PeekMessageW(&Msg
, NULL
, 0, 0, PM_REMOVE
))
1328 TranslateMessage(&Msg
);
1329 DispatchMessageW(&Msg
);
1331 DestroyWindow(Console
->hWindow
);
1332 Console
->hWindow
= NULL
;
1333 WindowCount
= GetWindowLongW(hWnd
, GWL_USERDATA
);
1335 SetWindowLongW(hWnd
, GWL_USERDATA
, WindowCount
);
1336 if (0 == WindowCount
)
1339 DestroyWindow(hWnd
);
1340 PrivateCsrssManualGuiCheck(-1);
1345 return DefWindowProcW(hWnd
, msg
, wParam
, lParam
);
1349 static DWORD STDCALL
1350 GuiConsoleGuiThread(PVOID Data
)
1353 PHANDLE GraphicsStartupEvent
= (PHANDLE
) Data
;
1355 NotifyWnd
= CreateWindowW(L
"Win32CsrCreateNotify",
1357 WS_OVERLAPPEDWINDOW
,
1364 (HINSTANCE
) GetModuleHandleW(NULL
),
1366 if (NULL
== NotifyWnd
)
1368 PrivateCsrssManualGuiCheck(-1);
1369 SetEvent(*GraphicsStartupEvent
);
1373 SetEvent(*GraphicsStartupEvent
);
1375 while(GetMessageW(&msg
, NULL
, 0, 0))
1377 TranslateMessage(&msg
);
1378 DispatchMessageW(&msg
);
1384 static BOOL FASTCALL
1389 if (NULL
== NotifyWnd
)
1391 PrivateCsrssManualGuiCheck(+1);
1394 wc
.cbSize
= sizeof(WNDCLASSEXW
);
1395 wc
.lpszClassName
= L
"Win32CsrCreateNotify";
1396 wc
.lpfnWndProc
= GuiConsoleNotifyWndProc
;
1398 wc
.hInstance
= (HINSTANCE
) GetModuleHandleW(NULL
);
1401 wc
.hbrBackground
= NULL
;
1402 wc
.lpszMenuName
= NULL
;
1406 if (RegisterClassExW(&wc
) == 0)
1408 DPRINT1("Failed to register notify wndproc\n");
1412 wc
.cbSize
= sizeof(WNDCLASSEXW
);
1413 wc
.lpszClassName
= L
"ConsoleWindowClass";
1414 wc
.lpfnWndProc
= GuiConsoleWndProc
;
1416 wc
.hInstance
= (HINSTANCE
) GetModuleHandleW(NULL
);
1417 wc
.hIcon
= LoadIconW(Win32CsrDllHandle
, MAKEINTRESOURCEW(1));
1418 wc
.hCursor
= LoadCursorW(NULL
, MAKEINTRESOURCEW(IDC_ARROW
));
1419 wc
.hbrBackground
= NULL
;
1420 wc
.lpszMenuName
= NULL
;
1423 wc
.hIconSm
= LoadImageW(Win32CsrDllHandle
, MAKEINTRESOURCEW(1), IMAGE_ICON
,
1424 GetSystemMetrics(SM_CXSMICON
), GetSystemMetrics(SM_CYSMICON
),
1426 if (RegisterClassExW(&wc
) == 0)
1428 DPRINT1("Failed to register console wndproc\n");
1436 GuiInitScreenBuffer(PCSRSS_CONSOLE Console
, PCSRSS_SCREEN_BUFFER Buffer
)
1438 Buffer
->DefaultAttrib
= 0x0f;
1442 GuiChangeTitle(PCSRSS_CONSOLE Console
)
1444 PWCHAR Buffer
, Title
;
1446 Buffer
= HeapAlloc(Win32CsrApiHeap
, 0,
1447 Console
->Title
.Length
+ sizeof(WCHAR
));
1450 memcpy(Buffer
, Console
->Title
.Buffer
, Console
->Title
.Length
);
1451 Buffer
[Console
->Title
.Length
/ sizeof(WCHAR
)] = L
'\0';
1458 SendMessageW(Console
->hWindow
, WM_SETTEXT
, 0, (LPARAM
) Title
);
1461 HeapFree(Win32CsrApiHeap
, 0, Buffer
);
1468 GuiChangeIcon(PCSRSS_CONSOLE Console
)
1470 SendMessageW(Console
->hWindow
, WM_SETICON
, ICON_BIG
, (LPARAM
)Console
->hWindowIcon
);
1471 SendMessageW(Console
->hWindow
, WM_SETICON
, ICON_SMALL
, (LPARAM
)Console
->hWindowIcon
);
1477 GuiCleanupConsole(PCSRSS_CONSOLE Console
)
1479 SendMessageW(NotifyWnd
, PM_DESTROY_CONSOLE
, 0, (LPARAM
) Console
);
1482 static CSRSS_CONSOLE_VTBL GuiVtbl
=
1484 GuiInitScreenBuffer
,
1495 GuiInitConsole(PCSRSS_CONSOLE Console
)
1497 HANDLE GraphicsStartupEvent
;
1498 HANDLE ThreadHandle
;
1499 PGUI_CONSOLE_DATA GuiData
;
1501 if (! ConsInitialized
)
1503 ConsInitialized
= TRUE
;
1506 ConsInitialized
= FALSE
;
1507 return STATUS_UNSUCCESSFUL
;
1511 Console
->Vtbl
= &GuiVtbl
;
1512 if (NULL
== NotifyWnd
)
1514 GraphicsStartupEvent
= CreateEventW(NULL
, FALSE
, FALSE
, NULL
);
1515 if (NULL
== GraphicsStartupEvent
)
1517 return STATUS_UNSUCCESSFUL
;
1520 ThreadHandle
= CreateThread(NULL
,
1522 GuiConsoleGuiThread
,
1523 (PVOID
) &GraphicsStartupEvent
,
1526 if (NULL
== ThreadHandle
)
1528 NtClose(GraphicsStartupEvent
);
1529 DPRINT1("Win32Csr: Failed to create graphics console thread. Expect problems\n");
1530 return STATUS_UNSUCCESSFUL
;
1532 SetThreadPriority(ThreadHandle
, THREAD_PRIORITY_HIGHEST
);
1533 CloseHandle(ThreadHandle
);
1535 WaitForSingleObject(GraphicsStartupEvent
, INFINITE
);
1536 CloseHandle(GraphicsStartupEvent
);
1538 if (NULL
== NotifyWnd
)
1540 DPRINT1("Win32Csr: Failed to create notification window.\n");
1541 return STATUS_UNSUCCESSFUL
;
1544 GuiData
= HeapAlloc(Win32CsrApiHeap
, HEAP_ZERO_MEMORY
,
1545 sizeof(GUI_CONSOLE_DATA
));
1548 DPRINT1("Win32Csr: Failed to create GUI_CONSOLE_DATA\n");
1549 return STATUS_UNSUCCESSFUL
;
1552 Console
->PrivateData
= (PVOID
) GuiData
;
1554 * we need to wait untill the GUI has been fully initialized
1555 * to retrieve custom settings i.e. WindowSize etc..
1556 * Ideally we could use SendNotifyMessage for this but its not
1560 GuiData
->hGuiInitEvent
= CreateEventW(NULL
, FALSE
, FALSE
, NULL
);
1561 /* create console */
1562 PostMessageW(NotifyWnd
, PM_CREATE_CONSOLE
, 0, (LPARAM
) Console
);
1564 /* wait untill initialization has finished */
1565 WaitForSingleObject(GuiData
->hGuiInitEvent
, INFINITE
);
1566 DPRINT("received event Console %p GuiData %p X %d Y %d\n", Console
, Console
->PrivateData
, Console
->Size
.X
, Console
->Size
.Y
);
1567 CloseHandle(GuiData
->hGuiInitEvent
);
1568 GuiData
->hGuiInitEvent
= NULL
;
1570 return STATUS_SUCCESS
;