-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathmmpWindowUtils.pas
More file actions
596 lines (473 loc) · 23 KB
/
mmpWindowUtils.pas
File metadata and controls
596 lines (473 loc) · 23 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
{ MMP: Minimalist Media Player
Copyright (C) 2021-2099 Baz Cuda
https://github.com/BazzaCuda/MinimalistMediaPlayerX
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA
}
unit mmpWindowUtils;
interface
uses
winApi.windows,
system.classes, system.SyncObjs,
vcl.forms,
mmpNotify.notices, mmpNotify.notifier, mmpNotify.subscriber,
mmpAction, mmpConsts, mmpGlobalState;
function mmpAdjustAspectRatio (const aWND: HWND; const aHeight: integer): TPoint;
function mmpAnimateResize(const aTargetForm: TForm; const aTargetWidth: integer; const aTargetHeight: integer; const aWidthDelta: integer; const aHeightDelta: integer; const aCenter: boolean; const aDurationMs: integer; var aCancel: boolean): TVoid; overload;
function mmpAnimateResize(const aWND: HWND; const aTargetWidth: integer; const aTargetHeight: integer; const aWidthDelta: integer; const aHeightDelta: integer; const aCenter: boolean; const aDurationMs: integer; var aCancel: boolean): TVoid; overload;
function mmpAnimateShrink(const aWND: HWND; const aTargetWidth: integer; const aTargetHeight: integer; const aDurationMs: integer): TVoid;
function mmpArrangeAll (const aWND: HWND): boolean;
function mmpCalcGreaterWindow (const aWND: HWND; const aShiftState: TShiftState; const aThumbSize: integer; const aHostType: THostType): TPoint;
function mmpCalcWindowSize (const aStartingHeight: integer; const bMaxSize: boolean): TPoint;
function mmpCenterWindow (const aWND: HWND; const aPt: TPoint; const aFlags: Cardinal = SWP_NOSIZE): TVoid;
function mmpGreaterWindow (const aWND: HWND; aShiftState: TShiftState): integer; overload;
function mmpGreaterWindow (const aWND: HWND; const aShiftState: TShiftState; const aThumbSize: integer; const aHostType: THostType): TVoid; overload;
function mmpPosWinXY (const aWND: HWND; const x: integer; const y: integer): TVoid;
function mmpSetWindowPos (const aWND: HWND; aPt: TPoint; const aWidth: integer = 0; const aHeight: integer = 0; const aFlags: cardinal = SWP_NOSIZE): TVoid;
function mmpSetWindowTop (const aWND: HWND): TVoid;
function mmpSetWindowTopmost (const aWND: HWND): TVoid;
function mmpSetWindowSize (const aWND: HWND; aPt: TPoint): TVoid;
function mmpWinXY (const aWND: HWND): TPoint;
implementation
uses
winApi.messages,
system.math, system.types,
bazCmd,
mmpDesktopUtils, mmpPostToAllUtils, mmpUtils,
_debugWindow;
function mmpAdjustAspectRatio(const aWND: HWND; const aHeight: integer): TPoint;
var
vWidth: integer;
MPmediaType: TMediaType;
MPvideoWidth: integer;
MPvideoHeight: integer;
function adjustWidthForAspectRatio: integer;
begin
result := -1;
case (MPvideoWidth <= 0) OR (MPvideoHeight <= 0) of TRUE: EXIT; end;
result := round(aHeight / MPvideoHeight * MPvideoWidth);
end;
function getMediaInfo: TVoid;
begin
MPmediaType := GS.mediaType;
MPvideoWidth := mmp.cmd(evMPReqVideoWidth).integer;
MPvideoHeight := mmp.cmd(evMPReqVideoHeight).integer;
// debugFormat('MP.x:%d, MP.y:%d', [MPvideoWidth, MPvideoHeight]);
end;
begin
result := point(0, 0);
getMediaInfo;
vWidth := adjustWidthForAspectRatio;
vWidth := vWidth + 2; // allow for the mysterious 1-pixel border that Windows insists on drawing around a borderless window
result.x := vWidth;
result.y := aHeight + 2;
end;
function mmpAnimateResize(const aWND: HWND; const aTargetWidth: integer; const aTargetHeight: integer; const aWidthDelta: integer; const aHeightDelta: integer; const aCenter: boolean; const aDurationMs: integer; var aCancel: boolean): TVoid;
begin
var vWorkArea: TRect := screen.workareaRect;
var vLogicalHeight: integer := vWorkArea.height - aHeightDelta;
var vDesktopCenterX: integer := vWorkArea.left + (vWorkArea.width div 2);
var vDesktopCenterY: integer := vWorkArea.top + (vLogicalHeight div 2);
var vFreq: int64;
queryPerformanceFrequency(vFreq);
var vStartTick: int64;
queryPerformanceCounter(vStartTick);
var vTotalDurationSeconds: double := aDurationMs / 1000;
var vR: TRect;
getWindowRect(aWND, vR);
var vInitialWidth: integer := vR.width;
var vInitialHeight: integer := vR.height;
var vInitialLeft: integer := vR.left;
var vInitialTop: integer := vR.top;
case (vInitialWidth = aTargetWidth) and (vInitialHeight = aTargetHeight) {and (NOT aCenter)} of TRUE: EXIT; end;
var vProgress: double := 0;
while vProgress < 1.0 do
begin
case aCancel of TRUE: BREAK; end;
var vCurrentTick: int64;
queryPerformanceCounter(vCurrentTick);
var vElapsedSeconds: double := (vCurrentTick - vStartTick) / vFreq;
vProgress := min(1.0, max(0.0, vElapsedSeconds / vTotalDurationSeconds));
var vCurrentW: integer := vInitialWidth + round((aTargetWidth - vInitialWidth) * vProgress);
var vCurrentH: integer := vInitialHeight + round((aTargetHeight - vInitialHeight) * vProgress);
var vCurrentL: integer := vInitialLeft;
var vCurrentT: integer := vInitialTop;
case aCenter of
TRUE:
begin
// Calculate 'Ideal' position centered on the desktop for the video window
var vIdealL: integer := vDesktopCenterX - (vCurrentW div 2);
var vIdealT: integer := vDesktopCenterY - (vCurrentH div 2);
var vMaxAllowedR: integer := vWorkArea.left + vWorkArea.width;
// Check for overhang on Right and Bottom caused by Deltas
var vOverhangX: integer := max(0, (vIdealL + vCurrentW + aWidthDelta) - (vMaxAllowedR - 1));
var vOverhangY: integer := max(0, (vIdealT + vCurrentH) - (vWorkArea.top + vLogicalHeight));
// Subtract overhang to shift window only as much as necessary
vCurrentL := vIdealL - vOverhangX;
vCurrentT := vIdealT - vOverhangY;
// Prevent shifting into negative space/off-monitor
vCurrentL := max(vWorkArea.left, vCurrentL);
vCurrentT := max(vWorkArea.top, vCurrentT);
end;
end;
setWindowPos(aWND, 0, vCurrentL, vCurrentT, vCurrentW, vCurrentH, SWP_NOZORDER or SWP_NOACTIVATE or SWP_ASYNCWINDOWPOS);
updateWindow(aWND);
application.processMessages;
end;
end;
function mmpAnimateResize(const aTargetForm: TForm; const aTargetWidth: integer; const aTargetHeight: integer; const aWidthDelta: integer; const aHeightDelta: integer; const aCenter: boolean; const aDurationMs: integer; var aCancel: boolean): TVoid;
begin
mmpAnimateResize(aTargetForm.HANDLE, aTargetWidth, aTargetHeight, aWidthDelta, aHeightDelta, aCenter, aDurationMs, aCancel);
end;
function mmpAnimateShrink(const aWND: HWND; const aTargetWidth: integer; const aTargetHeight: integer; const aDurationMs: integer): TVoid;
begin
var vFreq: int64;
queryPerformanceFrequency(vFreq);
var vStartTick: int64;
queryPerformanceCounter(vStartTick);
var vTotalDurationSeconds: double := aDurationMs / 1000;
var vR: TRect;
getWindowRect(aWND, vR);
var vInitialWidth: integer := vR.width;
var vInitialHeight: integer := vR.height;
var vInitialLeft: integer := vR.left;
var vInitialTop: integer := vR.top;
// identify the fixed anchor point: the current center of the window
var vAnchorX: integer := vInitialLeft + (vInitialWidth div 2);
var vAnchorY: integer := vInitialTop + (vInitialHeight div 2);
var vProgress: double := 0;
while vProgress < 1.0 do
begin
var vCurrentTick: int64;
queryPerformanceCounter(vCurrentTick);
var vElapsedSeconds: double := (vCurrentTick - vStartTick) / vFreq;
vProgress := min(1.0, max(0.0, vElapsedSeconds / vTotalDurationSeconds));
var vCurrentW: integer := vInitialWidth + round((aTargetWidth - vInitialWidth) * vProgress);
var vCurrentH: integer := vInitialHeight + round((aTargetHeight - vInitialHeight) * vProgress);
// calculate top/left so the midpoint remains at the anchor point
var vCurrentL: integer := vAnchorX - (vCurrentW div 2);
var vCurrentT: integer := vAnchorY - (vCurrentH div 2);
setWindowPos(aWND, 0, vCurrentL, vCurrentT, vCurrentW, vCurrentH, SWP_NOZORDER or SWP_NOACTIVATE or SWP_ASYNCWINDOWPOS);
updateWindow(aWND);
application.processMessages;
end;
end;
function mmpCalcWindowSize(const aStartingHeight: integer; const bMaxSize: boolean): TPoint;
{$J+} const vPrevVideoHeight: integer = 0; vPrevImageHeight: integer = 0; {$J-}
var
vWidth: integer;
vHeight: integer;
vStartingHeight: integer;
MPmediaType: TMediaType;
MPvideoWidth: integer;
MPvideoHeight: integer;
MIhasCoverArt: boolean;
function adjustWidthForAspectRatio: integer;
begin
result := -1;
case (MPvideoWidth = 0) or (MPvideoHeight = 0) of TRUE: EXIT; end;
result := trunc(vHeight / MPvideoHeight * MPvideoWidth);
end;
function getMediaInfo: TVoid;
begin
MPmediaType := GS.mediaType;
MPvideoWidth := GS.mpvWidth;
MPvideoHeight := GS.mpvHeight;
MIhasCoverArt := mmp.cmd(evMIReqHasCoverArt).tf;
// debugFormat('getMediaInfo MP.x:%d, MP.y:%d', [MPvideoWidth, MPvideoHeight]);
end;
function withinScreenLimits: boolean;
begin
var vDelta := mmpIfThenElse(GS.showingTimeline, GS.widthStreamlist, GS.widthHelp + GS.widthPlaylist); // at least one of widthHelp and widthPlaylist will be zero
result := (vWidth + vDelta <= mmpScreenWidth) and (vHeight <= mmpScreenHeight);
end;
begin
// debugBoolean('bMaxSize', bMaxsize);
// debugInteger('aStartingHeight', aStartingHeight);
// debugInteger('WorkAreaWidth', Screen.WorkAreaWidth); // requires vcl.forms
// debugInteger('WorkAreaHeight', Screen.WorkAreaHeight); // ditto
MPvideoWidth := 0; MPvideoHeight := 0;
getMediaInfo;
case MPmediaType of mtAudio: begin case MIhasCoverArt of TRUE: vWidth := 600;
FALSE: vWidth := 600; end;
case MIhasCoverArt of TRUE: vHeight := 400;
FALSE: vHeight := UI_DEFAULT_AUDIO_HEIGHT; end;
case MIhasCoverArt of TRUE: vWidth := adjustWidthForAspectRatio; end;
end;
mtVideo: begin
vStartingHeight := aStartingHeight;
case bMaxSize of TRUE: vStartingHeight := -1; end;
case (vStartingHeight <> -1) and (vStartingHeight <= UI_DEFAULT_AUDIO_HEIGHT) of TRUE: vStartingHeight := vPrevVideoHeight; end;
case (vStartingHeight <> -1) and (vStartingHeight <= UI_DEFAULT_AUDIO_HEIGHT) of TRUE: vStartingHeight := -1; end;
case vStartingHeight = -1 of
TRUE: vHeight := mmpScreenHeight - 30;
FALSE: vHeight := vStartingHeight; end;
vWidth := adjustWidthForAspectRatio;
while NOT withinScreenLimits do
begin
vHeight := vHeight - 30;
vWidth := adjustWidthForAspectRatio;
end;
vPrevVideoHeight := vHeight;
end;
mtImage: begin
//debugFormat('CWS: %d x %d', [MPvideoWidth, MPvideoHeight]);
vStartingHeight := aStartingHeight;
case GS.maxSize of TRUE: vStartingHeight := -1; end;
case (vStartingHeight <> -1) and (vStartingHeight <= UI_DEFAULT_AUDIO_HEIGHT) of TRUE: vStartingHeight := vPrevImageHeight; end;
case (vStartingHeight <> -1) and (vStartingHeight <= UI_DEFAULT_AUDIO_HEIGHT) of TRUE: vStartingHeight := -1; end;
case vStartingHeight = -1 of TRUE: begin
vWidth := trunc((mmpScreenHeight - 20) * 1.5); // EXPERIMENTAL WAS 100
vHeight := mmpScreenHeight - 20; end; // EXPERIMENTAL WAS 100
FALSE: begin
vWidth := trunc(vStartingHeight * 1.5);
vHeight := vStartingHeight; end;end;
//vWidth := adjustWidthForAspectRatio; // NO!
while NOT withinScreenLimits do
begin
vWidth := vWidth - 30;
vHeight := vHeight - 30;
end;
vPrevImageHeight := vHeight;
end;
end;
result.x := vWidth;
result.y := vHeight;
end;
function mmpArrangeAll(const aWND: HWND): boolean;
var
vCount: integer;
vWidth: integer;
vHeight: integer;
vScreenWidth: integer;
vScreenHeight: integer;
vZero: integer;
vHMiddle: integer;
//vVMiddle: integer;
begin
result := FALSE;
mmp.cmd(evGSArrangeAll, TRUE); // ignore MMPs showing the Image & Thumbnail Browser
vCount := mmp.cmd(evPAReqCount).integer;
case vCount = 0 of TRUE: EXIT; end; // HOW!?
mmp.cmd(evGSAutoCenter, vCount = 1);
case GS.autoCenter of FALSE: begin
mmp.cmd(evPAPostToEvery, WIN_AUTOCENTER_OFF);
mmp.cmd(evPAPostToEvery, WIN_MAX_SIZE_OFF); end;end;
mmp.cmd(evPAPostToEvery, WIN_SKIP_ANIMATION); // tell each window to skip the next animation in TVM.resizeWindow
var vMsg: TMessage;
vMsg := default(TMessage);
case vCount of
1: vMsg.WParam := mmpScreenWidth;
2: vMsg.WParam := mmpScreenWidth div 2;
3, 4: vMsg.LParam := mmpScreenHeight div 2;
else vMsg.WParam := mmpScreenWidth div vCount;
end;
vMsg.msg := WIN_RESIZE;
mmp.cmd(evPAPostToEveryEx, vMsg); // this rebuilds the list of HWNDs
mmpProcessMessages; // make sure this window has resized before continuing
mmpWndWidthHeight(aWND, vWidth, vHeight);
vScreenWidth := mmpScreenWidth;
vScreenHeight := mmpScreenHeight;
vHMiddle := vScreenWidth div 2;
// vVMiddle := vScreenHeight div 2;
vZero := vHMiddle - vWidth;
vCount := mmp.cmd(evPAReqCount).integer;
var vHWND := 0;
mmp.cmd(evGSArrangeAll, FALSE); // ensure that subsequent universal commands go to all MMPs
case vCount = 2 of TRUE: begin
mmpPosWinXY(PA[1], vZero, (vScreenHeight - vHeight) div 2);
mmpPosWinXY(PA[2], vHMiddle, (vScreenHeight - vHeight) div 2);
case mmpOffScreen(PA[1]) of TRUE: mmpPosWinXY(PA[1], vZero, 0); end;
case mmpOffScreen(PA[2]) of TRUE: mmpPosWinXY(PA[2], vHMiddle, 0); end;
vHWND := PA[1];
end;end;
case vCount in [3, 4] of TRUE: begin
mmpPosWinXY(PA[1], vZero, 0 + 40);
mmpPosWinXY(PA[2], vHMiddle, 0 + 40); end;end;
case vCount = 3 of TRUE: mmpPosWinXY(PA[3], vHMiddle - (vWidth div 2), vHeight + 40); end;
case vCount = 4 of TRUE: begin
mmpPosWinXY(PA[3], vZero, vHeight + 40);
mmpPosWinXY(PA[4], vHMiddle, vHeight + 40); end;end;
case vCount > 4 of TRUE: for var i := 1 to vCount do mmpPosWinXY(PA[i], ((mmpScreenWidth div vCount) * (i - 1)), 100); end;
case vHWND <> 0 of TRUE: begin mmpDelay(100); mmpPosWinXY(vHWND, mmpScreenCentre - vWidth, mmpWinXY(vHWND).Y); end;end; // hack for tall, narrow, TikTok-type windows
setForegroundWindow(aWnd);
result := TRUE;
end;
function mmpCalcGreaterWindow(const aWND: HWND; const aShiftState: TShiftState; const aThumbSize: integer; const aHostType: THostType): TPoint;
var
dx: integer;
dy: integer;
newW: integer;
newH: integer;
vR: TRect;
function calcDeltas: TVoid;
begin
case aHostType of
htMPVHost: begin
dx := 50;
dy := 30;
end;
htThumbsHost: begin
dx := aThumbSize + THUMB_MARGIN;
dy := aThumbSize + THUMB_MARGIN;
end;
end;
end;
function checkDesktop: TVoid;
begin
case ssCtrl in aShiftState of TRUE: begin
case newW - dx < dx of TRUE: dx := 0; end;
case newH - dy < dy of TRUE: dy := 0; end;end;
FALSE: begin
case newW + dx > mmpScreenWidth of TRUE: dx := 0; end;
case newH + dy > mmpScreenHeight of TRUE: dy := 0; end;end;end;
end;
function calcDimensions: TVoid;
begin
case ssCtrl in aShiftState of
TRUE: begin
newW := newW - dx;
newH := newH - dy;
end;
FALSE: begin
newW := newW + dx;
newH := newH + dy;
end;
end;
end;
begin
getWindowRect(aWND, vR);
newW := vR.Width;
newH := vR.height;
// debugInteger('greaterWindow vR.height', vR.height);
// TDebug.debugEnum<THostType>('aHostType', aHostType);
calcDeltas;
checkDesktop;
calcDimensions; // do what the user requested
result := point(newW, newH);
end;
function mmpCenterWindow(const aWND: HWND; const aPt: TPoint; const aFlags: Cardinal = SWP_NOSIZE): TVoid;
// aPt is optional and provides the calculated dimensions that a window is going to have
var
vR: TRect;
vHPos: integer;
vVPos: integer;
function alreadyCentred: boolean;
begin
var vWidthDelta := mmpIfThenElse(GS.showingTimeline, GS.widthStreamlist, GS.widthHelp + GS.widthPlaylist); // at least one of either widthHelp or widthPlaylist will be zero
vHPos := ((mmpScreenWidth - vR.width) div 2);
case vHPos + vR.width + vWidthDelta > mmpScreenWidth of TRUE: vHPos := mmpScreenWidth - vR.width - vWidthDelta - 1; end; // only shift left if necessary
// ensure we never shift into negative space (left monitor)
case vHPos < 0 of TRUE: vHPos := 0; end;
vVPos := (mmpScreenHeight - vR.height) div 2;
case vVPos + vR.height > mmpScreenHeight of TRUE: vVPos := mmpScreenHeight - vR.height - 1; end;
// ensure we never shift into negative space (top monitor)
case vVPos < 0 of TRUE: vVPos := 0; end;
result := (vR.left = vHPos) and (vR.top = vVPos);
end;
begin
getWindowRect(aWND, vR);
case (aPt.x <> 0) and (aPt.y <> 0) of TRUE: begin // override the current dimensions with those provided
vR.width := aPt.x;
vR.height := aPt.y; end;end;
case alreadyCentred of TRUE: EXIT; end;
case (vHPos >= 0) and (vVPos >= 0) of TRUE: mmpSetWindowPos(aWND, point(vHPos, vVPos), vR.width, vR.height, aFlags); end;
mmp.cmd(evGSAutoCenter, TRUE);
end;
function mmpGreaterWindow(const aWND: HWND; aShiftState: TShiftState): integer;
var
vR: TRect;
begin
getWindowRect(aWND, vR);
GS.notify(newNotice(evGSMaxSize, FALSE)); // pressing [M] reinstates maxSize
result := mmp.use<integer>(ssCtrl in aShiftState, vR.height - 30, vR.height + 30);
end;
function mmpGreaterWindow(const aWND: HWND; const aShiftState: TShiftState; const aThumbSize: integer; const aHostType: THostType): TVoid;
var
dx: integer;
dy: integer;
newW: integer;
newH: integer;
vR: TRect;
function calcDeltas: TVoid;
begin
case aHostType of
htMPVHost: begin
dx := 50;
dy := 30;
end;
htThumbsHost: begin
dx := aThumbSize + THUMB_MARGIN;
dy := aThumbSize + THUMB_MARGIN;
end;
end;
end;
function checkDesktop: TVoid;
begin
case ssCtrl in aShiftState of TRUE: begin
case newW - dx < dx of TRUE: dx := 0; end;
case newH - dy < dy of TRUE: dy := 0; end;end;
FALSE: begin
case newW + dx > mmpScreenWidth of TRUE: dx := 0; end;
case newH + dy > mmpScreenHeight of TRUE: dy := 0; end;end;end;
end;
function calcDimensions: TVoid;
begin
case ssCtrl in aShiftState of
TRUE: begin
newW := newW - dx;
newH := newH - dy;
end;
FALSE: begin
newW := newW + dx;
newH := newH + dy;
end;
end;
end;
begin
getWindowRect(aWND, vR);
newW := vR.Width;
newH := vR.height;
// debugInteger('greaterWindow vR.height', vR.height);
// TDebug.debugEnum<THostType>('aHostType', aHostType);
calcDeltas;
checkDesktop;
calcDimensions; // do what the user requested
mmpSetWindowSize(aWND, point(newW, newH)); // resize the window
end;
function mmpPosWinXY(const aWND: HWND; const x: integer; const y: integer): TVoid;
begin
mmpSetWindowPos(aWND, point(x, y));
end;
function mmpSetWindowPos(const aWND: HWND; aPt: TPoint; const aWidth: integer = 0; const aHeight: integer = 0; const aFlags: cardinal = SWP_NOSIZE): TVoid;
begin
setWindowPos(aWND, HWND_TOP, aPt.x, aPt.y, aWidth, aHeight, aFlags);
end;
function mmpSetWindowSize(const aWND: HWND; aPt: TPoint): TVoid;
begin
setWindowPos(aWND, HWND_TOP, 0, 0, aPt.x, aPt.y, SWP_NOMOVE);
end;
function mmpSetWindowTop(const aWND: HWND): TVoid;
begin
setWindowPos(aWND, HWND_TOP, 0, 0, 0, 0, SWP_NOSIZE + SWP_NOMOVE);
end;
function mmpSetWindowTopmost(const aWND: HWND): TVoid;
begin
setWindowPos(aWND, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOSIZE + SWP_NOMOVE);
end;
function mmpWinXY(const aWND: HWND): TPoint;
var vR: TRect;
begin
getWindowRect(aWnd, vR);
result := vR.location;
end;
end.