Build regular Windows programs using KoW {$IFNDEF Debug}

This commit is contained in:
Владислав Джавадов 2021-01-09 00:24:10 +03:00
parent 5f3fca1705
commit 65ad809822
6 changed files with 28 additions and 14 deletions

View File

@ -2,5 +2,6 @@
OutputDir=..\..\..\Bin\KoW OutputDir=..\..\..\Bin\KoW
UnitOutputDir=..\..\..\Bin\KoW\DCU UnitOutputDir=..\..\..\Bin\KoW\DCU
SearchPath=..\..\..\Lib;..\..\..\Bin\KoW\DCU SearchPath=..\..\..\Lib;..\..\..\Bin\KoW\DCU
Conditionals=Debug
UnitAliases= UnitAliases=
UsePackages=0 UsePackages=0

View File

@ -87,8 +87,8 @@ var
procedure InitConsole(Title: PKolibriChar; CloseWindowOnExit: Boolean; procedure InitConsole(Title: PKolibriChar; CloseWindowOnExit: Boolean;
WndWidth, WndHeight, ScrWidth, ScrHeight: LongWord); WndWidth, WndHeight, ScrWidth, ScrHeight: LongWord);
begin begin
con_init(WndWidth, WndHeight, ScrWidth, ScrHeight, Title);
CloseWindow := CloseWindowOnExit; CloseWindow := CloseWindowOnExit;
con_init(WndWidth, WndHeight, ScrWidth, ScrHeight, Title);
if ScrWidth <> LongWord(-1) then if ScrWidth <> LongWord(-1) then
ClrEOLWidth := ScrWidth; ClrEOLWidth := ScrWidth;
end; end;
@ -278,11 +278,13 @@ initialization
InitKoW; InitKoW;
{$ENDIF} {$ENDIF}
{$IF defined(KolibriOS) or defined(Debug)}
if IsConsole then if IsConsole then
InitConsole(AppPath); InitConsole(AppPath);
finalization finalization
if Assigned(System.con_exit) then if Assigned(System.con_exit) then
con_exit(CloseWindow); con_exit(CloseWindow);
{$IFEND}
end. end.

View File

@ -73,16 +73,21 @@ begin
end; end;
procedure con_init(WndWidth, WndHeight, ScrWidth, ScrHeight: LongWord; Title: PKolibriChar); stdcall; procedure con_init(WndWidth, WndHeight, ScrWidth, ScrHeight: LongWord; Title: PKolibriChar); stdcall;
{$IFDEF Debug}
var var
Font: TConsoleFontInfo; Font: TConsoleFontInfo;
R: TSmallRect; R: TSmallRect;
{$ENDIF}
begin begin
{$IFDEF Debug}
if not IsConsole then if not IsConsole then
AllocConsole; AllocConsole;
{$ENDIF}
TTextRec(Input).Handle := System.GetStdHandle(STD_INPUT_HANDLE); TTextRec(Input).Handle := System.GetStdHandle(STD_INPUT_HANDLE);
TTextRec(Output).Handle := System.GetStdHandle(STD_OUTPUT_HANDLE); TTextRec(Output).Handle := System.GetStdHandle(STD_OUTPUT_HANDLE);
{$IFDEF Debug}
SaveInputCP := GetConsoleCP; SaveInputCP := GetConsoleCP;
SetConsoleCP(CP_KOLIBRIOS); SetConsoleCP(CP_KOLIBRIOS);
SaveOutputCP := GetConsoleOutputCP; SaveOutputCP := GetConsoleOutputCP;
@ -95,8 +100,9 @@ begin
if WndHeight <> LongWord(-1) then if WndHeight <> LongWord(-1) then
WndSize.Y := WndHeight; WndSize.Y := WndHeight;
MainWindow := GetConsoleWindow;
GetCurrentConsoleFont(TTextRec(Output).Handle, False, Font); GetCurrentConsoleFont(TTextRec(Output).Handle, False, Font);
SetWindowPos(GetConsoleWindow, 0, WndPos.X, WndPos.Y, SetWindowPos(MainWindow, 0, WndPos.X, WndPos.Y,
Font.Size.X * WndSize.X + GetSystemMetrics(SM_CXVSCROLL), Font.Size.Y * WndSize.Y + GetSystemMetrics(SM_CYHSCROLL), 0); Font.Size.X * WndSize.X + GetSystemMetrics(SM_CXVSCROLL), Font.Size.Y * WndSize.Y + GetSystemMetrics(SM_CYHSCROLL), 0);
if ScrWidth <> LongWord(-1) then if ScrWidth <> LongWord(-1) then
@ -113,6 +119,7 @@ begin
Bottom := ScrSize.Y - 1; Bottom := ScrSize.Y - 1;
end; end;
SetConsoleWindowInfo(TTextRec(Output).Handle, True, R); SetConsoleWindowInfo(TTextRec(Output).Handle, True, R);
{$ENDIF}
end; end;
function con_get_cursor_height: Integer; stdcall; function con_get_cursor_height: Integer; stdcall;

View File

@ -38,23 +38,26 @@ const
EOL: array[0..1] of KolibriChar = #13#10; EOL: array[0..1] of KolibriChar = #13#10;
var var
Buf: array[Low(Byte)..High(Byte) + 1] of KolibriChar; Buf: array[Low(Byte)..High(Byte) + 1] of KolibriChar;
BytesWritten, Flags: Cardinal; {$IFNDEF Debug}
BytesWritten: LongWord;
{$ENDIF}
Flags: LongWord;
begin begin
{$IFNDEF Debug}
if TTextRec(Output).Handle <> 0 then if TTextRec(Output).Handle <> 0 then
begin begin
WriteFile(TTextRec(Output).Handle, Msg^, Count, BytesWritten, nil); WriteFile(TTextRec(Output).Handle, Msg^, Count, BytesWritten, nil);
WriteFile(TTextRec(Output).Handle, EOL, SizeOf(EOL), BytesWritten, nil); WriteFile(TTextRec(Output).Handle, EOL, SizeOf(EOL), BytesWritten, nil);
end Exit;
else
begin
if MainWindow <> 0 then
Flags := MB_ICONERROR
else
Flags := MB_ICONERROR or MB_TASKMODAL;
Move(Msg^, Buf, Count);
Msg[Count] := #0;
MessageBox(MainWindow, Msg, nil, Flags);
end; end;
{$ENDIF}
if MainWindow <> 0 then
Flags := MB_ICONERROR
else
Flags := MB_ICONERROR or MB_TASKMODAL;
Move(Msg^, Buf, Count);
Msg[Count] := #0;
MessageBox(MainWindow, Msg, nil, Flags);
end; end;
function SysFreeMem(P: Pointer): Integer; function SysFreeMem(P: Pointer): Integer;

View File

@ -2,5 +2,6 @@
OutputDir=..\..\Bin\KoW OutputDir=..\..\Bin\KoW
UnitOutputDir=..\..\Bin\KoW\DCU UnitOutputDir=..\..\Bin\KoW\DCU
SearchPath=..\..\Lib;..\..\Bin\KoW\DCU SearchPath=..\..\Lib;..\..\Bin\KoW\DCU
Conditionals=Debug
UnitAliases= UnitAliases=
UsePackages=0 UsePackages=0

View File

@ -4,7 +4,7 @@ set DCU=%~dp0Bin\DCU
set KoW=%~dp0Bin\KoW\DCU set KoW=%~dp0Bin\KoW\DCU
if #%1#==## ( if #%1#==## (
call "%~dp0Tools\init.bat" call "%~dp0Tools\init.bat" -dDebug
if errorlevel 1 goto exit if errorlevel 1 goto exit
if not exist "%KoW%" mkdir "%KoW%" if not exist "%KoW%" mkdir "%KoW%"