troubleshooting Question

Lost in the If..Then..Else statements.

Avatar of Peter Kiers
Peter KiersFlag for Netherlands asked on
Delphi
17 Comments1 Solution300 ViewsLast Modified:
Dear Experts,

I have kind of lost the way with the If..Then..Else-statements.

I have an application that contains 3 components:

a ToolBar (named: ToolBar).
a StatusBar (named: Hostbar, this bar has a TPanel as parent)
a StatusBar (named: MainBar)

Those components can be hidden or make visible with the MainMenu-items

This works perfect...

Now, i have made a fourth MainMenu-item named Full Screen
for switching between a 'Nomal screen' and a 'Full Screen'.

Even this procedure works perfect...

When a user switch between a normal screen to a fullscreen the coordinates
of the normal form must be saved and if the Toolbar, Hostbar and mainbar
where turn off or on. For Example if the Toolbar was turn off during the normal
screen and the user switch to fullscreen and back again to the normal screen the
Toolbar still has to be turned off.

Even this works perfect...

The problem is when the user uses de PopupMenu-items: Toolbar2 and Status-
bar2 in the fullscreen-mode.

For Example: if the user turns nothing off in the normal screen and goes to
the fullscreen-mode, and turns in fullscreen-mode the ToolBar off. When the
user gets back to the normal screen, the toolbar is still hidden and it should be
visible !!!

Anyway the problem lies in the procedures Toolbar1Click and the Statusbar1Click
that are hooked up with the PopupMenu-items : Toolbar2 en Statusbar2

Who can help me to solve this problem?

Thanx in Advanced.

Kind Regards,
Peter Kiers

The code:

type
  TForm1 = class(TForm)
    ToolBar: TToolBar;
    Space: TToolButton;
    ToolButton1: TToolButton;
    MainBar: TStatusBar;
    ScrollBox1: TScrollBox;
    ScrImage1: TImage;
    Panel1: TPanel;
    Hostbar: TStatusBar;
    MainMenu1: TMainMenu;
    View1: TMenuItem;
    Toolbar1: TMenuItem;
    Statusbar1: TMenuItem;
    HostStatusbar1: TMenuItem;
    N4: TMenuItem;
    FullScreen1: TMenuItem;
    PopupMenu1: TPopupMenu;
    Toolbar2: TMenuItem;
    Statusbar2: TMenuItem;
    N7: TMenuItem;
    FullScreen2: TMenuItem;
    procedure FormCreate(Sender: TObject);
    procedure Toolbar1Click(Sender: TObject);
    procedure Statusbar1Click(Sender: TObject);
    procedure HostStatusbar1Click(Sender: TObject);
    procedure FullScreen1Click(Sender: TObject);
  private
    { Private declarations }
    FWindowPlacement: TWindowPlacement;
    FOldStyle: Integer;
  public
    { Public declarations }
  end;

var
  Form1: TForm1;
  Tog: Boolean;
  Tob: Boolean;
  Hob: Boolean;
  Stb: Boolean;

implementation

{$R *.DFM}

procedure TForm1.FormCreate(Sender: TObject);
begin
  ScrollBox1.DoubleBuffered := True;
  ScrollBox1.Color := clBlack;
  Tog := False;
  Tob := True;
  Hob := True;
  Stb := True;
end;

procedure TForm1.Toolbar1Click(Sender: TObject);
begin
  ScrollBox1.Perform(WM_SETREDRAW, 0, 0);
  try
    if ToolBar1.Checked then
    begin
      Tob := False;
      ToolBar.Hide;
      ToolBar1.Checked := False;
      ToolBar2.Checked := False;
      if FullScreen2.Checked then
      begin
        ToolBar.Show;
        Toolbar.Height := 3;
        ToolBar2.Checked := False;
      end;
    end
    else
    begin
      Tob := True;
      ToolBar.Show;
      Toolbar.Height := 29;
      ToolBar1.Checked := True;
      ToolBar2.Checked := True;
      if FullScreen2.Checked then
      begin
        ToolBar.Show;
        Toolbar.Height := 29;
        ToolBar2.Checked := True;
      end;
    end;
  finally
    ScrollBox1.Perform(WM_SETREDRAW, 1, 0);
    ScrollBox1.Invalidate;
  end;
end;


procedure TForm1.Statusbar1Click(Sender: TObject);
begin
  if StatusBar1.Checked then
  begin
    Stb := False;
    MainBar.Hide;
    StatusBar1.Checked := False;
    StatusBar2.Checked := False;
    if FullScreen2.Checked then
      Stb := True;
  end
  else begin
    Stb := True;
    MainBar.Show;
    StatusBar1.Checked := True;
    StatusBar2.Checked := True;
    if FullScreen2.Checked then
      Stb := False;
  end;
end;

procedure TForm1.HostStatusbar1Click(Sender: TObject);
begin
  if HostStatusBar1.Checked then
  begin
    Hob := False;
    Panel1.Hide;
    HostBar.Hide;
    HostStatusBar1.Checked := False;
  end
  else begin
    Hob := True;
    Panel1.Show;
    HostBar.Show;
    HostStatusBar1.Checked := True;
  end;
end;

procedure TForm1.FullScreen1Click(Sender: TObject);
var dwStyle: Integer;
begin
  dwStyle := GetWindowLong(Handle, GWL_STYLE);
  DisableAlign;
  try
    if ((dwStyle and WS_CAPTION) = 0) then
    begin
      SetWindowPos(Handle, HWND_NOTOPMOST, 0, 0, 0, 0, SWP_NOMOVE or SWP_NOSIZE or SWP_NOZORDER);
      SetWindowLong(Handle, GWL_STYLE, FOldStyle);
      Menu := MainMenu1;
      SetWindowPlacement(Handle, @FWindowPlacement);
      if Stb then
      begin
        MainBar.Show;
        StatusBar1.Checked := True;
        StatusBar2.Checked := True;
      end
      else
      begin
        MainBar.Hide;
        StatusBar1.Checked := False;
        StatusBar2.Checked := False;
      end;
      if Tob then
      begin
        ToolBar.Show;
        ToolBar1.Checked := True;
        ToolBar2.Checked := True;
      end
      else
      begin
        ToolBar.Hide;
        ToolBar1.Checked := False;
        ToolBar2.Checked := False;
      end;
      if Hob then
      begin
        Panel1.Show;
        HostBar.Show;
        HostStatusBar1.Checked := True;
      end
      else
      begin
        Panel1.Hide;
        HostBar.Hide;
        HostStatusBar1.Checked := False;
      end;
      FullScreen1.Checked := False;
      FullScreen2.Checked := False;
    end
    else
    begin
      FOldStyle := dwStyle;
      GetWindowPlacement(Handle, @FWindowPlacement);
      SetWindowLong(Handle, GWL_STYLE, Integer(WS_POPUP or WS_VISIBLE));
      SetWindowPos(Handle, HWND_TOPMOST, 0, 0, Screen.Width, Screen.Height, SWP_DRAWFRAME);
      Menu := nil;
      Mainbar.Hide;
      StatusBar1.Checked := False;
      StatusBar2.Checked := False;
      FullScreen1.Checked := True;
      FullScreen2.Checked := True;
      ToolBar.Show;
      ToolBar1.Checked := True;
      ToolBar2.Checked := True;
      Panel1.Show;
      HostBar.Show;
      HostStatusBar1.Checked := True;
    end;
  finally
    EnableAlign;
  end;
end;



ASKER CERTIFIED SOLUTION
Join our community to see this answer!
Unlock 1 Answer and 17 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 17 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros