Subversion Repositories delphiutils

Rev

Rev 12 | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 12 Rev 50
Line 38... Line 38...
38
implementation
38
implementation
39
 
39
 
40
{$R *.dfm}
40
{$R *.dfm}
41
 
41
 
42
uses
42
uses
43
  CommCtrl, FullYearCalendar;
43
  CommCtrl, FullYearCalendar, Functions;
44
 
44
 
45
// Ref: http://www.delphi-fundgrube.de/faq01.htm
45
// Ref: http://www.delphi-fundgrube.de/faq01.htm
46
 
46
 
47
procedure TMainForm.TaskbarEvent(var Msg: TMessage);
47
procedure TMainForm.TaskbarEvent(var Msg: TMessage);
48
var
48
var
Line 113... Line 113...
113
 
113
 
114
  ClientWidth := cal.Width;
114
  ClientWidth := cal.Width;
115
  ClientHeight := cal.Height;
115
  ClientHeight := cal.Height;
116
end;
116
end;
117
 
117
 
118
// Ref: http://www.swissdelphicenter.ch/de/showcode.php?id=261
-
 
119
 
-
 
120
function ForceForegroundWindow(hwnd: THandle): Boolean;
-
 
121
const
-
 
122
  SPI_GETFOREGROUNDLOCKTIMEOUT = $2000;
-
 
123
  SPI_SETFOREGROUNDLOCKTIMEOUT = $2001;
-
 
124
var
-
 
125
  ForegroundThreadID: DWORD;
-
 
126
  ThisThreadID: DWORD;
-
 
127
  timeout: DWORD;
-
 
128
begin
-
 
129
  if IsIconic(hwnd) then ShowWindow(hwnd, SW_RESTORE);
-
 
130
 
-
 
131
  if GetForegroundWindow = hwnd then Result := True
-
 
132
  else
-
 
133
  begin
-
 
134
    // Windows 98/2000 doesn't want to foreground a window when some other
-
 
135
    // window has keyboard focus
-
 
136
 
-
 
137
    if ((Win32Platform = VER_PLATFORM_WIN32_NT) and (Win32MajorVersion > 4)) or
-
 
138
      ((Win32Platform = VER_PLATFORM_WIN32_WINDOWS) and
-
 
139
      ((Win32MajorVersion > 4) or ((Win32MajorVersion = 4) and
-
 
140
      (Win32MinorVersion > 0)))) then
-
 
141
    begin
-
 
142
      // Code from Karl E. Peterson, www.mvps.org/vb/sample.htm
-
 
143
      // Converted to Delphi by Ray Lischner
-
 
144
      // Published in The Delphi Magazine 55, page 16
-
 
145
 
-
 
146
      Result := False;
-
 
147
      ForegroundThreadID := GetWindowThreadProcessID(GetForegroundWindow, nil);
-
 
148
      ThisThreadID := GetWindowThreadPRocessId(hwnd, nil);
-
 
149
      if AttachThreadInput(ThisThreadID, ForegroundThreadID, True) then
-
 
150
      begin
-
 
151
        BringWindowToTop(hwnd); // IE 5.5 related hack
-
 
152
        SetForegroundWindow(hwnd);
-
 
153
        AttachThreadInput(ThisThreadID, ForegroundThreadID, False);
-
 
154
        Result := (GetForegroundWindow = hwnd);
-
 
155
      end;
-
 
156
      if not Result then
-
 
157
      begin
-
 
158
        // Code by Daniel P. Stasinski
-
 
159
        SystemParametersInfo(SPI_GETFOREGROUNDLOCKTIMEOUT, 0, @timeout, 0);
-
 
160
        SystemParametersInfo(SPI_SETFOREGROUNDLOCKTIMEOUT, 0, TObject(0),
-
 
161
          SPIF_SENDCHANGE);
-
 
162
        BringWindowToTop(hwnd); // IE 5.5 related hack
-
 
163
        SetForegroundWindow(hWnd);
-
 
164
        SystemParametersInfo(SPI_SETFOREGROUNDLOCKTIMEOUT, 0, TObject(timeout), SPIF_SENDCHANGE);
-
 
165
      end;
-
 
166
    end
-
 
167
    else
-
 
168
    begin
-
 
169
      BringWindowToTop(hwnd); // IE 5.5 related hack
-
 
170
      SetForegroundWindow(hwnd);
-
 
171
    end;
-
 
172
 
-
 
173
    Result := (GetForegroundWindow = hwnd);
-
 
174
  end;
-
 
175
end;
-
 
176
 
-
 
177
procedure TMainForm.Vordergrund;
118
procedure TMainForm.Vordergrund;
178
begin
119
begin
179
  Show;
120
  Show;
-
 
121
  ShowWindow(Handle, SW_RESTORE);
180
  ForceForegroundWindow(Handle);
122
  ForceForegroundWindow(Handle);
181
end;
123
end;
182
 
124
 
183
procedure TMainForm.FormCloseQuery(Sender: TObject; var CanClose: Boolean);
125
procedure TMainForm.FormCloseQuery(Sender: TObject; var CanClose: Boolean);
184
begin
126
begin