* * *

Author Topic: [SOLVED]Some problems about wsFullScreen  (Read 622 times)

tomitomy

  • Full Member
  • ***
  • Posts: 201
[SOLVED]Some problems about wsFullScreen
« on: October 11, 2017, 02:18:27 pm »
Hi, i have encountered some problems while running the following code, the result is not what i want.

------------------------------------------------------------

OS: Linux Mint 18.2 MATE-64Bit
Lazarus: 1.8.0 RC4 (FPC 3.0.4)

Code:
Code: Pascal  [Select]
  1. procedure TForm1.FormKeyPress(Sender: TObject; var Key: char);
  2. begin
  3.   if WindowState = wsFullScreen then
  4.     WindowState := wsNormal
  5.   else
  6.     WindowState := wsFullScreen;
  7. end;

Running result:
Code: [Select]
Press Key         WindowState
1 times           wsFullScreen
2 times           wsFullScreen
3 times           wsNormal
4 times           wsFullScreen
5 times           wsFullScreen
6 times           wsNormal

------------------------------------------------------------

OS: Windows 7-64Bit
Lazarus: 1.6.4 (FPC 3.0.2)

The same code:
Code: Pascal  [Select]
  1. procedure TForm1.FormKeyPress(Sender: TObject; var Key: char);
  2. begin
  3.   if WindowState = wsFullScreen then
  4.     WindowState := wsNormal
  5.   else
  6.     WindowState := wsFullScreen;
  7. end;

Running result:
Code: [Select]
Press Key         WindowState
1 times           wsMaximized
2 times           wsMaximized
3 times           wsNormal
4 times           wsMaximized
5 times           wsMaximized
6 times           wsNormal

------------------------------------------------------------

I want the window to switch between wsFullScreen and wsNormal, but the result is not, is this a issue?

« Last Edit: November 07, 2017, 02:27:36 pm by tomitomy »

ASerge

  • Sr. Member
  • ****
  • Posts: 472
Re: Some problems about wsFullScreen
« Reply #1 on: October 11, 2017, 11:09:25 pm »
I will say only for Windows.
In Windows, there is no FullScreen status, only Maximized. Lazarus passes this value in both cases. As a result:
1. WindowState := wsFullScreen
  ShowWindow(SW_SHOWMAXIMIZED).
  System message WM_SIZE.
  Form proc Resizing.
  WindowState := wsMaximized.
2. WindowState := wsFullScreen
  ShowWindow(SW_SHOWMAXIMIZED).
3. WindowsState := wsNormal
  ShowWindow(SW_SHOWNORMAL).
  System message WM_SIZE.
  Form proc Resizing.
  WindowState := wsNormal

Test:
Code: Pascal  [Select]
  1. function WindowStateToStr(State: TWindowState): string;
  2. const
  3.   CText: array [TWindowState] of string = (
  4.     'wsNormal', 'wsMinimized', 'wsMaximized', 'wsFullScreen');
  5. begin
  6.   Result := CText[State];
  7. end;
  8.  
  9. procedure TForm1.FormKeyPress(Sender: TObject; var Key: char);
  10. begin
  11.   if WindowState = wsFullScreen then
  12.     WindowState := wsNormal
  13.   else
  14.     WindowState := wsFullScreen;
  15.   Caption := 'After key press: ' + WindowStateToStr(WindowState);
  16. end;

tomitomy

  • Full Member
  • ***
  • Posts: 201
Re: Some problems about wsFullScreen
« Reply #2 on: October 12, 2017, 07:35:16 am »
I will say only for Windows.

Thank you for your explanation, I have understood.

I can use the following code in windows system, but it does not work properly in Linux mint, is there any way to work properly in Linux?

Code: Pascal  [Select]
  1. type
  2.   TForm1 = class(TForm)
  3.     procedure FormKeyPress(Sender: TObject; var Key: char);
  4.   private
  5.     SavedBorderStyle: TBorderStyle;
  6.     SavedLeft, SavedTop, SavedWidth, SavedHeight: Integer;
  7.   public      
  8.     procedure ToggleFullScreen;
  9.   end;
  10.  
  11. procedure TForm1.ToggleFullScreen;
  12. begin
  13.   if BorderStyle <> bsNone then
  14.   begin
  15.     // Save Form Size
  16.     SavedBorderStyle := BorderStyle;
  17.     SavedLeft := Left;
  18.     SavedTop := Top;
  19.     SavedWidth := Width;
  20.     SavedHeight := Height;
  21.     // FullScreen
  22.     BorderStyle := bsNone;
  23.     Left := -1;
  24.     Top := -1;
  25.     Width := Screen.Width + 2;
  26.     Height := Screen.Height + 2;
  27.   end
  28.   else
  29.   begin
  30.     // Restore Form Size
  31.     BorderStyle := SavedBorderStyle;
  32.     Left := SavedLeft;
  33.     Top := SavedTop;
  34.     Width := SavedWidth;
  35.     Height := SavedHeight;
  36.   end;
  37. end;
  38.  
  39. procedure TForm1.FormKeyPress(Sender: TObject; var Key: char);
  40. begin
  41.   ToggleFullScreen;
  42. end;
  43.  

ASerge

  • Sr. Member
  • ****
  • Posts: 472
Re: Some problems about wsFullScreen
« Reply #3 on: October 12, 2017, 04:11:19 pm »
Usually the windows do not open so wide :)
Here is the code shorter and without errors (BorderStyle: TFormBorderStyle but not TBorderStyle)
Code: Pascal  [Select]
  1.   TForm1 = class(TForm)
  2.     procedure FormKeyPress(Sender: TObject; var Key: char);
  3.   private
  4.     FOldBorderStyle: TFormBorderStyle;
  5.     FOldBoundsRect: TRect;
  6.     procedure ToggleFullScreen;
  7.   end;
  8.  
  9. procedure TForm1.ToggleFullScreen;
  10. begin
  11.   if BorderStyle <> bsNone then
  12.   begin
  13.     FOldBoundsRect := BoundsRect;
  14.     FOldBorderStyle := BorderStyle;
  15.     BorderStyle := bsNone;
  16.     BoundsRect := Screen.DesktopRect;
  17.   end
  18.   else
  19.   begin
  20.     BorderStyle := FOldBorderStyle;
  21.     BoundsRect := FOldBoundsRect;
  22.   end;
  23. end;
  24.  
  25. procedure TForm1.FormKeyPress(Sender: TObject; var Key: char);
  26. begin
  27.   ToggleFullScreen;
  28. end;

tomitomy

  • Full Member
  • ***
  • Posts: 201
Re: Some problems about wsFullScreen
« Reply #4 on: October 13, 2017, 07:28:21 am »
Usually the windows do not open so wide :)
Here is the code shorter and without errors (BorderStyle: TFormBorderStyle but not TBorderStyle)

I like your code, your code is clear and rigorous, thank you very much. :)

This code in the Windows can work very well, but the performance of the Linux is very strange, some people know how to achieve full-screen switch in Linux? Thank you in advance!

tomitomy

  • Full Member
  • ***
  • Posts: 201
Re: Some problems about wsFullScreen
« Reply #5 on: October 13, 2017, 08:47:45 am »
I thought of a way to achieve full-screen switch under Windows and Linux, and I can not find a better way. If anyone has a better way, please tell me, thanks in advance!

This's my way:
Code: Pascal  [Select]
  1.   TForm1 = class(TForm)
  2.     Button1: TButton;
  3.     procedure Button1Click(Sender: TObject);
  4.   private
  5.     FOldBorderStyle: TFormBorderStyle;
  6.     FOldBoundsRect: TRect;
  7.   public
  8.   end;
  9.  
  10. procedure TForm1.Button1Click(Sender: TObject);
  11. var
  12.   Form: TForm;
  13. begin
  14.   if BorderStyle = bsNone then begin
  15.     BorderStyle := FOldBorderStyle;
  16.     BoundsRect := FOldBoundsRect;
  17.   end else begin
  18.     FOldBorderStyle := BorderStyle;
  19.     FOldBoundsRect := BoundsRect;
  20.     BorderStyle := bsNone;
  21.     BoundsRect := Screen.DesktopRect;
  22.     // In Linux, need a form to assist
  23.     Form := TForm.Create(nil);
  24.     try
  25.       Parent := Form;
  26.       Parent := nil
  27.     finally
  28.       Form.Free;
  29.     end;
  30.   end;
  31. end;
« Last Edit: October 23, 2017, 03:41:08 am by tomitomy »

 

Recent

Get Lazarus at SourceForge.net. Fast, secure and Free Open Source software downloads Open Hub project report for Lazarus