unit main; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, ComCtrls, Menus; type TApp_TOOLWallpaper = class(TForm) PageControl1: TPageControl; TabSheet_WallpaperSet: TTabSheet; TabSheet_WallpaperCreate: TTabSheet; MainMenu_Main: TMainMenu; procedure FormCreate(Sender: TObject); procedure PageControl1Change(Sender: TObject); procedure MenuItem_FileExitClick(Sender: TObject); procedure FormDestroy(Sender: TObject); private { Private 宣言 } function FLoadIni: Boolean; procedure FSaveIni; //システム終了 procedure WMQueryEndSession(var Msg: TWMQueryEndSession); message WM_QUERYENDSESSION; //モニター情報変更 procedure WMDisplayChange(var Msg: TMessage); message WM_DISPLAYCHANGE; public { Public 宣言 } end; var App_TOOLWallpaper: TApp_TOOLWallpaper; const G_ciBGCOLORDESKTOP = 1; implementation uses myApp, myIniFile, myMessageBox, myWindow, setwall, createwall; {$R *.dfm} procedure TApp_TOOLWallpaper.WMDisplayChange(var Msg: TMessage); begin //TScreenのMonitorsプロパティがディスプレイの変更に追随しない不具合の回避のため Self.Monitor; with App_TOOLWallpaperCreate do begin if (gfniMessageBoxYesNo( 'モニター情報が変更されました。壁紙画像をリセットします'#13 + 'よろしいですか'#13#13 + '[はい]  でリセットを行います'#13 + ' 壁紙画像の内容は失われます'#13 + '[いいえ] でリセットを行いません'#13 + ' 引き続き作業を行えますが「モニター情報更新」を行うまで「壁紙に設定」は行えません' ) = ID_YES) then begin //リセットする Action_FileReloadMonitorInfoExecute(nil); Action_FileReloadMonitorInfo.Enabled := False; end else begin //リセットしない Action_FileSetWallpaper.Enabled := False; Action_FileReloadMonitorInfo.Enabled := True; end; end; end; //システム終了 procedure TApp_TOOLWallpaper.WMQueryEndSession(var Msg: TWMQueryEndSession); begin //http://www.wwlnk.com/boheme/delphi/tips/tec0690.htm FormDestroy(Self); Msg.Result := 1; end; procedure TApp_TOOLWallpaper.FormCreate(Sender: TObject); begin PageControl1.Align := alClient; Self.DoubleBuffered := True; PageControl1.DoubleBuffered := True; App_TOOLWallpaperSet := TApp_TOOLWallpaperSet.Create(Self); App_TOOLWallpaperSet.ManualDock(TabSheet_WallpaperSet); App_TOOLWallpaperSet.Align := alClient; App_TOOLWallpaperSet.Show; App_TOOLWallpaperCreate := TApp_TOOLWallpaperCreate.Create(Self); App_TOOLWallpaperCreate.ManualDock(TabSheet_WallpaperCreate); App_TOOLWallpaperCreate.Align := alClient; App_TOOLWallpaperCreate.Show; PageControl1Change(nil); FLoadIni; Show; gpcFormBringToFront(Self); end; procedure TApp_TOOLWallpaper.FormDestroy(Sender: TObject); begin FSaveIni; with App_TOOLWallpaperSet do begin Align := alNone; Hide; ManualFloat(Rect(Left, Top, Width, Height)); end; if (App_TOOLWallpaperCreate <> nil) then begin with App_TOOLWallpaperCreate do begin Align := alNone; Hide; ManualFloat(Rect(Left, Top, Width, Height)); end; end; end; procedure TApp_TOOLWallpaper.PageControl1Change(Sender: TObject); begin if (PageControl1.ActivePage = TabSheet_WallpaperSet) then begin MainMenu_Main.Merge(App_TOOLWallpaperSet.MainMenu_Main); if (App_TOOLWallpaperCreate <> nil) then begin MainMenu_Main.Unmerge(App_TOOLWallpaperCreate.MainMenu_Main); end; end else if (PageControl1.ActivePage = TabSheet_WallpaperCreate) then begin if (App_TOOLWallpaperCreate = nil) then begin App_TOOLWallpaperCreate := TApp_TOOLWallpaperCreate.Create(Self); App_TOOLWallpaperCreate.ManualDock(TabSheet_WallpaperCreate); App_TOOLWallpaperCreate.Align := alClient; App_TOOLWallpaperCreate.Show; end; MainMenu_Main.Merge (App_TOOLWallpaperCreate.MainMenu_Main); MainMenu_Main.Unmerge(App_TOOLWallpaperSet.MainMenu_Main); end; end; procedure TApp_TOOLWallpaper.MenuItem_FileExitClick(Sender: TObject); begin end; //------------------------------------------------------------------------------ //IniFile const lcsSECT_BOUNDS = 'WALLPAPERSET_Bounds'; function TApp_TOOLWallpaper.FLoadIni: Boolean; var l_IniFile : TMyIniFile; begin Result := False; //Shift+Ctrl起動で設定を読み込まない。 if (gfnbKeyStateAnd([VK_SHIFT, VK_CONTROL])) then begin Exit; end; l_IniFile := TMyIniFile.Create; try with l_IniFile do begin SetMonitorBoundsRect(lcsSECT_BOUNDS, Self); App_TOOLWallpaperSet.LoadIni(l_IniFile); if (App_TOOLWallpaperCreate <> nil) then begin App_TOOLWallpaperCreate.LoadIni(l_Inifile); end; end; finally l_IniFile.Free; end; Result := True; end; //設定保存 procedure TApp_TOOLWallpaper.FSaveIni; var l_IniFile : TMyIniFile; begin //Shift+Ctrl起動で設定を書き込まない。 if (gfnbKeyStateAnd([VK_SHIFT, VK_CONTROL])) then begin Exit; end; l_IniFile := TMyIniFile.Create; try with l_IniFile do begin WriteBoundsRect(lcsSECT_BOUNDS, Self); App_TOOLWallpaperSet.SaveIni(l_IniFile); if (App_TOOLWallpaperCreate <> nil) then begin App_TOOLWallpaperCreate.SaveIni(l_Inifile); end; end; finally l_IniFile.Free; end; end; end.