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
[SOLVED] Lazreport Horizo...
by
Petrus Vorster
[
Today
at 08:03:05 am]
We are starting to use La...
by
ALLIGATOR
[
Today
at 05:19:46 am]
The Future of FPC
by
ALLIGATOR
[
Today
at 05:01:20 am]
ThorVG - test (lightweigh...
by
ALLIGATOR
[
Today
at 04:55:46 am]
fpGUI Toolkit v2.0.1 has ...
by
cdbc
[
Today
at 02:27:42 am]
[ANN] fpGUI Toolkit v2.0....
by
Graeme
[
Today
at 01:43:31 am]
Frustrating Error When us...
by
TYDQ
[
Today
at 01:38:26 am]
Fast Canvas Library V1.05...
by
backprop
[
Today
at 01:32:51 am]
; after then
by
Martin_fr
[
Today
at 12:38:46 am]
Are the source files for ...
by
Martin_fr
[
Today
at 12:26:57 am]
Debian removes FPC/Lazaru...
by
kupferstecher
[February 13, 2026, 10:29:53 pm]
AVRPascal – free code edi...
by
ackarwow
[February 13, 2026, 10:08:59 pm]
Select rectangle of the i...
by
backprop
[February 13, 2026, 08:16:27 pm]
How to determine the unkn...
by
LV
[February 13, 2026, 07:37:32 pm]
how to enable multihelper...
by
mas steindorff
[February 13, 2026, 07:03:20 pm]
Lazarus/FreePascal Bug
by
Bart
[February 13, 2026, 06:27:28 pm]
Questions from a Windows ...
by
CM630
[February 13, 2026, 06:15:33 pm]
Duplicated icon in the Wi...
by
w click
[February 13, 2026, 05:47:49 pm]
AdvancedHTTPServer: A Go-...
by
LeP
[February 13, 2026, 03:01:15 pm]
Status of FPC 3.4.0 or FP...
by
gidesa
[February 13, 2026, 12:35:41 pm]
Notetask 1.1.1 - Free cro...
by
AlexanderT
[February 13, 2026, 12:00:08 pm]
Bee Hive solitaire
by
TBMan
[February 13, 2026, 03:22:09 am]
AI Created Music
by
Tony Stone
[February 13, 2026, 03:02:08 am]
Send form to true left an...
by
mas steindorff
[February 13, 2026, 02:39:34 am]
Help needed compiling
by
jamie
[February 13, 2026, 02:33:02 am]
« previous
next »
Print
Pages: [
1
]
Author
Topic: Matching video to form (Read 1056 times)
Pe3s
Hero Member
Posts: 641
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: 458
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: 641
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: 1568
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: 641
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: 1568
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: 641
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: 1568
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: 641
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: 641
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