Newsgroups : Borland : borland.public.delphi.nativeapi.win32 : 2005 Mar : Re: Can I send a windows message equivalent to the F5 key to the entire desktop?
| Subject: | Re: Can I send a windows message equivalent to the F5 key to the entire desktop? |
| Posted by: | "Ronaldo Souza" (nospam@nospam.org) |
| Date: | Sat, 19 Mar 2005 00:56:15 |
Ace wrote:
> I have written a program that enables/disables certain devices. It works
> fine. But half the time if there is an open Windows Explorer window, I need
> to press F5 so that the device shows up (or removes itself) from below My
> Computer.
Try this:
============================================================================
unit Unit1;
interface
uses
Windows, Classes, Controls, StdCtrls, Forms, Messages, Dialogs;
type
TForm1 = class(TForm)
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.DFM}
var //Global vars
G_Found : boolean = false;
G_HWnd : HWND = 0;
function FindExplorerSysTreeView(Wnd : HWND; Param : Integer) : BOOL;
stdcall;
var
ClassName : array[0..255] of char;
begin
GetClassName(Wnd,ClassName,256);
G_Found := (ClassName = 'SysTreeView32') and IsWindow(Wnd);
Result := not G_Found;
if G_Found
then G_HWnd := Wnd;
end;
function FindExplorerUsingItsCaption(Wnd : HWND; Param : integer) :
BOOL; stdcall;
const
ExplorerCaption = 'Explorando - '; //<<< USE YOUR EXPLORER'S CAPTION
var
Caption : array[0..255] of char;
begin
SendMessage(Wnd,WM_GETTEXT,256,Integer(@Caption));
G_Found := (Pos(ExplorerCaption,Caption) > 0) and IsWindow(Wnd);
if G_Found
then G_HWnd := Wnd;
Result := not G_Found;
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
EnumWindows(@FindExplorerUsingItsCaption,0);
if G_Found
then begin
EnumChildWindows(G_HWnd,@FindExplorerSysTreeView,0);
if G_Found
then SendMessage(G_HWnd,WM_WININICHANGE,0,0);
end
else ShowMessage('Couldn't find Explorer!');
end;
end.
============================================================================
Hope it helps,
Ronaldo