1 /* $Id: guiconsole.c,v 1.11 2004/03/07 21:00:11 hbirr Exp $
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 ******************************************************************/
13 #include "guiconsole.h"
19 /* Not defined in any header file */
20 extern VOID STDCALL
PrivateCsrssManualGuiCheck(LONG Check
);
22 /* GLOBALS *******************************************************************/
24 typedef struct GUI_CONSOLE_DATA_TAG
32 CRITICAL_SECTION Lock
;
35 } GUI_CONSOLE_DATA
, *PGUI_CONSOLE_DATA
;
40 #define PM_CREATE_CONSOLE (WM_APP + 1)
41 #define PM_DESTROY_CONSOLE (WM_APP + 2)
43 #define CURSOR_BLINK_TIME 500
45 static BOOL Initialized
= FALSE
;
46 static HWND NotifyWnd
;
48 /* FUNCTIONS *****************************************************************/
51 GuiConsoleGetDataPointers(HWND hWnd
, PCSRSS_CONSOLE
*Console
, PGUI_CONSOLE_DATA
*GuiData
)
53 *Console
= (PCSRSS_CONSOLE
) GetWindowLongW(hWnd
, GWL_USERDATA
);
54 *GuiData
= (NULL
== *Console
? NULL
: (*Console
)->PrivateData
);
58 GuiConsoleHandleNcCreate(HWND hWnd
, CREATESTRUCTW
*Create
)
61 PCSRSS_CONSOLE Console
= (PCSRSS_CONSOLE
) Create
->lpCreateParams
;
62 PGUI_CONSOLE_DATA GuiData
;
68 GuiData
= HeapAlloc(Win32CsrApiHeap
, HEAP_ZERO_MEMORY
,
69 sizeof(GUI_CONSOLE_DATA
) +
70 (Console
->Size
.X
+ 1) * sizeof(WCHAR
));
73 DPRINT1("GuiConsoleNcCreate: HeapAlloc failed\n");
77 Status
= RtlInitializeCriticalSection(&GuiData
->Lock
);
78 if (!NT_SUCCESS(Status
))
80 DPRINT1("RtlInitializeCriticalSection failed, Status=%x\n", Status
);
81 HeapFree(Win32CsrApiHeap
, 0, GuiData
);
85 GuiData
->LineBuffer
= (PWCHAR
)(GuiData
+ 1);
87 GuiData
->Font
= CreateFontW(12, 0, 0, TA_BASELINE
, FW_NORMAL
,
88 FALSE
, FALSE
, FALSE
, ANSI_CHARSET
,
89 OUT_DEFAULT_PRECIS
, CLIP_DEFAULT_PRECIS
,
90 DEFAULT_QUALITY
, FIXED_PITCH
| FF_DONTCARE
,
91 L
"Bitstream Vera Sans Mono");
92 if (NULL
== GuiData
->Font
)
94 DPRINT1("GuiConsoleNcCreate: CreateFont failed\n");
95 RtlDeleteCriticalSection(&GuiData
->Lock
);
96 HeapFree(Win32CsrApiHeap
, 0, GuiData
);
102 DPRINT1("GuiConsoleNcCreate: GetDC failed\n");
103 DeleteObject(GuiData
->Font
);
104 RtlDeleteCriticalSection(&GuiData
->Lock
);
105 HeapFree(Win32CsrApiHeap
, 0, GuiData
);
108 OldFont
= SelectObject(Dc
, GuiData
->Font
);
111 DPRINT1("GuiConsoleNcCreate: SelectObject failed\n");
113 DeleteObject(GuiData
->Font
);
114 RtlDeleteCriticalSection(&GuiData
->Lock
);
115 HeapFree(Win32CsrApiHeap
, 0, GuiData
);
118 if (! GetTextMetricsW(Dc
, &Metrics
))
120 DPRINT1("GuiConsoleNcCreate: GetTextMetrics failed\n");
121 SelectObject(Dc
, OldFont
);
123 DeleteObject(GuiData
->Font
);
124 RtlDeleteCriticalSection(&GuiData
->Lock
);
125 HeapFree(Win32CsrApiHeap
, 0, GuiData
);
128 GuiData
->CharWidth
= Metrics
.tmMaxCharWidth
;
129 GuiData
->CharHeight
= Metrics
.tmHeight
+ Metrics
.tmExternalLeading
;
130 SelectObject(Dc
, OldFont
);
132 GuiData
->MemoryDC
= CreateCompatibleDC(Dc
);
133 GuiData
->MemoryBitmap
= CreateCompatibleBitmap(Dc
,
134 Console
->Size
.X
* GuiData
->CharWidth
,
135 Console
->Size
.Y
* GuiData
->CharHeight
);
136 DeleteObject(SelectObject(GuiData
->MemoryDC
, GuiData
->MemoryBitmap
));
137 DeleteObject(SelectObject(GuiData
->MemoryDC
, GuiData
->Font
));
141 GuiData
->CursorBlinkOn
= TRUE
;
142 GuiData
->ForceCursorOff
= FALSE
;
144 Console
->PrivateData
= GuiData
;
145 SetWindowLongW(hWnd
, GWL_USERDATA
, (LONG
) Console
);
147 GetWindowRect(hWnd
, &Rect
);
148 Rect
.right
= Rect
.left
+ Console
->Size
.X
* GuiData
->CharWidth
+
149 2 * GetSystemMetrics(SM_CXFIXEDFRAME
);
150 Rect
.bottom
= Rect
.top
+ Console
->Size
.Y
* GuiData
->CharHeight
+
151 2 * GetSystemMetrics(SM_CYFIXEDFRAME
) + GetSystemMetrics(SM_CYCAPTION
);
152 MoveWindow(hWnd
, Rect
.left
, Rect
.top
, Rect
.right
- Rect
.left
,
153 Rect
.bottom
- Rect
.top
, FALSE
);
155 SetTimer(hWnd
, 1, CURSOR_BLINK_TIME
, NULL
);
157 return (BOOL
) DefWindowProcW(hWnd
, WM_NCCREATE
, 0, (LPARAM
) Create
);
160 static COLORREF FASTCALL
161 GuiConsoleRGBFromAttribute(BYTE Attribute
)
163 int Red
= (Attribute
& 0x04 ? (Attribute
& 0x08 ? 0xff : 0x80) : 0x00);
164 int Green
= (Attribute
& 0x02 ? (Attribute
& 0x08 ? 0xff : 0x80) : 0x00);
165 int Blue
= (Attribute
& 0x01 ? (Attribute
& 0x08 ? 0xff : 0x80) : 0x00);
167 return RGB(Red
, Green
, Blue
);
171 GuiConsoleSetTextColors(HDC Dc
, BYTE Attribute
)
173 SetTextColor(Dc
, GuiConsoleRGBFromAttribute(Attribute
& 0x0f));
174 SetBkColor(Dc
, GuiConsoleRGBFromAttribute((Attribute
& 0xf0) >> 4));
178 GuiConsoleGetLogicalCursorPos(PCSRSS_SCREEN_BUFFER Buff
, ULONG
*CursorX
, ULONG
*CursorY
)
180 *CursorX
= Buff
->CurrentX
;
181 if (Buff
->CurrentY
< Buff
->ShowY
)
183 *CursorY
= Buff
->MaxY
- Buff
->ShowY
+ Buff
->CurrentY
;
187 *CursorY
= Buff
->CurrentY
- Buff
->ShowY
;
192 GuiConsoleUpdateBitmap(HWND hWnd
, RECT rc
)
194 PCSRSS_CONSOLE Console
;
195 PGUI_CONSOLE_DATA GuiData
;
196 PCSRSS_SCREEN_BUFFER Buff
;
198 ULONG TopLine
, BottomLine
, LeftChar
, RightChar
;
199 ULONG Line
, Char
, Start
;
202 BYTE LastAttribute
, Attribute
;
203 ULONG CursorX
, CursorY
, CursorHeight
;
204 HBRUSH CursorBrush
, OldBrush
;
206 GuiConsoleGetDataPointers(hWnd
, &Console
, &GuiData
);
207 if (NULL
!= Console
&& NULL
!= GuiData
&& NULL
!= Console
->ActiveBuffer
)
209 Buff
= Console
->ActiveBuffer
;
210 EnterCriticalSection(&Buff
->Header
.Lock
);
212 if (rc
.right
<= rc
.left
|| rc
.bottom
<= rc
.top
)
215 LeaveCriticalSection(&Buff
->Header
.Lock
);
219 EnterCriticalSection(&GuiData
->Lock
);
221 TopLine
= rc
.top
/ GuiData
->CharHeight
;
222 BottomLine
= (rc
.bottom
+ (GuiData
->CharHeight
- 1)) / GuiData
->CharHeight
- 1;
223 LeftChar
= rc
.left
/ GuiData
->CharWidth
;
224 RightChar
= (rc
.right
+ (GuiData
->CharWidth
- 1)) / GuiData
->CharWidth
- 1;
225 LastAttribute
= Buff
->Buffer
[(TopLine
* Buff
->MaxX
+ LeftChar
) * 2 + 1];
226 GuiConsoleSetTextColors(GuiData
->MemoryDC
, LastAttribute
);
228 for (Line
= TopLine
; Line
<= BottomLine
; Line
++)
230 if (Line
+ Buff
->ShowY
< Buff
->MaxY
)
232 From
= Buff
->Buffer
+ ((Line
+ Buff
->ShowY
) * Buff
->MaxX
+ LeftChar
) * 2;
236 From
= Buff
->Buffer
+
237 ((Line
- (Buff
->MaxY
- Buff
->ShowY
)) * Buff
->MaxX
+ LeftChar
) * 2;
239 Attribute
= *(From
+ 1);
241 To
= GuiData
->LineBuffer
;
242 for (Char
= LeftChar
; Char
<= RightChar
; Char
++)
244 if (*(From
+ 1) != Attribute
)
246 TextOutW(GuiData
->MemoryDC
, Start
* GuiData
->CharWidth
, Line
* GuiData
->CharHeight
,
247 GuiData
->LineBuffer
, Char
- Start
);
249 To
= GuiData
->LineBuffer
;
250 Attribute
= *(From
+ 1);
251 if (Attribute
!= LastAttribute
)
253 GuiConsoleSetTextColors(GuiData
->MemoryDC
, Attribute
);
254 LastAttribute
= Attribute
;
257 *((PBYTE
) To
) = *From
;
258 *(((PBYTE
) To
) + 1) = '\0';
262 TextOutW(GuiData
->MemoryDC
, Start
* GuiData
->CharWidth
, Line
* GuiData
->CharHeight
,
263 GuiData
->LineBuffer
, RightChar
- Start
+ 1);
266 if (Buff
->CursorInfo
.bVisible
&& GuiData
->CursorBlinkOn
267 &&! GuiData
->ForceCursorOff
)
269 GuiConsoleGetLogicalCursorPos(Buff
, &CursorX
, &CursorY
);
270 if (LeftChar
<= CursorX
&& CursorX
<= RightChar
&&
271 TopLine
<= CursorY
&& CursorY
<= BottomLine
)
273 CursorHeight
= (GuiData
->CharHeight
* Buff
->CursorInfo
.dwSize
) / 100;
274 if (CursorHeight
< 1)
278 From
= Buff
->Buffer
+ (Buff
->CurrentY
* Buff
->MaxX
+ Buff
->CurrentX
) * 2 + 1;
279 CursorBrush
= CreateSolidBrush(GuiConsoleRGBFromAttribute(*From
));
280 OldBrush
= SelectObject(GuiData
->MemoryDC
, CursorBrush
);
281 PatBlt(GuiData
->MemoryDC
, CursorX
* GuiData
->CharWidth
,
282 CursorY
* GuiData
->CharHeight
+ (GuiData
->CharHeight
- CursorHeight
),
283 GuiData
->CharWidth
, CursorHeight
, PATCOPY
);
284 SelectObject(GuiData
->MemoryDC
, OldBrush
);
285 DeleteObject(CursorBrush
);
289 LeaveCriticalSection(&GuiData
->Lock
);
291 LeaveCriticalSection(&Buff
->Header
.Lock
);
292 InvalidateRect(hWnd
, &rc
, FALSE
);
298 GuiConsoleHandlePaint(HWND hWnd
)
302 PCSRSS_CONSOLE Console
;
303 PGUI_CONSOLE_DATA GuiData
;
305 GuiConsoleGetDataPointers(hWnd
, &Console
, &GuiData
);
306 if (NULL
!= Console
&& NULL
!= GuiData
)
308 EnterCriticalSection(&GuiData
->Lock
);
309 Dc
= BeginPaint (hWnd
, &Ps
);
310 BitBlt(Dc
, Ps
.rcPaint
.left
, Ps
.rcPaint
.top
,
311 Ps
.rcPaint
.right
- Ps
.rcPaint
.left
+ 1,
312 Ps
.rcPaint
.bottom
- Ps
.rcPaint
.top
+ 1, GuiData
->MemoryDC
,
313 Ps
.rcPaint
.left
, Ps
.rcPaint
.top
, SRCCOPY
);
314 EndPaint (hWnd
, &Ps
);
315 LeaveCriticalSection(&GuiData
->Lock
);
319 Dc
= BeginPaint (hWnd
, &Ps
);
320 EndPaint (hWnd
, &Ps
);
325 GuiConsoleHandleKey(HWND hWnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
327 PCSRSS_CONSOLE Console
;
328 PGUI_CONSOLE_DATA GuiData
;
331 GuiConsoleGetDataPointers(hWnd
, &Console
, &GuiData
);
333 Message
.message
= msg
;
334 Message
.wParam
= wParam
;
335 Message
.lParam
= lParam
;
337 ConioProcessKey(&Message
, Console
, FALSE
);
341 GuiIntDrawRegion(PGUI_CONSOLE_DATA GuiData
, HWND Wnd
, RECT
*Region
)
345 RegionRect
.left
= Region
->left
* GuiData
->CharWidth
;
346 RegionRect
.top
= Region
->top
* GuiData
->CharHeight
;
347 RegionRect
.right
= (Region
->right
+ 1) * GuiData
->CharWidth
;
348 RegionRect
.bottom
= (Region
->bottom
+ 1) * GuiData
->CharHeight
;
350 GuiConsoleUpdateBitmap(Wnd
, RegionRect
);
354 GuiDrawRegion(PCSRSS_CONSOLE Console
, RECT
*Region
)
356 PGUI_CONSOLE_DATA GuiData
= (PGUI_CONSOLE_DATA
) Console
->PrivateData
;
358 if (NULL
== Console
->hWindow
|| NULL
== GuiData
)
363 GuiIntDrawRegion(GuiData
, Console
->hWindow
, Region
);
367 GuiInvalidateCell(PGUI_CONSOLE_DATA GuiData
, HWND Wnd
, UINT x
, UINT y
)
376 GuiIntDrawRegion(GuiData
, Wnd
, &CellRect
);
380 GuiWriteStream(PCSRSS_CONSOLE Console
, RECT
*Region
, UINT CursorStartX
, UINT CursorStartY
,
381 UINT ScrolledLines
, CHAR
*Buffer
, UINT Length
)
383 PGUI_CONSOLE_DATA GuiData
= (PGUI_CONSOLE_DATA
) Console
->PrivateData
;
384 PCSRSS_SCREEN_BUFFER Buff
= Console
->ActiveBuffer
;
385 LONG CursorEndX
, CursorEndY
;
388 if (NULL
== Console
->hWindow
|| NULL
== GuiData
)
393 if (0 != ScrolledLines
)
396 Source
.top
= ScrolledLines
;
397 Source
.right
= Console
->Size
.X
- 1;
398 Source
.bottom
= ScrolledLines
+ Region
->top
- 1;
401 Dest
.right
= Console
->Size
.X
- 1;
402 Dest
.bottom
= Region
->top
- 1;
404 GuiConsoleCopyRegion(Console
->hWindow
, &Source
, &Dest
);
407 GuiIntDrawRegion(GuiData
, Console
->hWindow
, Region
);
409 if (CursorStartX
< Region
->left
|| Region
->right
< CursorStartX
410 || CursorStartY
< Region
->top
|| Region
->bottom
< CursorStartY
)
412 GuiInvalidateCell(GuiData
, Console
->hWindow
, CursorStartX
, CursorStartY
);
415 ConioPhysicalToLogical(Buff
, Buff
->CurrentX
, Buff
->CurrentY
,
416 &CursorEndX
, &CursorEndY
);
417 if ((CursorEndX
< Region
->left
|| Region
->right
< CursorEndX
418 || CursorEndY
< Region
->top
|| Region
->bottom
< CursorEndY
)
419 && (CursorEndX
!= CursorStartX
|| CursorEndY
!= CursorStartY
))
421 GuiInvalidateCell(GuiData
, Console
->hWindow
, CursorEndX
, CursorEndY
);
426 GuiSetCursorInfo(PCSRSS_CONSOLE Console
, PCSRSS_SCREEN_BUFFER Buff
)
430 if (Console
->ActiveBuffer
== Buff
)
432 ConioPhysicalToLogical(Buff
, Buff
->CurrentX
, Buff
->CurrentY
,
433 &UpdateRect
.left
, &UpdateRect
.top
);
434 UpdateRect
.right
= UpdateRect
.left
;
435 UpdateRect
.bottom
= UpdateRect
.top
;
436 ConioDrawRegion(Console
, &UpdateRect
);
443 GuiSetScreenInfo(PCSRSS_CONSOLE Console
, PCSRSS_SCREEN_BUFFER Buff
, UINT OldCursorX
, UINT OldCursorY
)
447 if (Console
->ActiveBuffer
== Buff
)
449 /* Redraw char at old position (removes cursor) */
450 UpdateRect
.left
= OldCursorX
;
451 UpdateRect
.top
= OldCursorY
;
452 UpdateRect
.right
= OldCursorX
;
453 UpdateRect
.bottom
= OldCursorY
;
454 ConioDrawRegion(Console
, &UpdateRect
);
455 /* Redraw char at new position (shows cursor) */
456 ConioPhysicalToLogical(Buff
, Buff
->CurrentX
, Buff
->CurrentY
,
457 &(UpdateRect
.left
), &(UpdateRect
.top
));
458 UpdateRect
.right
= UpdateRect
.left
;
459 UpdateRect
.bottom
= UpdateRect
.top
;
460 ConioDrawRegion(Console
, &UpdateRect
);
467 GuiConsoleHandleTimer(HWND hWnd
)
469 PCSRSS_CONSOLE Console
;
470 PGUI_CONSOLE_DATA GuiData
;
472 ULONG CursorX
, CursorY
;
474 GuiConsoleGetDataPointers(hWnd
, &Console
, &GuiData
);
475 GuiData
->CursorBlinkOn
= ! GuiData
->CursorBlinkOn
;
477 GuiConsoleGetLogicalCursorPos(Console
->ActiveBuffer
, &CursorX
, &CursorY
);
478 CursorRect
.left
= CursorX
;
479 CursorRect
.top
= CursorY
;
480 CursorRect
.right
= CursorX
;
481 CursorRect
.bottom
= CursorY
;
482 GuiDrawRegion(Console
, &CursorRect
);
486 GuiConsoleHandleClose(HWND hWnd
)
488 /* FIXME for now, just ignore close requests */
492 GuiConsoleHandleNcDestroy(HWND hWnd
)
494 PCSRSS_CONSOLE Console
;
495 PGUI_CONSOLE_DATA GuiData
;
497 GuiConsoleGetDataPointers(hWnd
, &Console
, &GuiData
);
499 Console
->PrivateData
= NULL
;
500 DeleteDC(GuiData
->MemoryDC
);
501 RtlDeleteCriticalSection(&GuiData
->Lock
);
502 HeapFree(Win32CsrApiHeap
, 0, GuiData
);
505 static LRESULT CALLBACK
506 GuiConsoleWndProc(HWND hWnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
513 Result
= (LRESULT
) GuiConsoleHandleNcCreate(hWnd
, (CREATESTRUCTW
*) lParam
);
516 GuiConsoleHandlePaint(hWnd
);
524 GuiConsoleHandleKey(hWnd
, msg
, wParam
, lParam
);
528 GuiConsoleHandleTimer(hWnd
);
532 GuiConsoleHandleClose(hWnd
);
536 GuiConsoleHandleNcDestroy(hWnd
);
540 Result
= DefWindowProcW(hWnd
, msg
, wParam
, lParam
);
547 static LRESULT CALLBACK
548 GuiConsoleNotifyWndProc(HWND hWnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
552 PCSRSS_CONSOLE Console
= (PCSRSS_CONSOLE
) lParam
;
557 SetWindowLongW(hWnd
, GWL_USERDATA
, 0);
559 case PM_CREATE_CONSOLE
:
560 NewWindow
= CreateWindowW(L
"Win32CsrConsole",
561 Console
->Title
.Buffer
,
562 WS_OVERLAPPED
| WS_CAPTION
| WS_SYSMENU
| WS_MINIMIZEBOX
,
569 (HINSTANCE
) GetModuleHandleW(NULL
),
571 Console
->hWindow
= NewWindow
;
572 if (NULL
!= NewWindow
)
574 SetWindowLongW(hWnd
, GWL_USERDATA
, GetWindowLongW(hWnd
, GWL_USERDATA
) + 1);
575 ShowWindow(NewWindow
, SW_SHOW
);
577 return (LRESULT
) NewWindow
;
578 case PM_DESTROY_CONSOLE
:
579 DestroyWindow(Console
->hWindow
);
580 Console
->hWindow
= NULL
;
581 WindowCount
= GetWindowLongW(hWnd
, GWL_USERDATA
);
583 SetWindowLongW(hWnd
, GWL_USERDATA
, WindowCount
);
584 if (0 == WindowCount
)
588 PrivateCsrssManualGuiCheck(-1);
593 return DefWindowProcW(hWnd
, msg
, wParam
, lParam
);
598 GuiConsoleGuiThread(PVOID Data
)
601 PHANDLE GraphicsStartupEvent
= (PHANDLE
) Data
;
603 NotifyWnd
= CreateWindowW(L
"Win32CsrCreateNotify",
612 (HINSTANCE
) GetModuleHandleW(NULL
),
614 if (NULL
== NotifyWnd
)
616 PrivateCsrssManualGuiCheck(-1);
617 SetEvent(*GraphicsStartupEvent
);
621 SetEvent(*GraphicsStartupEvent
);
623 while(GetMessageW(&msg
, NULL
, 0, 0))
625 TranslateMessage(&msg
);
626 DispatchMessageW(&msg
);
639 Desktop
= OpenDesktopW(L
"Default", 0, FALSE
, GENERIC_ALL
);
642 DPRINT1("Failed to open desktop\n");
645 Status
= NtSetInformationProcess(NtCurrentProcess(),
649 if (!NT_SUCCESS(Status
))
651 DPRINT1("Cannot set default desktop.\n");
654 if (! SetThreadDesktop(Desktop
))
656 DPRINT1("Failed to set thread desktop\n");
660 if (NULL
== NotifyWnd
)
662 PrivateCsrssManualGuiCheck(+1);
665 wc
.cbSize
= sizeof(WNDCLASSEXW
);
666 wc
.lpszClassName
= L
"Win32CsrCreateNotify";
667 wc
.lpfnWndProc
= GuiConsoleNotifyWndProc
;
669 wc
.hInstance
= (HINSTANCE
) GetModuleHandleW(NULL
);
672 wc
.hbrBackground
= NULL
;
673 wc
.lpszMenuName
= NULL
;
677 if (RegisterClassExW(&wc
) == 0)
679 DPRINT1("Failed to register notify wndproc\n");
683 wc
.cbSize
= sizeof(WNDCLASSEXW
);
684 wc
.lpszClassName
= L
"Win32CsrConsole";
685 wc
.lpfnWndProc
= GuiConsoleWndProc
;
687 wc
.hInstance
= (HINSTANCE
) GetModuleHandleW(NULL
);
688 wc
.hIcon
= LoadIconW(Win32CsrDllHandle
, MAKEINTRESOURCEW(1));
689 wc
.hCursor
= LoadCursorW(NULL
, MAKEINTRESOURCEW(IDC_ARROW
));
690 wc
.hbrBackground
= NULL
;
691 wc
.lpszMenuName
= NULL
;
694 wc
.hIconSm
= LoadImageW(Win32CsrDllHandle
, MAKEINTRESOURCEW(1), IMAGE_ICON
,
695 GetSystemMetrics(SM_CXSMICON
), GetSystemMetrics(SM_CYSMICON
),
697 if (RegisterClassExW(&wc
) == 0)
699 DPRINT1("Failed to register console wndproc\n");
707 GuiInitScreenBuffer(PCSRSS_CONSOLE Console
, PCSRSS_SCREEN_BUFFER Buffer
)
709 Buffer
->DefaultAttrib
= 0x0f;
713 GuiChangeTitle(PCSRSS_CONSOLE Console
)
715 SendMessageW(Console
->hWindow
, WM_SETTEXT
, 0, (LPARAM
) Console
->Title
.Buffer
);
721 GuiCleanupConsole(PCSRSS_CONSOLE Console
)
723 SendMessageW(NotifyWnd
, PM_DESTROY_CONSOLE
, 0, (LPARAM
) Console
);
726 static CSRSS_CONSOLE_VTBL GuiVtbl
=
738 GuiInitConsole(PCSRSS_CONSOLE Console
)
740 HANDLE GraphicsStartupEvent
;
749 return STATUS_UNSUCCESSFUL
;
753 Console
->Vtbl
= &GuiVtbl
;
754 Console
->Size
.X
= 80;
755 Console
->Size
.Y
= 25;
756 if (NULL
== NotifyWnd
)
758 GraphicsStartupEvent
= CreateEventW(NULL
, FALSE
, FALSE
, NULL
);
759 if (NULL
== GraphicsStartupEvent
)
761 return STATUS_UNSUCCESSFUL
;
764 ThreadHandle
= CreateThread(NULL
,
767 (PVOID
) &GraphicsStartupEvent
,
770 if (NULL
== ThreadHandle
)
772 NtClose(GraphicsStartupEvent
);
773 DPRINT1("Win32Csr: Failed to create graphics console thread. Expect problems\n");
774 return STATUS_UNSUCCESSFUL
;
776 SetThreadPriority(ThreadHandle
, THREAD_PRIORITY_HIGHEST
);
777 CloseHandle(ThreadHandle
);
779 WaitForSingleObject(GraphicsStartupEvent
, INFINITE
);
780 CloseHandle(GraphicsStartupEvent
);
782 if (NULL
== NotifyWnd
)
784 DPRINT1("Win32Csr: Failed to create notification window.\n");
785 return STATUS_UNSUCCESSFUL
;
789 PostMessageW(NotifyWnd
, PM_CREATE_CONSOLE
, 0, (LPARAM
) Console
);
791 return STATUS_SUCCESS
;
795 GuiConsoleCopyRegion(HWND hWnd
,
800 PGUI_CONSOLE_DATA GuiData
;
801 PCSRSS_CONSOLE Console
;
804 GuiConsoleGetDataPointers(hWnd
, &Console
, &GuiData
);
806 ScrollRect
.left
= Dest
->left
* GuiData
->CharWidth
;
807 ScrollRect
.right
= (Dest
->right
+ 1) * GuiData
->CharWidth
;
808 ScrollRect
.top
= Dest
->top
* GuiData
->CharHeight
;
809 ScrollRect
.bottom
= (Dest
->bottom
+ 1) * GuiData
->CharHeight
;
810 EnterCriticalSection(&GuiData
->Lock
);
811 BitBlt(GuiData
->MemoryDC
, ScrollRect
.left
, ScrollRect
.top
,
812 ScrollRect
.right
- ScrollRect
.left
, ScrollRect
.bottom
- ScrollRect
.top
,
813 GuiData
->MemoryDC
, Source
->left
* GuiData
->CharWidth
, Source
->top
* GuiData
->CharHeight
, SRCCOPY
);
815 LeaveCriticalSection(&GuiData
->Lock
);
817 InvalidateRect(hWnd
, &ScrollRect
, FALSE
);