Lazarus
Home
Help
TinyPortal
Search
Login
Register
Lazarus
»
Forum
»
Programming
»
Graphics and Multimedia
»
Audio and Video
»
Matching video to form
Free Pascal
Website
Downloads
Wiki
Documentation
Bugtracker
Mailing List
Lazarus
Website
Downloads (Laz+FPC)
Packages (OPM)
FAQ
Wiki
Documentation (RTL/FCL/LCL)
Bugtracker
CCR Bugs
GIT
Mailing List
Other languages
Foundation
Website
Useful Wiki Links
Project Roadmap
Getting the Source
Screenshots
How to use the forum
Forum Rules
About donations (wiki)
Bookstore
Computer Math and Games in Pascal
(preview)
Lazarus Handbook
Search
Advanced search
Recent
would multi threading hel...
by
MathMan
[
Today
at 03:49:15 pm]
Strange Error when I use ...
by
TYDQ
[
Today
at 03:14:50 pm]
FPCupDeluxe unable to bui...
by
Martin_fr
[
Today
at 02:57:15 pm]
Lazarus in Windows allowe...
by
LeP
[
Today
at 02:53:24 pm]
Perlin Map 3D
by
dergen
[
Today
at 02:20:25 pm]
Rolling releases Lazarus[...
by
marcov
[
Today
at 01:50:56 pm]
TRichMemo install shows "...
by
vinntec
[
Today
at 01:36:50 pm]
Lazarus Bugfix Release 4...
by
Martin_fr
[
Today
at 08:12:20 am]
Register global hotkey
by
Thaddy
[
Today
at 06:28:54 am]
X11Libre, finally and for...
by
Fred vS
[January 21, 2026, 10:20:53 pm]
Difference in formatting ...
by
Bart
[January 21, 2026, 09:49:01 pm]
What's wrong with my appl...
by
bourbon
[January 21, 2026, 09:04:40 pm]
How to observe the value ...
by
nouzi
[January 21, 2026, 06:26:13 pm]
Anti "churning" in solita...
by
TBMan
[January 21, 2026, 04:30:05 pm]
Lazarus for Windows on aa...
by
msintle
[January 21, 2026, 03:11:13 pm]
Perlin Noise Map With BGR...
by
Boleeman
[January 21, 2026, 01:36:13 pm]
Strange Mail from memo.mi...
by
Thaddy
[January 21, 2026, 01:27:19 pm]
[Solved] Lazreport. Sorti...
by
Petrus Vorster
[January 21, 2026, 11:39:09 am]
Regarding the issue of de...
by
Martin_fr
[January 21, 2026, 11:16:29 am]
[Windows] UTF8 encoding w...
by
Thaddy
[January 21, 2026, 10:42:15 am]
Pleas help, Synapse / Ind...
by
patyit
[January 21, 2026, 10:25:29 am]
Default, Manual Initializ...
by
Okoba
[January 21, 2026, 09:17:22 am]
Cannot see unit text - ed...
by
lorenzo
[January 21, 2026, 04:05:13 am]
AdvancedHTTPServer: A Go-...
by
egsuh
[January 21, 2026, 01:44:33 am]
ThemeServices.OnThemeChan...
by
440bx
[January 21, 2026, 12:16:35 am]
« previous
next »
Print
Pages: [
1
]
Author
Topic: Matching video to form (Read 1013 times)
Pe3s
Hero Member
Posts: 633
Matching video to form
«
on:
December 07, 2025, 07:41:42 pm »
I wrote a procedure that adjusts the form dimensions to the video dimensions, but I got stuck in one place, namely how to limit the form dimensions so that it does not go beyond the Windows taskbar?
Code: Pascal
[Select]
[+]
[-]
procedure
TForm1
.
ResizeFormToVideo
;
var
VW
,
VH
:
Integer
;
WA
:
TRect
;
MaxW
,
MaxH
:
Integer
;
BW
,
BH
:
Integer
;
AR
:
Double
;
FW
,
FH
:
Integer
;
AvH
:
Integer
;
SL
:
Integer
;
begin
VW
:
=
MPVPlayer1
.
GetVideoWidth
;
VH
:
=
MPVPlayer1
.
GetVideoHeight
;
if
(
VW <
=
0
)
or
(
VH <
=
0
)
then
Exit
;
AR
:
=
VW
/
VH
;
SystemParametersInfo
(
SPI_GETWORKAREA
,
0
,
@
WA
,
0
)
;
MaxW
:
=
WA
.
Right
-
WA
.
Left
;
MaxH
:
=
WA
.
Bottom
-
WA
.
Top
;
BW
:
=
Width
-
ClientWidth
;
BH
:
=
Height
-
ClientHeight
;
FH
:
=
MaxH
;
AvH
:
=
FH
-
BH
;
FW
:
=
Trunc
(
AvH
*
AR
)
+
BW
;
if
FW > MaxW
then
begin
FW
:
=
MaxW
;
AvH
:
=
Trunc
(
(
FW
-
BW
)
/
AR
)
;
FH
:
=
Trunc
(
AvH
)
+
BH
;
end
;
SL
:
=
WA
.
Left
+
(
MaxW
-
FW
)
div
2
;
SetBounds
(
SL
,
WA
.
Top
,
FW
,
FH
)
;
end
;
Logged
Thausand
Sr. Member
Posts: 457
Re: Matching video to form
«
Reply #1 on:
December 07, 2025, 09:48:04 pm »
May be you have same situate as describe here (
https://learn.microsoft.com/en-us/answers/questions/760561/how-do-i-find-the-size-of-the-available-display-ex
) ?
Logged
Pe3s
Hero Member
Posts: 633
Re: Matching video to form
«
Reply #2 on:
December 09, 2025, 12:24:33 pm »
Is there any other way to calculate the workspace limited to the taskbar?
Logged
paweld
Hero Member
Posts: 1561
Re: Matching video to form
«
Reply #3 on:
December 09, 2025, 12:50:39 pm »
Code: Pascal
[Select]
[+]
[-]
Screen
.
WorkAreaHeight
eg.
Code: Pascal
[Select]
[+]
[-]
uses
LCLIntf
,
LCLType
;
procedure
TForm1
.
Button1Click
(
Sender
:
TObject
)
;
var
tp
,
s
:
String
;
begin
Memo1
.
Lines
.
Clear
;
Memo1
.
Lines
.
Add
(
Format
(
'Titlebar height: %d'
,
[
GetSystemMetrics
(
SM_CXFRAME
)
+
GetSystemMetrics
(
SM_CYSMCAPTION
)
]
)
)
;
Memo1
.
Lines
.
Add
(
Format
(
'Fullscreen size: %d x %d'
,
[
Screen
.
Width
,
Screen
.
Height
]
)
)
;
Memo1
.
Lines
.
Add
(
Format
(
'Workarea size: %d x %d'
,
[
Screen
.
WorkAreaWidth
,
Screen
.
WorkAreaHeight
]
)
)
;
if
(
Screen
.
Width
=
Screen
.
WorkAreaWidth
)
and
(
Screen
.
Height
=
Screen
.
WorkAreaHeight
)
then
Memo1
.
Lines
.
Add
(
'Taskbar not visible or autohide enabled'
)
else
begin
tp
:
=
'bottom'
;
if
Screen
.
WorkAreaLeft
>
0
then
tp
:
=
'left'
else
if
Screen
.
WorkAreaTop
>
0
then
tp
:
=
'top'
else
if
Screen
.
WorkAreaWidth
< Screen
.
Width
then
tp
:
=
'rigth'
;
if
(
tp
=
'bottom'
)
or
(
tp
=
'top'
)
then
s
:
=
Format
(
'Taskbar height: %d'
,
[
Screen
.
Height
-
Screen
.
WorkAreaHeight
]
)
else
s
:
=
Format
(
'Taskbar width: %d'
,
[
Screen
.
Width
-
Screen
.
WorkAreaWidth
]
)
;
Memo1
.
Lines
.
Add
(
s
)
;
Memo1
.
Lines
.
Add
(
Format
(
'Taskbar position: %s'
,
[
tp
]
)
)
;
end
;
end
;
Logged
Best regards / Pozdrawiam
paweld
Pe3s
Hero Member
Posts: 633
Re: Matching video to form
«
Reply #4 on:
December 09, 2025, 09:40:53 pm »
I corrected the code, but the form still goes beyond the task bar.
How can I calculate this? Where am I making a mistake?
Code: Pascal
[Select]
[+]
[-]
procedure
TForm1
.
ResizeFormToVideo
;
var
VW
,
VH
:
Integer
;
// wideo width/height
AR
:
Double
;
// aspect ratio
MaxW
,
MaxH
:
Integer
;
BW
,
BH
:
Integer
;
// ramki okna
FW
,
FH
:
Integer
;
// final width/height
AvW
,
AvH
:
Integer
;
// dostępna przestrzeń klienta
begin
// Pobierz wymiary wideo
VW
:
=
MPVPlayer1
.
GetVideoWidth
;
VH
:
=
MPVPlayer1
.
GetVideoHeight
;
if
(
VW <
=
0
)
or
(
VH <
=
0
)
then
Exit
;
AR
:
=
VW
/
VH
;
// Dostępna przestrzeń ekranu (bez taskbara)
MaxW
:
=
Screen
.
WorkAreaWidth
;
MaxH
:
=
Screen
.
WorkAreaHeight
;
// Oblicz rozmiar ramek okna
BW
:
=
Width
-
ClientWidth
;
BH
:
=
Height
-
ClientHeight
;
// Najpierw dopasuj do wysokości ekranu
AvH
:
=
MaxH
-
BH
;
// dostępna wysokość client area
AvW
:
=
Trunc
(
AvH
*
AR
)
;
// szerokość z proporcji
// Gdyby szerokość przekraczała ekran — dopasuj do szerokości
if
AvW
+
BW > MaxW
then
begin
AvW
:
=
MaxW
-
BW
;
AvH
:
=
Trunc
(
AvW
/
AR
)
;
end
;
// Finalny rozmiar okna
FW
:
=
AvW
+
BW
;
FH
:
=
AvH
+
BH
;
// Wyśrodkuj na ekranie roboczym
SetBounds
(
Screen
.
WorkAreaLeft
+
(
MaxW
-
FW
)
div
2
,
Screen
.
WorkAreaTop
,
FW
,
FH
)
;
end
;
«
Last Edit: December 09, 2025, 09:43:38 pm by Pe3s
»
Logged
paweld
Hero Member
Posts: 1561
Re: Matching video to form
«
Reply #5 on:
December 10, 2025, 08:44:46 am »
You've overcomplicated the calculations. . All you need to do is calculate the window reduction scale and apply it to the video size. In the example, I also showed how to get the height of the title bar and frames.
Code: Pascal
[Select]
[+]
[-]
procedure
TForm1
.
ResizeFormToVideo
;
var
VW
,
VH
:
Integer
;
// wideo width/height
Scale
:
Double
;
MaxW
,
MaxH
:
Integer
;
FW
,
FH
:
Integer
;
// final width/height
begin
// Pobierz wymiary wideo
VW
:
=
MPVPlayer1
.
GetVideoWidth
;
VH
:
=
MPVPlayer1
.
GetVideoHeight
;
if
(
VW <
=
0
)
or
(
VH <
=
0
)
then
Exit
;
// Dostępna przestrzeń ekranu (bez taskbara)
MaxW
:
=
Screen
.
WorkAreaWidth
-
2
*
GetSystemMetrics
(
SM_CXFRAME
)
;
//szerokość bez ewentualnego taskbara i ramek
MaxH
:
=
Screen
.
WorkAreaHeight
-
2
*
GetSystemMetrics
(
SM_CYFRAME
)
-
GetSystemMetrics
(
SM_CYSMCAPTION
)
;
//wysokość bez ewentualnego taskbara, ramek i paska tytułowego okna
// Finalny rozmiar okna
Scale
:
=
1
;
FW
:
=
VW
;
FH
:
=
VH
;
if
(
VW > MaxW
)
or
(
VH > MaxH
)
then
begin
Scale
:
=
MaxW
/
VW
;
if
(
MaxH
/
VH
)
< Scale
then
Scale
:
=
MaxH
/
VH
;
FW
:
=
Trunc
(
VW
*
Scale
)
;
FH
:
=
Trunc
(
VH
*
Scale
)
;
end
;
// Wyśrodkuj na ekranie roboczym
SetBounds
(
Screen
.
WorkAreaLeft
+
(
MaxW
-
FW
)
div
2
,
Screen
.
WorkAreaTop
+
(
MaxH
-
FH
)
div
2
,
FW
,
FH
)
;
end
;
Logged
Best regards / Pozdrawiam
paweld
Pe3s
Hero Member
Posts: 633
Re: Matching video to form
«
Reply #6 on:
December 10, 2025, 01:54:30 pm »
@paweld, I have one more question: is it possible to add the option of scaling from the bottom and top to this procedure? Currently, it only scales from the left and right sides and corners. Is there another option for proportional scaling with the possibility of maximizing the form? Best regards
Code: Pascal
[Select]
[+]
[-]
procedure
TForm1
.
HandleSizing
(
var
Msg
:
TLMessage
)
;
Const
Aspect
=
16
/
9
;
begin
With
WindowPos
(
Pointer
(
Msg
.
Lparam
)
^
)
do
Begin
cy
:
=
Round
(
cx
/
Aspect
)
;
end
;
end
;
Logged
paweld
Hero Member
Posts: 1561
Re: Matching video to form
«
Reply #7 on:
December 11, 2025, 06:40:24 am »
I'm sorry, but I don't quite understand your question—could you give me an example?
Logged
Best regards / Pozdrawiam
paweld
Pe3s
Hero Member
Posts: 633
Re: Matching video to form
«
Reply #8 on:
December 11, 2025, 10:56:47 am »
Here is an example
Code: Pascal
[Select]
[+]
[-]
procedure
TForm1
.
HandleSizing
(
var
Msg
:
TLMessage
)
;
const
Aspect
=
16
/
9
;
var
R
:
PWindowPos
;
begin
R
:
=
PWindowPos
(
Msg
.
LParam
)
;
// Jeśli użytkownik zmienia szerokość — dopasuj wysokość
if
R
^
.
cx
<> Width
then
R
^
.
cy
:
=
Round
(
R
^
.
cx
/
Aspect
)
// Jeśli użytkownik zmienia wysokość — dopasuj szerokość
else
if
R
^
.
cy
<> Height
then
R
^
.
cx
:
=
Round
(
R
^
.
cy
*
Aspect
)
;
end
;
Logged
Pe3s
Hero Member
Posts: 633
Re: Matching video to form
«
Reply #9 on:
December 17, 2025, 01:11:07 pm »
How can I combine the procedures into one?
Width
Code: Pascal
[Select]
[+]
[-]
const
Aspect
=
16
/
9
;
procedure
TForm1
.
FormResize
(
Sender
:
TObject
)
;
begin
Constraints
.
MinHeight
:
=
Round
(
Width
/
Aspect
)
;
Constraints
.
MaxHeight
:
=
Constraints
.
MinHeight
;
end
;
Height
Code: Pascal
[Select]
[+]
[-]
procedure
TForm1
.
FormResize
(
Sender
:
TObject
)
;
begin
Constraints
.
MinWidth
:
=
Round
(
Height
*
Aspect
)
;
Constraints
.
MaxWidth
:
=
Constraints
.
MinWidth
;
end
;
Logged
Print
Pages: [
1
]
« previous
next »
Lazarus
»
Forum
»
Programming
»
Graphics and Multimedia
»
Audio and Video
»
Matching video to form
TinyPortal
© 2005-2018