2020-05-10 20:38:18 +02:00
|
|
|
program SetWindowPosApp;
|
|
|
|
|
|
|
|
uses
|
|
|
|
KolibriOS;
|
|
|
|
|
|
|
|
const
|
|
|
|
KS_UP = #$48;
|
|
|
|
KS_DOWN = #$50;
|
|
|
|
KS_LEFT = #$4B;
|
|
|
|
KS_RIGHT = #$4D;
|
|
|
|
|
|
|
|
MOVE_STEP = 10;
|
|
|
|
|
|
|
|
LEFT_CTRL_PRESSED = 4;
|
|
|
|
RIGHT_CTRL_PRESSED = 8;
|
|
|
|
|
|
|
|
procedure OnKey;
|
|
|
|
var
|
|
|
|
Key: TKeyboardInput;
|
|
|
|
ThreadInfo: TThreadInfo;
|
|
|
|
ControlKeyState: LongWord;
|
|
|
|
begin
|
|
|
|
GetThreadInfo($FFFFFFFF, ThreadInfo);
|
|
|
|
ControlKeyState := GetControlKeyState;
|
|
|
|
Key := GetKey;
|
|
|
|
with ThreadInfo.Window do
|
|
|
|
begin
|
|
|
|
if Boolean(ControlKeyState and (RIGHT_CTRL_PRESSED or LEFT_CTRL_PRESSED)) then
|
2020-05-23 15:32:30 +02:00
|
|
|
case Key.ScanCode of
|
2020-05-10 20:38:18 +02:00
|
|
|
KS_UP:
|
2020-09-17 17:29:37 +02:00
|
|
|
Dec(Height, MOVE_STEP);
|
2020-05-10 20:38:18 +02:00
|
|
|
KS_DOWN:
|
2020-09-17 17:29:37 +02:00
|
|
|
Inc(Height, MOVE_STEP);
|
2020-05-10 20:38:18 +02:00
|
|
|
KS_LEFT:
|
2020-09-17 17:29:37 +02:00
|
|
|
Dec(Width, MOVE_STEP);
|
2020-05-10 20:38:18 +02:00
|
|
|
KS_RIGHT:
|
2020-09-17 17:29:37 +02:00
|
|
|
Inc(Width, MOVE_STEP);
|
2020-05-10 20:38:18 +02:00
|
|
|
end
|
|
|
|
else
|
2020-05-23 15:32:30 +02:00
|
|
|
case Key.ScanCode of
|
2020-05-10 20:38:18 +02:00
|
|
|
KS_UP:
|
|
|
|
Dec(Top, MOVE_STEP);
|
|
|
|
KS_DOWN:
|
|
|
|
Inc(Top, MOVE_STEP);
|
|
|
|
KS_LEFT:
|
|
|
|
Dec(Left, MOVE_STEP);
|
|
|
|
KS_RIGHT:
|
|
|
|
Inc(Left, MOVE_STEP);
|
|
|
|
end;
|
2020-09-17 17:29:37 +02:00
|
|
|
SetWindowPos(Left, Top, Width, Height);
|
2020-05-10 20:38:18 +02:00
|
|
|
end;
|
|
|
|
end;
|
|
|
|
|
|
|
|
var
|
2020-06-07 21:30:49 +02:00
|
|
|
WndLeft, WndTop, WndWidth, WndHeight: Integer;
|
2020-05-10 20:38:18 +02:00
|
|
|
|
|
|
|
begin
|
|
|
|
with GetScreenSize do
|
|
|
|
begin
|
2020-06-07 21:30:49 +02:00
|
|
|
WndWidth := Width div 4;
|
|
|
|
if WndWidth < 280 then
|
|
|
|
WndWidth := 280; // to center the prompt
|
|
|
|
WndHeight := Height div 4;
|
|
|
|
WndLeft := (Width - WndWidth) div 2;
|
|
|
|
WndTop := (Height - WndHeight) div 2;
|
2020-05-10 20:38:18 +02:00
|
|
|
end;
|
|
|
|
|
|
|
|
while True do
|
|
|
|
case WaitEvent of
|
|
|
|
REDRAW_EVENT:
|
|
|
|
begin
|
|
|
|
BeginDraw;
|
2020-06-07 21:30:49 +02:00
|
|
|
DrawWindow(WndLeft, WndTop, WndWidth, WndHeight, 'Set Window Position', $00FFFFFF,
|
2020-05-23 15:32:30 +02:00
|
|
|
WS_SKINNED_SIZABLE + WS_CLIENT_COORDS + WS_CAPTION, CAPTION_MOVABLE);
|
2020-05-10 20:38:18 +02:00
|
|
|
DrawText(24, 26, 'Use arrow keys(Left, Right, Up, Down)', $00000000, $00FFFFFF, DT_ZSTRING, 0);
|
|
|
|
DrawText(24, 35, 'to move the window.', $00000000, $00FFFFFF, DT_ZSTRING, 0);
|
|
|
|
DrawText(24, 44, 'Use Ctrl+arrow keys to resize window.', $00000000, $00FFFFFF, DT_ZSTRING, 0);
|
|
|
|
EndDraw;
|
|
|
|
end;
|
|
|
|
KEY_EVENT:
|
|
|
|
OnKey;
|
|
|
|
BUTTON_EVENT:
|
|
|
|
if GetButton.ID = 1 then
|
2020-06-07 20:55:00 +02:00
|
|
|
Break;
|
2020-05-10 20:38:18 +02:00
|
|
|
end;
|
|
|
|
end.
|