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
Finding List of Fonts & P...
by
J-G
[
Today
at 02:06:36 am]
Application triggers mess...
by
jamie
[
Today
at 12:37:30 am]
Star Wars Galaxian
by
flowCRANE
[
Today
at 12:27:35 am]
Fpcupdeluxe
by
ap3000
[August 07, 2026, 11:40:58 pm]
Gtk3 becomes default widg...
by
Bart
[August 07, 2026, 10:45:51 pm]
Create small language
by
DavidL
[August 07, 2026, 07:57:45 pm]
Lazarus for Windows on aa...
by
Martin_fr
[August 07, 2026, 07:41:36 pm]
Unleashed Pascal (async/a...
by
creaothceann
[August 07, 2026, 07:06:23 pm]
New Big Integer library i...
by
ad1mt
[August 07, 2026, 06:42:46 pm]
Identify network devices
by
LemonParty
[August 07, 2026, 03:03:16 pm]
how to connect to mariadb...
by
Mike.Cornflake
[August 07, 2026, 01:30:59 pm]
Automatic generation of *...
by
marcov
[August 07, 2026, 01:12:50 pm]
Multiple CodeAlign
by
marcov
[August 07, 2026, 11:52:54 am]
[SOLVED]SpeedButton Font
by
Petrus Vorster
[August 07, 2026, 10:29:10 am]
[SOLVED] Transparent Butt...
by
Petrus Vorster
[August 07, 2026, 10:05:53 am]
Lazarus undead repository...
by
Mike.Cornflake
[August 07, 2026, 09:44:08 am]
excel and word automation...
by
CM630
[August 07, 2026, 09:06:14 am]
Fast Canvas Library V1.05...
by
Gigatron
[August 07, 2026, 01:53:29 am]
MathParser and CrossGraph...
by
ypisareff
[August 07, 2026, 01:20:50 am]
[SOLVED] synEdit autoComp...
by
Weiss
[August 06, 2026, 09:19:53 pm]
TyControls: a custom-draw...
by
armandoboza
[August 06, 2026, 08:55:43 pm]
Random
by
Paolo
[August 06, 2026, 08:18:11 pm]
Using UTF8
by
ADMGNS
[August 06, 2026, 06:51:50 pm]
TFPHTTPServer extract par...
by
LemonParty
[August 06, 2026, 06:44:05 pm]
Using the "Messages" wind...
by
Martin_fr
[August 06, 2026, 02:20:26 pm]
« previous
next »
Print
Pages: [
1
]
Author
Topic: Matching video to form (Read 1504 times)
Pe3s
Guest
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
Hero Member
Posts: 583
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
A docile goblin always follow HERMES.md
Pe3s
Guest
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: 1687
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
Guest
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: 1687
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
Guest
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: 1687
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
Guest
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
Guest
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