--> Refresh Desktop with Delphi | Delphi Tips Trick

For Newbie

Tuesday, 15 November 2011

Refresh Desktop with Delphi

| Tuesday, 15 November 2011


Tricks refresh Windows desktop.

Declaration procedure:
RefreshDesktop procedure;
var
   desktopHwnd: hWnd;
   s: String;
begin
  / / Handle Desktop
  desktopHwnd: = FindWindow ('ProgMan', nil);
  desktopHwnd: = GetWindow (desktopHwnd, GW_CHILD);
  desktopHwnd: = GetWindow (desktopHwnd, GW_CHILD);
  SetLength (s, 40);
  GetClassName (desktopHwnd, PChar (S), 39);
  if PChar (S) <> 'SysListView32' then desktopHwnd: = 0;
  / / Refresh
  PostMessage (desktopHwnd, WM_KEYDOWN, VK_F5, 0);
  PostMessage (desktopHwnd, WM_KEYUP, VK_F5, 1 SHL 31);
  SendMessage (desktopHwnd, WM_COMMAND, $ A065, 0);
  InvalidateRect (desktopHwnd, nil, True);
end;

Example of implementation:
procedure TForm1.Button1Click (Sender: TObject);
begin
   RefreshDesktop;
end;

Related Posts

No comments: