Board index » delphi » Re: Benefits of dual monitor system
Chris Morgan
![]() Delphi Developer |
Re: Benefits of dual monitor system2005-12-02 01:41:57 AM delphi133 QuoteIs it possible to make Delphi to start the application on second monitor. position each time it is run. This is a nice friendly feature for end users as well. If you save into an INI file in Documents and Settings\username\... or into the HKCU section of the registry, then each user keeps his own settings. Example methods below (please excuse the blatant use of 'with' blocks - I'm trying to phase it out honest! // call this method from main form's OnCreate event handler procedure TTrDumpForm.LoadWindowPos; var R: TRect; begin { load last window size/position from USER.INI } try with TIniFile.Create(GetUserIniName) do try with TStringList.Create do try // restore main form size/position CommaText := ReadString(ProgName,USER_POSITION,''); if Count>0 then begin R.Left := StrToInt(Strings[0]); R.Top := StrToInt(Strings[1]); R.Right := StrToInt(Strings[2]); R.Bottom := StrToInt(Strings[3]); BoundsRect := R; end; finally Free; {TStringList} end; finally Free; {TIniFile} end; except { ignore any exceptions } end; end; // call this method from main form's OnDestroy event handler procedure TTrDumpForm.SaveWindowPos; var wp: TWindowPlacement; begin { save window position to USER.INI } wp.length := SizeOf(TWindowPlacement); GetWindowPlacement(Self.Handle,@wp); { if window is maximised or minimised, this gets normal position } try with TIniFile.Create(GetUserIniName) do try with TStringList.Create do try Add(IntToStr(wp.rcNormalPosition.Left)); Add(IntToStr(wp.rcNormalPosition.Top)); Add(IntToStr(wp.rcNormalPosition.Right)); Add(IntToStr(wp.rcNormalPosition.Bottom)); WriteString(ProgName,USER_POSITION,CommaText); finally Free; {TStringList} end; finally Free; {TIniFile} end; except {ignore exceptions} end; end; The implementation of GetUserIniName is left as an exercise! The only potential issue is when using roaming profiles on PCs with different screen sizes. Before setting BoundsRect in LoadwindowPos, you should check that the coords are within the current screen range. Cheers, Chris |