旧的Delphi隐藏/显示桌面图标方法在Windows 7 64位下不工作 [英] Old Delphi hide/show desktop icons method not working under Windows 7 64 Bit

查看:242
本文介绍了旧的Delphi隐藏/显示桌面图标方法在Windows 7 64位下不工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个Delphi 2010应用程序,显示/隐藏XP下的桌面图标。然而,在我的Window 7测试环境(恰好是64位)下,图标不会消失。



这是我正在使用的关键代码(对于隐藏):

  ShowWindow(FindWindow(nil,'Program Manager'),SW_HIDE); 

我发现我可以设置注册表:

  [HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced] 
HideIcons= dword:00000001

如果我重新启动Windows(或杀死资源管理器并重新启动它),则可以正常工作,但是有没有办法获取旧代码工作和/或告诉桌面重新加载使用新的注册表信息没有这种激进的方法。



提前感谢。

解决方案

好的,这里是修改的 hackish方法(对不起,Alexander!):

  var 
DeskHandle:HWND;

...

//////////////////////////// //////////////////////
// EnumWindows的回调函数
////////////////////////////////////////// //////////////////////
函数MyGetWindow(Handle:HWND; NotUsed:longint):bool;标准
var
hChild:HWND;
begin
如果handle<> 0 then
begin
hChild:= FindWindowEx(handle,0,'SHELLDLL_DefView',nil);
如果hChild<> 0 then
begin
hChild:= FindWindowEx(hChild,0,'SysListView32',nil);
如果hChild<> 0然后
begin
DeskHandle:= hChild;
结束
结束
结束
result:= TRUE;
结束

procedure ShowDesktopIcons(const Show:boolean);
begin
DeskHandle:= 0;
EnumWindows(@MyGetWindow,0);

如果DeskHandle<> 0 then
begin
if Show then
begin
ShowWindow(DeskHandle,SW_SHOW);
end
else
begin
ShowWindow(DeskHandle,SW_HIDE);
结束
结束
结束

出现此问题是因为Progman和SysListView32之间的父/子关系已从XP更改为Vista / Win7(正是为什么你不应该使用hack ;-)。另外,在Win7(我的测试环境)下应用多个图片的主题会进一步改变这种关系。因此,新的例程将遍历所有窗口,直到找到一个SHELLDLL_DefView和SysListView32子项设置为一个。然后在全局变量DeskHandle中返回SysListView32的句柄。不优雅,不确定在未来的代码中工作,但今天工作。



如果任何人可以获得SHGetSetSettings版本的工作,这绝对是正确的方法,而不是这个垃圾。


I have a Delphi 2010 app which shows/hides the desktop icons under XP fine. However under my Window 7 test environment (happens to be 64 bit) the icons don't disappear.

Here is the critical code I am using (for the hide):

ShowWindow(FindWindow(nil, 'Program Manager'), SW_HIDE );

I have found I can set the registry:

[HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced]
"HideIcons"=dword:00000001

And that works fine if I restart windows (or kill explorer and restart it), however is there a way to get the old code to work and/or tell the desktop to reload using the new registry information without such radical methods.

Thank in advance.

解决方案

Ok, here is the revised hackish method (sorry Alexander!):

var
DeskHandle : HWND;

...

///////////////////////////////////////////////////////////////////////
// Callback function for EnumWindows
///////////////////////////////////////////////////////////////////////
function MyGetWindow (Handle: HWND; NotUsed: longint): bool; stdcall;
var
  hChild : HWND;
begin
  if handle <> 0 then
  begin
    hChild := FindWindowEx(handle, 0, 'SHELLDLL_DefView' ,nil);
    if hChild <> 0 then
    begin
      hChild := FindWindowEx(hChild, 0, 'SysListView32' ,nil);
      if hChild <> 0 then
      begin
        DeskHandle := hChild;
      end;
    end;
  end;
  result := TRUE;
end;

procedure ShowDesktopIcons(const Show : boolean) ;
begin
  DeskHandle := 0;
  EnumWindows(@MyGetWindow, 0);

  if DeskHandle <> 0 then
  begin
    if Show then
    begin
      ShowWindow(DeskHandle, SW_SHOW );
    end
    else
    begin
      ShowWindow(DeskHandle, SW_HIDE );
    end;
  end;
end;

The issue arises because parent/child relationship between "Progman" and SysListView32 has changed from XP to Vista/Win7 (precisely why you shouldn't use a hack ;-). In addition, applying a theme with multiple pictures under Win7 (my test environment) changes this relationship even further. Therefore the new routine looks through all windows until it finds one with a "SHELLDLL_DefView" and "SysListView32" child set under one. It then returns the handle of SysListView32 in the global variable DeskHandle. Not elegant, not sure to work in future code, but works today.

If anyone can get a SHGetSetSettings version to work, that is definitely the correct way to go, not this junk.

这篇关于旧的Delphi隐藏/显示桌面图标方法在Windows 7 64位下不工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆