免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 4293 | 回复: 0

应用程序窗口嵌入桌面 [复制链接]

论坛徽章:
0
发表于 2010-11-24 20:29 |显示全部楼层
Ap的窗口可以嵌入桌面,这样Win+D键的时候就可以看到,很方便。在网上搜索了一下,原理就是将窗口的父窗口设置成桌面。
这个父窗口在Xp下通过FindWindow("rogram manager","progman"找到,但是在win7下这个方法找到的父窗口就不好用了。用spy++看了之后,写了下面一段代码findDesktopIconWnd(),在xp和win7下都可以找到这个父窗口。子窗口再调用SetParent(child,parent)就可以在桌面上看到了。

main.cpp
#include <windows.h>

#include <QtCore>

#include <QtGui/QApplication>
#include "dialog.h"
static BOOL enumUserWindowsCB(HWND hwnd,LPARAM lParam)
{
long wflags = GetWindowLong(hwnd, GWL_STYLE);
if(!(wflags & WS_VISIBLE)) return TRUE;
HWND sndWnd;
if( !(sndWnd=FindWindowEx(hwnd, NULL, L"SHELLDLL_DefView", NULL)) ) return TRUE;
HWND targetWnd;
if( !(targetWnd=FindWindowEx(sndWnd, NULL, L"SysListView32", L"FolderView") ) return TRUE;
HWND* resultHwnd = (HWND*)lParam;
*resultHwnd = targetWnd;
return FALSE;
}
HWND findDesktopIconWnd()
{
HWND resultHwnd = NULL;
EnumWindows((WNDENUMPROC)enumUserWindowsCB, (LPARAM)&resultHwnd);
return resultHwnd;
}
int main(int argc,char *argv[])
{
QApplication a(argc,argv);
Dialog w;
HWND desktopHwnd = findDesktopIconWnd();
//HWND desktopHwnd = FindWindow();
if (desktopHwnd)
SetParent(w.winId(),desktopHwnd);
w.setAttribute(Qt::WA_TranslucentBackground,true);
w.show();
return a.exec();
}
dialog.cpp
#include "dialog.h"
Dialog:ialog(QWidget *parent)Dialog(parent)
{
//创建个LineEdit用来测试焦点
QLineEdit* le = new QLineEdit(this );
}
void Dialog::paintEvent(QPaintEvent *e)
{
QPainter p(this);
p.fillRect(this->rect(),QColor(0,0xff,0,30));
}
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP