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
Strange Mail from memo.mi...
by
Dzandaa
[
Today
at 11:41:56 am]
[Solved] Lazreport. Sorti...
by
Petrus Vorster
[
Today
at 11:39:09 am]
Strange Error when I use ...
by
TYDQ
[
Today
at 11:36:09 am]
Regarding the issue of de...
by
Martin_fr
[
Today
at 11:16:29 am]
[Windows] UTF8 encoding w...
by
Thaddy
[
Today
at 10:42:15 am]
Pleas help, Synapse / Ind...
by
patyit
[
Today
at 10:25:29 am]
would multi threading hel...
by
speter
[
Today
at 09:42:28 am]
Default, Manual Initializ...
by
Okoba
[
Today
at 09:17:22 am]
How to observe the value ...
by
yinhuajian
[
Today
at 05:50:14 am]
Cannot see unit text - ed...
by
lorenzo
[
Today
at 04:05:13 am]
AdvancedHTTPServer: A Go-...
by
egsuh
[
Today
at 01:44:33 am]
Perlin Noise Map With BGR...
by
Boleeman
[
Today
at 01:31:57 am]
What's wrong with my appl...
by
VisualLab
[
Today
at 01:04:16 am]
ThemeServices.OnThemeChan...
by
440bx
[
Today
at 12:16:35 am]
Cross Compile for Dos on ...
by
PascalDragon
[January 20, 2026, 10:54:36 pm]
Feature announcement: Fun...
by
PascalDragon
[January 20, 2026, 09:50:39 pm]
Access violation during d...
by
PascalDragon
[January 20, 2026, 09:49:09 pm]
IStringList...
by
PascalDragon
[January 20, 2026, 09:35:54 pm]
Strings in Free Pascal: I...
by
PascalDragon
[January 20, 2026, 09:33:09 pm]
Developing FreePascal on ...
by
HKPhysicist
[January 20, 2026, 08:59:53 pm]
Anti "churning" in solita...
by
andersonscinfo
[January 20, 2026, 08:37:14 pm]
[Solved] Exception in TFi...
by
d.oertel
[January 20, 2026, 06:18:05 pm]
Animated Sine Beziers
by
Boleeman
[January 20, 2026, 02:34:32 pm]
PadXml 1.0.0 – Portable A...
by
AlexanderT
[January 20, 2026, 02:04:18 pm]
Very simple Style Manager...
by
sgj
[January 20, 2026, 09:29:05 am]
« previous
next »
Print
Pages: [
1
]
Author
Topic: Matching video to form (Read 1010 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