For Newbie

Tuesday, 15 November 2011

Refresh Desktop with Delphi



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;

Share on Facebook
Share on Twitter
Share on Google+

Related : Refresh Desktop with Delphi