Can forms be manipulated at runtime?

Can forms be manipulated at runtime?

Can forms be manipulated at runtime?

Typically, you want to have your programs visibleand have the ability to switch to them; however, there are times when youhave a background operation that you don’t want anyone messing with onceit has started; or only when you choose to let them mess with it. Theway to accomplish this is with a WinAPI call to ShowWindow.

ShowWindowis a function that allows you change a window’s appearancewith respect to Windows environment. With it, you can maximize, minimize,hide, or show windows to your heart’s content. For a more detailed explanationof the function, check out the Delphi help under WinAPI. Search on ShowWindow,and you’ll be on your way.

The program below is a simple example of how youcan employ ShowWindow. It demonstrates notonly the ShowWindow procedure, but also a methodology for periodicallyquerying a user for a response. You can execute a program like this onthe fly to implement a “Register Now!” screen. Here’s what todo:

  1. Start a new project
  2. Drop two BitButtons on the form.
  3. Set the ‘Kind’ property for BitBtn1 to bkRetry and set its captionto ‘Continue’
  4. Set the ‘Kind’ property for BitBtn1 to bkCancel, leaving its captionalone.
  5. Drop a timer onto the form, and set its ‘Interval’ property to 30000(30 secs).
  6. Copy the code from the listing below into each event listed in thecode.
  7. Run the form. Now every 30 seconds a message will appear on thescreen, asking whether you want to show the form.
  8. Select Cancel to quit the program or select Continue to keep hidingthe form.
{======================================================================= This unit demonstrates how you can hide a window from the task manager and keep the user from being able to Alt-Tab to it. =======================================================================}unit Hidemain;interfaceuses  WinTypes, WinProcs, Messages, Controls, Forms,  Dialogs, StdCtrls, Buttons, Classes, ExtCtrls;type  TForm1 = class(TForm)    BitBtn1: TBitBtn;    BitBtn2: TBitBtn;    Timer1: TTimer;    procedure Timer1Timer(Sender: TObject);    procedure BitBtn1Click(Sender: TObject);    procedure BitBtn2Click(Sender: TObject);    procedure FormClose(Sender: TObject; var Action: TCloseAction);    procedure FormCreate(Sender: TObject);  private    { Private declarations }  public    { Public declarations }  end;var  Form1: TForm1;implementation{$R *.DFM}procedure TForm1.Timer1Timer(Sender: TObject);begin  {First, check the button's label. If it's 'Hide' then   change it to 'Continue'. First value is only for initial   program execution}  if (BitBtn1.Caption = 'Hide') then    begin      BitBtn1.Caption := 'Continue';      BitBtn1.Update;    end;  {If the window's hidden, ask the user if he/she wants to show it. If   so, show it with its default display parameters.}  if NOT IsWindowVisible(Self.Handle) then    if (MessageDlg('Do you want to show the hidden application?',                  mtConfirmation, [mbYes,mbNo], 0) = mrYes) then      ShowWindow(Self.Handle, SW_SHOWNORMAL);end;procedure TForm1.BitBtn1Click(Sender: TObject);begin  ShowWindow(Self.Handle, SW_HIDE);end;procedure TForm1.BitBtn2Click(Sender: TObject);begin  Close;end;procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);begin  Action := caFree;end;procedure TForm1.FormCreate(Sender: TObject);begin  BitBtn1.Caption := 'Hide';  BitBtn1.Update;end;end.

So what gets accomplished here? Once the form is hidden, it ishidden. You won’t be able to Alt-Tab or Ctrl-Esc to the Task Manager. This is one of those point of no return scenarios,but it’s useful. Something like this couldbe used for monitoring certain Windows events or checking the statusof a file independent of another program. Play around withit.

Share the Post:
Heading photo, Metadata.

What is Metadata?

What is metadata? Well, It’s an odd concept to wrap your head around. Metadata is essentially the secondary layer of data that tracks details about the “regular” data. The regular

XDR solutions

The Benefits of Using XDR Solutions

Cybercriminals constantly adapt their strategies, developing newer, more powerful, and intelligent ways to attack your network. Since security professionals must innovate as well, more conventional endpoint detection solutions have evolved

AI is revolutionizing fraud detection

How AI is Revolutionizing Fraud Detection

Artificial intelligence – commonly known as AI – means a form of technology with multiple uses. As a result, it has become extremely valuable to a number of businesses across

AI innovation

Companies Leading AI Innovation in 2023

Artificial intelligence (AI) has been transforming industries and revolutionizing business operations. AI’s potential to enhance efficiency and productivity has become crucial to many businesses. As we move into 2023, several

data fivetran pricing

Fivetran Pricing Explained

One of the biggest trends of the 21st century is the massive surge in analytics. Analytics is the process of utilizing data to drive future decision-making. With so much of