Не перерисовывается фон, когда неактивное окно изменяет своё положение
Posted: Tue Oct 04, 2016 4:58 pm
Есть исходник только на паскалеСкомпилированный бинарник Вот так это выглядитЗапускал в VirtualBox.
Spoiler:
Code: Select all
Unit test;
Interface
Type
SIZE = Record height, width : Word End;
Const
(* Window Style Constants *)
WS_SKINNED_FIXED = $4000000;
WS_SKINNED_SIZABLE = $3000000;
WS_FIXED = $0000000;
WS_SIZABLE = $2000000;
WS_FILL_TRANSPARENT = $40000000;
WS_FILL_GRADIENT = $80000000;
WS_COORD_CLIENT = $20000000;
WS_CAPTION = $10000000;
(* Event Constants *)
REDRAW_EVENT = 1;
KEY_EVENT = 2;
BUTTON_EVENT = 3;
(* Color Constants *)
COLOR_BLUE = $000000FF;
COLOR_RED = $00FF0000;
COLOR_GREEN = $0000FF00;
COLOR_WHITE = $00FFFFFF;
COLOR_BLACK = $00000000;
sz_hello = AnsiString('Test');
Var
WindowLeft, WindowTop, WindowWidth, WindowHeight : Cardinal;
Scr : SIZE;
Motion : Cardinal;
Function WaitEvent: Cardinal; Forward;
Function WaitEventByTime(time : Cardinal):
Cardinal; StdCall; Forward;
Function GetKeyCode: Cardinal; Forward;
Function GetButtonNumber: Cardinal; Forward;
Function GetScreenSize: SIZE; Forward;
Procedure RedrawStart; Forward;
Procedure RedrawFinish; Forward;
Procedure ThreadTerminate; Forward;
Procedure SetWindowPos(left, top, right, bottom : INTEGER);
StdCall; Forward;
Procedure DrawWindow(left, top, right, bottom : Cardinal;
Caption : PChar; BackColor, Style: Cardinal);
StdCall; Forward;
Procedure main; Forward;
Procedure On_Redraw; Forward;
Procedure On_KeyPress; Forward;
Procedure On_ButtonPress; Forward;
Procedure CtlMove(N : Cardinal); Forward;
implementation
(* -------------------------------------------------------- *)
Procedure main; Begin
Scr := GetScreenSize();
WindowWidth := Scr.width Shr 2;
WindowHeight := Scr.height Shr 2;
WindowLeft := (Scr.width - WindowWidth) Shr 1;
WindowTop := (Scr.height - WindowHeight) Shr 1;
Motion := 1;
On_Redraw;
While TRUE Do Begin
CtlMove(10);
Case WaitEventByTime(100) Of
REDRAW_EVENT : On_Redraw;
KEY_EVENT : On_KeyPress;
BUTTON_EVENT : On_ButtonPress;
End;
End;
End;
(* -------------------------------------------------------- *)
Procedure CtlMove; Begin
Case Motion Of
1 : Begin
WindowLeft := WindowLeft - N; WindowTop := WindowTop - N;
If WindowLeft <= 0 Then Motion := 2
Else If WindowTop <= 0 Then Motion := 4;
End;
2 : Begin
WindowLeft := WindowLeft + N; WindowTop := WindowTop - N;
If WindowLeft >= Scr.Width - WindowWidth Then Motion := 1
Else If WindowTop <= 0 Then Motion := 3;
End;
3 : Begin
WindowLeft := WindowLeft + N; WindowTop := WindowTop + N;
If WindowLeft >= Scr.Width - WindowWidth Then Motion := 4
Else If WindowTop >= Scr.Height - WindowHeight Then Motion := 2;
End;
4 : Begin
WindowLeft := WindowLeft - N; WindowTop := WindowTop + N;
If WindowLeft <= 0 Then Motion := 3
Else If WindowTop >= Scr.Height - WindowHeight Then Motion := 1;
End;
End;
SetWindowPos(WindowLeft, WindowTop, $FFFFFFFF, $FFFFFFFF);
End;
(* -------------------------------------------------------- *)
Procedure On_Redraw; Begin
RedrawStart;
DrawWindow(WindowLeft, WindowTop, WindowWidth, WindowHeight,
sz_hello, COLOR_WHITE, WS_SKINNED_FIXED + WS_COORD_CLIENT + WS_CAPTION);
RedrawFinish;
End;
(* -------------------------------------------------------- *)
Procedure On_KeyPress; Begin
GetKeyCode;
End;
(* -------------------------------------------------------- *)
Procedure On_ButtonPress; Begin
Case GetButtonNumber() Of
1 : ThreadTerminate;
End;
End;
(* -------------------------------------------------------- *)
Procedure RedrawStart; Asm
push ebx
mov eax, 12
mov ebx, 1
int 64
pop ebx
End;
(* -------------------------------------------------------- *)
Procedure RedrawFinish; Asm
push ebx
mov eax, 12
mov ebx, 2
int 64
pop ebx
End;
(* -------------------------------------------------------- *)
Procedure DrawWindow; Asm
push ebx
push edi
xor eax, eax
mov ebx, [WindowLeft]
shl ebx, 16
add ebx, [WindowWidth]
mov ecx, [WindowTop]
shl ecx, 16
add ecx, [WindowHeight]
mov edx, [Style]
or edx, [BackColor]
mov edi, [Caption]
int 64
pop edi
pop ebx
End;
(* -------------------------------------------------------- *)
Function WaitEvent; Asm
mov eax, 10
int 64
End;
(* -------------------------------------------------------- *)
Function WaitEventByTime; Asm
push ebx
mov eax, 23
mov ebx, [time]
int 64
pop ebx
End;
(* -------------------------------------------------------- *)
Function GetKeyCode; Asm
mov eax, 2
int 64
End;
(* -------------------------------------------------------- *)
Function GetButtonNumber; Asm
mov eax, 17
int 64
shr eax, 8
End;
(* -------------------------------------------------------- *)
Procedure ThreadTerminate; Asm
or eax, -1
int 64
End;
(* -------------------------------------------------------- *)
Function GetScreenSize; Asm
push ebx
mov eax, 61
mov ebx, 1
int 64
pop ebx
End;
(* -------------------------------------------------------- *)
Procedure SetWindowPos; Asm
push ebx
push esi
mov eax, 67
mov ebx, [left]
mov ecx, [top]
mov edx, [right]
mov esi, [bottom]
int 64
pop esi
pop ebx
End;
(* -------------------------------------------------------- *)
End.