Problem to change form style with SetWindowLong for hiding the window caption. lazarus / 31-LCL ---------------------------------------------------------------------- Don Antonio · 2011-09-06 19:07 Hi, I'm trying to hide the caption of default optioned form using the following code, which works properly on Delphi: SetWindowLong(Handle, GWL_STYLE, GetWindowLong(Handle, GWL_STYLE) and not WS_CAPTION); The issue is: 1. After showing the form contains a caption like it would be a child(WS_CHILD). 2. At the bottom of the form appears empty space. 3. Everytime when window shows after hiding its height increases by the caption height. The issue on the screenshot bellow: http://visualbooster.com/share/20110906202532551.png [^] When I attempt to resize the form it becomes normal as it should be. See the following screenshot: http://visualbooster.com/share/20110906203014778.png [^] Is this a known issue? Please advice. P.S. 1. PageControl has a client alignment. 2. ClientHeight := Height; - doesn't work. 3. Height := Height - GetSystemMetrics(SM_CYCAPTION); - works once as it only in a form constructor. When form shows its size grows so this is not correct solution. ---------------------------------------------------------------------- felipemdc · 2011-09-07 07:44 Quote from: Don Antonio on September 06, 2011, 09:07:20 pmIs this a known issue? Please advice. It's not really an issue. Nowhere is it stated that non-portable calls are guaranteed to work like they do in Delphi. Lazarus is optimized for cross-platform code, and this feature doesn't look like something which can be implemented in Linux and Mac OS X. ---------------------------------------------------------------------- Shebuka · 2011-09-07 08:51 Try use YourForm.BorderStyle := bsNone ---------------------------------------------------------------------- Bart · 2011-09-07 10:54 Yes, that'll do just fine, tested both on Win9x and Win7. That is, it removes the caption. I just re-tested in Delphi. The call to SetWindowLong only removes the caption when WindowState = wsMaximized; Bart ---------------------------------------------------------------------- Don Antonio · 2011-09-08 05:12 Quote from: felipemdc on September 07, 2011, 09:44:05 amLazarus is optimized for cross-platform code, and this feature doesn't look like something which can be implemented in Linux and Mac OS X. Yes, you are right. However a lot of programs nowadays on Windows use the ability to set window style as needed (e.g. excluding caption, making a custom frame, adding custom buttons into caption or other non-client area). So, I think Lazarus should support this depending on platform it builds an app. ---------------------------------------------------------------------- Don Antonio · 2011-09-08 05:34 Quote from: Shebuka on September 07, 2011, 10:51:28 amTry use YourForm.BorderStyle := bsNone That method actually removes a frame of specified form. I need to remove only caption. And I did that before on Lazarus 0.9.28. I made a custom frame and It was quite enough for me except when you try to move the form it leaves same marks on the desktop. However it worked with 0.9.28. With 0.9.30 it doesn't work anymore. That is why I tried to remove only caption and leave default frame. P.S. If I use "YourForm.BorderStyle := bsNone" I can't add frame without caption like that:   SetWindowLong(Handle, GWL_STYLE, GetWindowLong(Handle, GWL_STYLE) and (not WS_CAPTION) or WS_THICKFRAME) ---------------------------------------------------------------------- felipemdc · 2011-09-08 06:19 Quote from: Don Antonio on September 08, 2011, 07:12:56 amYes, you are right. However a lot of programs nowadays on Windows use the ability to set window style as needed (e.g. excluding caption, making a custom frame, adding custom buttons into caption or other non-client area). So, I think Lazarus should support this depending on platform it builds an app. You can always implement this the correct way: Add a new BorderStyle, named bsSizableWithoutTitle and then implement it in LCL-Win32. Create a patch for it. But I'm not sure if it should be added to Lazarus, because: 1> This feature looks useless for me. What is the real use case here? 2> It is not portable But at the very least it would work for you and others with a patch, and then we can discuss if it is worth adding to the LCL. ---------------------------------------------------------------------- Avishai · 2011-09-08 06:32 I just tried your code and added Form1.Width:=Form1.Width+1; after yor code and I think it did what you are looking for.  There may be better way. ---------------------------------------------------------------------- Don Antonio · 2011-09-08 09:58 Quote from: felipemdc on September 08, 2011, 08:19:41 am1> This feature looks useless for me. What is the real use case here? Only one use case: to hide unnecessary window caption and increase client area. Problem with caption has resolved: 1. SetWindowLong(Handle, GWL_STYLE, GetWindowLong(Handle, GWL_STYLE) and (not WS_CAPTION) or WS_THICKFRAME); 2. BorderStyle := bsNone; Now I have another problem. Everytime when form shows some part of client area with controls appears under frame. See the following screenshot: http://visualbooster.com/share/20110908154044365.png If resize window using mouse it becomes normal: http://visualbooster.com/share/20110908155345512.png If window hides and shows again the issue repeats. Form1.Width := Form1.Width + 1; doesn't take any effects. Please advice how to resolve it. ---------------------------------------------------------------------- LA.Center · 2011-09-08 23:01 Leave the borderstyle single or sizeable and as Avishai already suggested: and add on the show event of the form Code: [Select]Width := Width +1; Width := Width -1; This has worked for me. ---------------------------------------------------------------------- Shebuka · 2011-09-09 08:22 Quote from: plusplus on September 09, 2011, 01:01:52 amLeave the borderstyle single or sizeable and as Avishai already suggested: and add on the show event of the form Code: [Select]Width := Width +1; Width := Width -1; This has worked for me. To all who are in the tank (armored one), you can also do Code: [Select]Width += 1; Width -= 1; ---------------------------------------------------------------------- LA.Center · 2011-09-09 09:43 yeah I am a bit old-school, need to adjust, thx ---------------------------------------------------------------------- Don Antonio · 2011-09-09 13:12 Thanks to everyone who posted here. Quote from: plusplus on September 09, 2011, 01:01:52 amLeave the borderstyle single or sizeable and as Avishai already suggested: and add on the show event of the form Code: [Select]Width := Width +1; Width := Width -1; This has worked for me. This workaround works in Delphi, but doesn't in Lazarus 0.9.30. Perhaps you use the version from svn and it has different behavior. Anyway I have attached two examples below. 1. The form in examples has default properties. 2. OnCreate callback procedure contains the following code: Code: [Select]procedure TForm1.FormCreate(Sender: TObject); begin   SetWindowLong(Handle,GWL_STYLE,     GetWindowLong(Handle,GWL_STYLE) and (not WS_CAPTION) or WS_THICKFRAME);   Width := Width + 1;   Width := Width - 1; end; Delphi code: http://zentimo.com/exe/TestFrame_Delphi.zip Screenshot: http://visualbooster.com/share/20110909181239387.png The form looks properly. Lazarus code: http://zentimo.com/exe/TestFrame_Lasarus.zip Screenshot: http://visualbooster.com/share/20110909181448015.png Differs from Delphi result. I don't really understand what happen with client area. If I set BorderStyle = bsNone in Delphi I get perfect form as I need and I even don't need to do Width := Width + 1. If I do the same in Lazarus I get another issue. Right and bottom part of client area becomes invisible. See the screenshot: http://visualbooster.com/share/20110909181744458.png - that is strange issue I couldn't resolve. And the workaround Width := Width + 1 doesn't help in this case. The form becomes normal if I resize it manually (using mouse).   Any ideas? ---------------------------------------------------------------------- otorres · 2011-09-09 15:17 Code: [Select]procedure TForm1.FormActivate(Sender: TObject); begin SetWindowLong(Handle, GWL_STYLE, GetWindowLong(Handle, GWL_STYLE) and (not WS_CAPTION) or WS_THICKFRAME); BorderStyle:=bsNone; end; ---------------------------------------------------------------------- Don Antonio · 2011-09-09 15:39 Thanks otorres, but your method kills the frame around window. I need a window with the frame and without the caption. ---------------------------------------------------------------------- otorres · 2011-09-09 15:52 Sorry, my error, the fix is Code: [Select]procedure TForm1.FormActivate(Sender: TObject); begin BorderStyle:=bsNone; SetWindowLong(Handle, GWL_STYLE, GetWindowLong(Handle, GWL_STYLE) and (not WS_CAPTION) or WS_THICKFRAME); end; ---------------------------------------------------------------------- Avishai · 2011-09-09 15:56 otorres, I just tried your fix and it seems to do what I think Don Antonio is wanting   Nice work.  The Form does get a bit smaller but nothing that can not be fixed. ---------------------------------------------------------------------- Avishai · 2011-09-09 16:26 I just posted another "SetWindowLong" question that maybe you Gurus can help me with.  It is for RightToLeft Form for RightToLeft Languages like Hebrew, Arabic and others. ---------------------------------------------------------------------- Don Antonio · 2011-09-09 17:50 Quote from: otorres on September 09, 2011, 05:52:20 pmSorry, my error, the fix is Code: [Select]procedure TForm1.FormActivate(Sender: TObject); begin BorderStyle:=bsNone; SetWindowLong(Handle, GWL_STYLE, GetWindowLong(Handle, GWL_STYLE) and (not WS_CAPTION) or WS_THICKFRAME); end; Quote from: Avishai on September 09, 2011, 05:56:36 pmotorres, I just tried your fix and it seems to do what I think Don Antonio is wanting Nice work.  The Form does get a bit smaller but nothing that can not be fixed. Guys, as I mentioned before that is really good way to do what I want. But what about this: http://visualbooster.com/share/20110909233731958.png ---------------------------------------------------------------------- otorres · 2011-09-09 19:11 send you project zipped to see it better. ---------------------------------------------------------------------- Avishai · 2011-09-09 19:13 Which version of Lazarus/FPC are you using?  I can't reproduce what you show. ---------------------------------------------------------------------- Don Antonio · 2011-09-09 19:28 Quote from: Avishai on September 09, 2011, 09:13:11 pmWhich version of Lazarus/FPC are you using?  I use Lazarus 0.9.30/FPC 2.4.2. I download it here: http://sourceforge.net/projects/lazarus/files/ QuoteI can't reproduce what you show.Interesting. I will try latest svn version. Perhaps it will help. Thanks anyway. ---------------------------------------------------------------------- Don Antonio · 2011-09-09 19:30 Quote from: otorres on September 09, 2011, 09:11:12 pmsend you project zipped to see it better. I attached zipped archive to one of my previous posts. ---------------------------------------------------------------------- otorres · 2011-09-09 20:53 For me is working so nice =) only with this code Code: [Select]procedure TForm1.Button1Click(Sender: TObject); begin   Close; end; procedure TForm1.FormActivate(Sender: TObject); begin   BorderStyle:=bsNone;   SetWindowLong(Handle, GWL_STYLE, GetWindowLong(Handle, GWL_STYLE) and (not WS_CAPTION) or WS_THICKFRAME); end;