请教:如何实现桌面级别的窗口平铺、层叠

邓学彬 2010-05-14 02:59:32
我想要实现的功能是类似任务栏、任务管理器上的功能,对桌面上的所有窗口进行排列(横向平铺、纵向平铺、层叠),功能和MDI程序里对子窗口的排列类似,但我要的不是自身的子窗口,是对桌面上的所有顶级窗口进行操作。

我现在的方法是先获取桌面的窗口句柄,然后发送消息,但不知道是我的方法错了还是消息错了,达不到想要的效果,请各位指教一下。
HWND hDesk=::GetDesktopWindow();//获取桌面的窗口句柄
::SendMessage(hDesk,WM_MDITILE,MDITILE_HORIZONTAL,0);//横向平铺
::SendMessage(hDesk,WM_MDITILE,MDITILE_VERTICAL,0);//纵向平铺
::SendMessage(hDesk,WM_MDICASCADE,0,0);//层叠


...全文
2542 10 打赏 收藏 转发到动态 举报
写回复
用AI写文章
10 条回复
切换为时间正序
请发表友善的回复…
发表回复
邓学彬 2010-05-14
  • 打赏
  • 举报
回复
[Quote=引用 9 楼 oysoft 的回复:]
在程序中调用windows外壳命令:

UINT nEventIds;
nEventIds=403; //ArrangeCascade
nEventIds=404; //ArrangeTileHrz
nEventIds=405; //ArrangeTileVrt
HWND hShellWnd = ::FindWindow(_T("Shell_TrayWnd"), NULL);
if(hShellWnd != NULL)
::PostMessage(hShellWnd, WM_COMMAND, MAKELONG(nEventIds, 0), NULL);
[/Quote]

感谢你的回复,可惜你在结贴后回复的,没法给你分了,抱歉。
oysoft 2010-05-14
  • 打赏
  • 举报
回复
在程序中调用windows外壳命令:

UINT nEventIds;
nEventIds=403; //ArrangeCascade
nEventIds=404; //ArrangeTileHrz
nEventIds=405; //ArrangeTileVrt
HWND hShellWnd = ::FindWindow(_T("Shell_TrayWnd"), NULL);
if(hShellWnd != NULL)
::PostMessage(hShellWnd, WM_COMMAND, MAKELONG(nEventIds, 0), NULL);
//其中selIndex选择前面对应数组序号
邓学彬 2010-05-14
  • 打赏
  • 举报
回复
[Quote=引用 3 楼 visualeleven 的回复:]
找了一下,有API函数可以实现:
TileWindows();
CascadeWindows();
[/Quote]

非常感谢,测试通过,结贴给分。

BOOL CMyDlg::OnCommand(WPARAM wParam, LPARAM lParam)
{
switch(wParam){
case IDM_ALL_HORIZONTAL:
::TileWindows(NULL,MDITILE_HORIZONTAL,NULL,NULL,NULL);
break;
case IDM_ALL_VERTICAL:
::TileWindows(NULL,MDITILE_VERTICAL,NULL,NULL,NULL);
break;
case IDM_ALL_CASCADING:
::CascadeWindows(NULL,NULL,NULL,NULL,NULL);
break;
}
return CDialog::OnCommand(wParam, lParam);
}
Eleven 2010-05-14
  • 打赏
  • 举报
回复
WORD CascadeWindows( HWND hwndParent,
UINT wHow,
const RECT *lpRect,
UINT cKids,
const HWND *lpKids
);
Parameters

hwndParent
[in] Handle to the parent window. If this parameter is NULL, the desktop window is assumed.
wHow
[in] Specifies a cascade flag. This parameter can be one or more of the following values.
MDITILE_SKIPDISABLED
Prevents disabled multiple-document interface (MDI) child windows from being cascaded.
MDITILE_ZORDER
Windows 2000/XP: Arranges the windows in Z order. If this value is not specified, the windows are arranged using the order specified in the lpKids array.
lpRect
[in] Pointer to a RECT structure that specifies the rectangular area, in client coordinates, within which the windows are arranged. This parameter can be NULL, in which case the client area of the parent window is used.
cKids
[in] Specifies the number of elements in the array specified by the lpKids parameter. This parameter is ignored if lpKids is NULL.
lpKids
[in] Pointer to an array of handles to the child windows to arrange. If this parameter is NULL, all child windows of the specified parent window (or of the desktop window) are arranged.
----------------------------------------------------------
调用:
CascadeWindows(NULL, MDITILE_HORIZONTAL, NULL, 0, NULL);
MoXiaoRab 2010-05-14
  • 打赏
  • 举报
回复
[Quote=引用 3 楼 visualeleven 的回复:]
找了一下,有API函数可以实现:
TileWindows();
CascadeWindows();
[/Quote]
Eleven 2010-05-14
  • 打赏
  • 举报
回复
WORD TileWindows( HWND hwndParent,
UINT wHow,
RECT *lpRect,
UINT cKids,
const HWND *lpKids
);
Parameters

hwndParent
[in] Handle to the parent window. If this parameter is NULL, the desktop window is assumed.
wHow
[in] Specifies tiling flags. This parameter can be one of the following values—optionally combined with MDITILE_SKIPDISABLED to prevent disabled multiple-document interface (MDI) child windows from being tiled.
MDITILE_HORIZONTAL
Tiles windows horizontally.
MDITILE_VERTICAL
Tiles windows vertically.
lpRect
[in] Pointer to a RECT structure that specifies the rectangular area, in client coordinates, within which the windows are arranged. If this parameter is NULL, the client area of the parent window is used.
cKids
[in] Specifies the number of elements in the array specified by the lpKids parameter. This parameter is ignored if lpKids is NULL.
lpKids
[in] Pointer to an array of handles to the child windows to arrange. If this parameter is NULL, all child windows of the specified parent window (or of the desktop window) are arranged.
----------------------------
调用:
TileWindows(NULL, MDITILE_HORIZONTAL, NULL, 0, NULL);
邓学彬 2010-05-14
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 visualeleven 的回复:]
有个山寨的方法,就是EnumWindows找到所有的窗口,然后SetWindowPos或者MoveWindow
[/Quote]

感谢你的回复,不过这个方法不太好吧?
理论上说,应该有这样的接口或消息的。继续期待其他答案。
Eleven 2010-05-14
  • 打赏
  • 举报
回复
找了一下,有API函数可以实现:
TileWindows();
CascadeWindows();
Eleven 2010-05-14
  • 打赏
  • 举报
回复
期待楼下兄弟更好的方法。。。
Eleven 2010-05-14
  • 打赏
  • 举报
回复
有个山寨的方法,就是EnumWindows找到所有的窗口,然后SetWindowPos或者MoveWindow

2,641

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC 硬件/系统
社区管理员
  • 硬件/系统社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧