Hello, I've been (slowly) learning Pascal through Lazarus/FreePascal and have started to convert an AutoHotKey script I made to Pascal, However I've ran into an issue with removing the Caption Bar from the top of my windows.
I found code on a post here:
http://forum.lazarus.freepascal.org/index.php/topic,33899.msg220717.html#msg220717However the window shrinks each time I resize it with a key press, I figure its this code here doing it:
Height := Height - GetSystemMetrics(SM_CYCAPTION);
but when I comment that out, the Caption Bar reappears.
So does anyone have any ideas or can help me with this?
(Also its bright green in the project zip just to be 'noticeable', I copied this out of my other code to narrow the issue down to try to fix it and post it here.)
UNIT Unit1;
{$mode objfpc}{$H+}
INTERFACE
USES
Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, Windows;
TYPE
{ TForm1 }
TForm1 = CLASS(TForm)
PROCEDURE FormCreate(Sender: TObject);
PROCEDURE FormKeyDown(Sender: TObject; VAR Key: Word; Shift: TShiftState);
PROCEDURE FormKeyUp(Sender: TObject; VAR Key: Word; Shift: TShiftState);
PRIVATE
{ private declarations }
PUBLIC
{ public declarations }
END;
VAR
Form1: TForm1;
IMPLEMENTATION
{$R *.lfm}
{ TForm1 }
PROCEDURE TForm1.FormCreate(Sender: TObject);
var
Style: Longint;
begin
DoubleBuffered := True;
// HIDE CAPTION BAR
begin
if BorderStyle = bsNone then Exit;
Style := GetWindowLong(Handle, GWL_STYLE);
if (Style and WS_CAPTION) = WS_CAPTION then
begin
case BorderStyle of
bsSingle,
bsSizeable: SetWindowLong(Handle, GWL_STYLE, Style and
(not (WS_CAPTION)) or WS_BORDER);
bsDialog: SetWindowLong(Handle, GWL_STYLE, Style and
(not (WS_CAPTION)) or DS_MODALFRAME or WS_DLGFRAME);
end;
Height := Height - GetSystemMetrics(SM_CYCAPTION);
Refresh;
end;
end;
end;
PROCEDURE TForm1.FormKeyDown(Sender: TObject; VAR Key: Word; Shift: TShiftState);
var
Style: Longint;
begin
if (Shift = [ssCtrl]) then
begin
BorderStyle:=bsSizeable;
if BorderStyle = bsNone then Exit;
Style := GetWindowLong(Handle, GWL_STYLE);
if (Style and WS_CAPTION) = WS_CAPTION then
begin
case BorderStyle of
bsSingle,
bsSizeable: SetWindowLong(Handle, GWL_STYLE, Style and
(not (WS_CAPTION)) or WS_BORDER);
bsDialog: SetWindowLong(Handle, GWL_STYLE, Style and
(not (WS_CAPTION)) or DS_MODALFRAME or WS_DLGFRAME);
end;
Height := Height - GetSystemMetrics(SM_CYCAPTION);
Refresh;
end;
END;
END;
PROCEDURE TForm1.FormKeyUp(Sender: TObject; VAR Key: Word; Shift: TShiftState);
begin
if (Shift <> [ssCtrl]) then
BorderStyle:=bsNone;
end;
END.
Other Issues:
Some help with this 'KeyUp' & 'KeyDown' stuff would be nice also...
The way I have it "works", but if I press ALT or SHIFT it bugs out.
(obviously because the 'if (Shift <> [ssCtrl]) then' bit checking for any key other then CTRL.)
I want the form to be Resizable ONLY when CTRL is held down and then change back to borderless when CTRL is released (I don't want a Caption Bar in either). I've tried adding an 'else BorderStyle:=bsNone;' to the 'if (Shift = [ssCtrl]) then' but I get errors:
'unit1.pas(79,3) Fatal: Syntax error, ";" expected but "ELSE" found'
So either my 'else' isn't in the correct spot, or I'm doing it wrong. Probably the latter.
(I tried it on different lines 77&78, between other 'END;'s but same thing.)
Also if I resize the form while CTRL is down and release the key, the the window size is different from how I just resized it.
(I imagine that this might get fixed or have a different fix, if how I'm hiding the Caption Bar changes. So this is less important right now.)
Note: Because I live way out in the country I only have internet access once a week and thats using an old Linux netbook. So any replys I make will be very slow as I'd have to take code home and try it then wait till next week to get back to post. Sorry in advance. ^-^;
Hopefully this will be fixed in the next month or two, but It's what I have right now. -_-
Thanks for reading and any help offered, even if I am slow to reply. ^-^;