program project1;
{$IFDEF MSWINDOWS}{$APPTYPE CONSOLE}{$ENDIF}
uses
Windows;
var
Original_Window_Title: shortstring;
Wnd: HWND;
OldStyle, NewStyle: LONG_PTR;
Caption: array[0..255] of AnsiChar;
function Get_Console_Title: shortstring;
var
GGet_Title, SGet_Title: shortstring;
LX: longint;
begin
GETConsoleTitle(@GGet_Title[1], 255);
SGet_Title := '';
LX := 1;
while GGet_Title[LX] <> #0 do
begin
SGet_Title := SGet_Title + GGet_Title[LX];
Inc(LX);
end;
Get_Console_Title := SGet_Title;
end;
procedure Set_Console_Title(CTitle: shortstring);
begin
SETConsoleTitle(@CTitle[1]);
end;
function Handler(dwCtrlType: DWORD): WINBOOL; StdCall;
begin
Result := False;
case dwCtrlType of
CTRL_C_EVENT: begin WriteLn('CTRL_C_EVENT'); ReadLn; Result := True; end;
CTRL_BREAK_EVENT: begin WriteLn('CTRL_BREAK_EVENT'); ReadLn; Result := True; end;
CTRL_CLOSE_EVENT: begin WriteLn('CTRL_CLOSE_EVENT'); ReadLn; Result := True; end;
CTRL_LOGOFF_EVENT: begin WriteLn('CTRL_LOGOFF_EVENT'); ReadLn; Result := True; end;
CTRL_SHUTDOWN_EVENT: begin WriteLn('CTRL_SHUTDOWN_EVENT'); ReadLn; Result := True; end;
else
begin WriteLn(dwCtrlType, ' = unknown Event'); ReadLn; end;
end;
end;
begin
if (GetConsoleWindow = 0) then
AllocConsole;
if SetConsoleCtrlHandler(@Handler, True) then
WriteLn('Handler set.')
else
WriteLn('Handler NOT set.');
GetConsoleTitle(Caption, Length(Caption));
Wnd := FindWindow(nil, Caption);
if Wnd <> 0 then
begin
WriteLn('Update the Style');
OldStyle := GetWindowLongPtr(Wnd, GWL_STYLE);
NewStyle := OldStyle and not (WS_SYSMENU or WS_MINIMIZEBOX or WS_MAXIMIZEBOX);
SetWindowLongPtr(Wnd, GWL_STYLE, NewStyle);
Writeln('Press ENTER to restore original Window Style...');
ReadLn;
SetWindowLongPtr(Wnd, GWL_STYLE, OldStyle);
end
else
WriteLn('Error @ Update the Style');
Original_Window_Title := Get_Console_Title;
Writeln('Press ENTER to update Window Title...');
ReadLn;
Set_Console_Title('Demo program...'#0);
Writeln('Press ENTER to restore original Window Title...');
ReadLn;
Set_Console_Title(Original_Window_Title + #0);
Writeln('Press ENTER to Exit...');
ReadLn;
FreeConsole;
SetConsoleCtrlHandler(@Handler, False);
end.