请问如何将桌面上的所有窗口都最小化?谢谢(20分)

  • 主题发起人 主题发起人 zyl000
  • 开始时间 开始时间
Z

zyl000

Unregistered / Unconfirmed
GUEST, unregistred user!
 谢谢!
 
列举窗口,然后发出消息
 
因该可以用shell的一条指令来实现,不过不知道是什么指令,接口
 
to xjxxln: 为什么不用HWND_BROADCAST?何必列举窗口?<br>
 
WIN+M键<br>
 
//这些代码由PENGS书写在Delphi 5+Win2K 上成功!从我的一个程序中Copy来的<br>// 在程序中调用 HideDesktopAllWin 就可以啦<br>//如有不对仔细检查一下代码,修改部分就可以啦<br>//如果运行可以,[^]给点分吧<br><br><br>{-------------------------------------------------------------------------------}<br>{ ShowWinNoAnimate }<br><br>function GetAnimation: Boolean;<br>var<br>&nbsp; Info: TAnimationInfo;<br>begin<br>&nbsp; Info.cbSize := SizeOf(TAnimationInfo);<br>&nbsp; if SystemParametersInfo(SPI_GETANIMATION, SizeOf(Info), @Info, 0) then<br>&nbsp; &nbsp; Result := Info.iMinAnimate &lt;&gt; 0 else<br>&nbsp; &nbsp; Result := False;<br>end;<br><br>procedure SetAnimation(Value: Boolean);<br>var<br>&nbsp; Info: TAnimationInfo;<br>begin<br>&nbsp; Info.cbSize := SizeOf(TAnimationInfo);<br>&nbsp; BOOL(Info.iMinAnimate) := Value;<br>&nbsp; SystemParametersInfo(SPI_SETANIMATION, SizeOf(Info), @Info, 0);<br>end;<br><br>procedure ShowWinNoAnimate(Handle: HWnd; CmdShow: Integer);<br>var<br>&nbsp; Animation: Boolean;<br>begin<br>&nbsp; Animation := GetAnimation;<br>&nbsp; if Animation then SetAnimation(False);<br>&nbsp; ShowWindow(Handle, CmdShow);<br>&nbsp; if Animation then SetAnimation(True);<br>end;<br>procedure HideDesktopAllWin(Sender: TObject);<br>&nbsp; function EnumWindowsProc (Wnd: HWND; LParam: LPARAM): BOOL; stdcall;<br>&nbsp; begin<br>&nbsp; &nbsp; Result := True;<br>&nbsp; &nbsp; if (IsWindowVisible(Wnd)) and<br>&nbsp; &nbsp; &nbsp; &nbsp;(GetWindowLong(Wnd, GWL_HWNDPARENT) = 0) and<br>&nbsp; &nbsp; &nbsp; &nbsp;(GetWindowLong(Wnd, GWL_EXSTYLE) and WS_EX_TOOLWINDOW = 0) then<br>&nbsp; &nbsp; begin<br>&nbsp; &nbsp; &nbsp; ShowWinNoAnimate(Wnd, SW_MINIMIZE);<br>&nbsp; &nbsp; end;<br>&nbsp; end;<br>var<br>&nbsp; Param : Longint;<br>begin<br>&nbsp; Param := 0;<br>&nbsp; EnumWindows(@EnumWindowsProc , Param);<br>&nbsp; SetForegroundWindow(FindWindow(PChar('ProgMan'), nil));<br>&nbsp; SetActiveWindow(FindWindow(PChar('ProgMan'), nil));<br>end;
 
一句即可,何必那么麻烦?<br>winexec(Pchar('rundll32 user,tilechildwindows'),sw_show);
 
To sfj:<br>&nbsp; &nbsp;你的那句我在win2000下没能起作用
 
To 坏蟑螂:<br>&nbsp; &nbsp;不好意思,我是初学者,能否给出代码?谢谢!
 
就和按下任务栏的显示桌面一样的效果吧!win键+M键就可以实现了!
 
To SuperJS:<br>&nbsp; &nbsp;你说的我当然也知道,我是问在程序中如何实现!
 
这个过程没问题<br>procedure MinimizeAll; <br>var h:HWnd; <br>begin <br>&nbsp; h:=handle; <br>&nbsp; while h &gt; 0 do <br>&nbsp; begin <br>&nbsp; &nbsp; if IsWindowVisible(h) then <br>&nbsp; &nbsp; Postmessage(h,WM_SYSCOMMAND,SC_MINIMIZE,0); <br>&nbsp; &nbsp; h:=GetnextWindow(h,GW_HWNDNEXT); <br>&nbsp; end; <br>end;<br>
 
PostMessage(HWND_BROADCAST, WM_SYSCOMMAND, SC_MINIMIZE, 0);<br>试试这个,知道会怎么样吗?<br>哈哈!太好玩了。<br>别学我啊!!!<br><br>正确的做法应该是枚举Application(而不是Window),<br>再发Hide消息,而不是Minimize。<br><br>
 
最简单的办法就是模拟WIN+M啦 [:D]<br>什么PostMessage, 枚举窗口都免了<br><br>procedure TForm2.Button1Click(Sender: TObject);<br>&nbsp; procedure PerformKeyboardEvent(bVk, bScan: Byte; Flags,<br>&nbsp; &nbsp; ExtraInfo: LongWord);<br>&nbsp; var<br>&nbsp; &nbsp; sk: Word;<br>&nbsp; &nbsp; dwExtraInfo: Longint;<br>&nbsp; begin<br>&nbsp; &nbsp; sk := MapVirtualKey(bVk, 0);<br>&nbsp; &nbsp; dwExtraInfo := (sk shl 8) + 1;<br>&nbsp; &nbsp; keybd_event(bVk, sk, Flags, dwExtraInfo);<br>&nbsp; end;<br>begin<br>&nbsp; PerformKeyboardEvent(VK_LWIN, 0, 0, 0);<br>&nbsp; PerformKeyboardEvent(vkKeyScan('M'), 0, 0, 0);<br>&nbsp; PerformKeyboardEvent(VK_LWIN, 0, KEYEVENTF_KEYUP, 0);<br>&nbsp; PerformKeyboardEvent(vkKeyScan('M'), 0, KEYEVENTF_KEYUP, 0);<br>end;<br>
 
&nbsp; 谢谢大家,不好意思,不够大家分,看在我分数已经不多的份上,请大家莫见怪
 

Similar threads

S
回复
0
查看
3K
SUNSTONE的Delphi笔记
S
S
回复
0
查看
2K
SUNSTONE的Delphi笔记
S
D
回复
0
查看
911
DelphiTeacher的专栏
D
D
回复
0
查看
868
DelphiTeacher的专栏
D
后退
顶部