Hide Dialog to Notification Area on Minimize

Example scripts and tips (replaces Old Scripts & Tips archive)

Moderators: Dorian (MJT support), JRL, Phil Pendlebury

Post Reply
User avatar
Rain
Automation Wizard
Posts: 550
Joined: Tue Aug 09, 2005 5:02 pm
Contact:

Hide Dialog to Notification Area on Minimize

Post by Rain » Tue Jul 30, 2013 2:51 pm

Simple example that makes it appear like a dialog is hidden to the notification area when the minimize button is clicked.

Maybe someone will find this useful.

Code: Select all

Dialog>Dialog1
object Dialog1: TForm
  Left = 430
  Top = 178
  HelpContext = 5000
  BorderIcons = [biSystemMenu]
  Caption = 'Minimize to tray example'
  ClientHeight = 94
  ClientWidth = 279
  Color = clBtnFace
  DefaultMonitor = dmPrimary
  Font.Charset = DEFAULT_CHARSET
  Font.Color = clWindowText
  Font.Height = -11
  Font.Name = 'MS Sans Serif'
  Font.Style = []
  OldCreateOrder = True
  Position = poScreenCenter
  ShowHint = True
  OnTaskBar = True
  PixelsPerInch = 96
  TextHeight = 13
  object Label1: TLabel
    Left = 8
    Top = 16
    Width = 265
    Height = 65
    AutoSize = False
    Caption = 
      '1. Click the minimize button to hide the dialog to the notificat' +
      'ion area.'#13#10#13#10'2. Click the tray icon to show the dialog.'
    WordWrap = True
  end
end
EndDialog>Dialog1

AddDialogHandler>Dialog1,,OnClose,ExitScript
SetDialogProperty>Dialog1,,BorderIcons,[biSystemMenu, biMinimize, biMaximize]
Show>Dialog1

//Directory to icon file
//Leave empty to use Macro Schedulers icon
Let>IconFile=

Let>FirstRun=True

Label>Loop

  GetDialogProperty>Dialog1,,WindowState,WindowStateRes
  IF>WindowStateRes=wsMinimized
    IF>FirstRun=True
      //Create Tray icon if dialog was minimized for the first time
      Let>FirstRun=False
      AddTrayIcon>%IconFile%,MyTrayIcon,Show Dialog
      AddTrayHandler>MyTrayIcon,OnMouseDown,ShowDialog
    ENDIF
    //Hide the dialog
    SetDialogProperty>Dialog1,,Visible,False
    SetDialogProperty>Dialog1,,WindowState,wsNormal
    //Show Tray Icon
    ModTrayIcon>MyTrayIcon,,,True
  ENDIF

 Wait>0.1
Goto>Loop

SRT>ShowDialog
  //Hide Tray Ico
  ModTrayIcon>MyTrayIcon,,,False
  //Make Dialog visible
  SetDialogProperty>Dialog1,,Visible,True
  Show>Dialog1
END>ShowDialog

SRT>ExitScript
  Exit>1
END>ExitScript

Post Reply
cron
Sign up to our newsletter for free automation tips, tricks & discounts