xp桌面图标上怎么实现像windows7一样一点就有方块?(愿意追加更多分数)
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了xp桌面图标上怎么实现像windows7一样一点就有方块?(愿意追加更多分数)相关的知识,希望对你有一定的参考价值。
xp桌面图标上怎么实现像windows7一样一点就有方块?(愿意追加)
还有就是我不想重装。
都仿了,但是就是这种效果仿不出来
追答那推荐你还是安装个win7吧 前提是你的配置跟得上就ok
参考技术C 采用360安全桌面,相信你一定会满意的!追问具体怎么做?
追答你有360安全卫士么?打开“功能大全”后,点击“360安全桌面”下载安装即可。
参考技术D 这个 只能下载win7主题吧~~ 暂时没有更好的办法了追问都下了,但是就是这种效果仿不出来
第5个回答 2011-11-04 XP的做出来很难看并达不到7系统那样的界面效果。建议不要模拟window桌面实现
正在开发中的游戏有个全屏功能--可以在window桌面背景上运行,就像一些视频播放器在桌面背景上播放一样的,花了个上午整了个Demo放出来留个纪念。
实现功能:显示图标,双击图标执行相应的程序,右击图标弹出该图标对应得菜单,点击非图标区则弹出桌面菜单。需要完整工程可以点此下载:DesktopWindow.rar。程序效果图如下:
在这个程序里,定义了一个XShellItem的数据结构,保持桌面图标的iten id(ITEMIDLiST),图标以及文字图标。
struct XShellItem {
ITEMIDLIST* itemId;
int x;
int y;
int w;
int h;
int nameX;
int nameY;
int nameW;
int nameH;
BOOL hit;
CStringW name;
Bitmap* icon;
Bitmap* nameIcon;
XShellItem()
:
itemId(NULL),
x(0),
y(0),
w(0),
h(0),
nameX(0),
nameY(0),
nameW(0),
nameH(0),
name(L""),
hit(FALSE),
icon(NULL),
nameIcon(NULL) {
}
~XShellItem() {
}
};
ITEMIDLIST* itemId;
int x;
int y;
int w;
int h;
int nameX;
int nameY;
int nameW;
int nameH;
BOOL hit;
CStringW name;
Bitmap* icon;
Bitmap* nameIcon;
XShellItem()
:
itemId(NULL),
x(0),
y(0),
w(0),
h(0),
nameX(0),
nameY(0),
nameW(0),
nameH(0),
name(L""),
hit(FALSE),
icon(NULL),
nameIcon(NULL) {
}
~XShellItem() {
}
};
然后定义一个数组CAtlArray<XShellItem> itemArray;用来保存所有桌面图标对象,在InitShellFolder()中对它进行初始化:
// 获取桌面图标的相关数据
BOOL InitShellFolder()
{
HRESULT hRslt = SHGetDesktopFolder(&folder);
if (FAILED(hRslt)) {
return FALSE;
}
CComPtr<IEnumIDList> ids;
hRslt = folder->EnumObjects(0, SHCONTF_FOLDERS | SHCONTF_NONFOLDERS, &ids);
if (FAILED(hRslt)) {
return FALSE;
}
CAtlList<XShellItem> items;
for (;;) {
ITEMIDLIST* id = 0;
ULONG cIds = 0;
hRslt = ids->Next(1, &id, &cIds);
if (hRslt != S_OK) {
break;
}
CStringW name;
STRRET str = { 0};
hRslt = folder->GetDisplayNameOf(id, SHGDN_NORMAL | SHGDN_INFOLDER, &str);
if (SUCCEEDED(hRslt)) {
LPWSTR pname = 0;
StrRetToStrW(&str, id, &pname);
name = pname;
CoTaskMemFree(pname);
}
XShellItem item;
item.itemId = id;
item.name = name;
items.AddTail(item);
}
SIZE_T iItem = 0;
SIZE_T cItems = items.GetCount();
itemArray.SetCount(cItems);
POSITION pos = items.GetHeadPosition();
while (pos != 0) {
XShellItem& si = items.GetNext(pos);
itemArray[iItem] = si;
iItem++;
}
HDC hDC = CreateCompatibleDC(0);
Graphics g(hDC);
g.Clear(Color(0, 0, 0, 0));
ICONMETRICS im = { 0};
im.cbSize = sizeof(im);
SystemParametersInfo(SPI_GETICONMETRICS, sizeof(im), &im, 0);
SolidBrush br_t(Color(255, 255, 255));
Font font_i(hDC, &(im.lfFont));
float fcy = font_i.GetHeight(&g) * 2 + 2;
DeleteDC(hDC);
Gdiplus::StringFormat sf(Gdiplus::StringFormat::GenericTypographic());
sf.SetAlignment(Gdiplus::StringAlignmentCenter);
sf.SetTrimming(Gdiplus::StringTrimmingEllipsisWord);
iconSpacingWidth = im.iHorzSpacing + OFFSET_WIDTH;
iconSpacingHeight = im.iVertSpacing + OFFSET_HEIGHT;
int iconWidth = GetSystemMetrics(SM_CXICON);
int iconHeight = GetSystemMetrics(SM_CYICON);
for (SIZE_T i = 0; i < cItems; i++) {
XShellItem& item = itemArray[i];
// SHGetFileInfo
HICON hIcon = 0;
HIMAGELIST hImgList;
SHFILEINFO stSHFileInfo;
CImageList cImgList;
// 获取图标
hImgList = (HIMAGELIST)::SHGetFileInfo(
(LPCWSTR) item.itemId,
0,
&stSHFileInfo,
sizeof(SHFILEINFO),
SHGFI_PIDL | SHGFI_ICON | SHGFI_LARGEICON | SHGFI_SYSICONINDEX);
// DIBSection 8bit
BITMAPINFO bmi;
BITMAPINFOHEADER& bmih = bmi.bmiHeader;
bmih.biSize = sizeof(bmih);
bmih.biWidth = ICON_WIDTH;
bmih.biHeight = -ICON_HEIGHT; // BMP反转
bmih.biPlanes = 1;
bmih.biBitCount = 32;
bmih.biCompression = BI_RGB;
bmih.biSizeImage = 0;
bmih.biXPelsPerMeter = 0;
bmih.biYPelsPerMeter = 0;
bmih.biClrUsed = 0;
bmih.biClrImportant = 0;
HDC memDC = CreateCompatibleDC(0);
void* pDib = 0;
HBITMAP hBmp = CreateDIBSection(memDC, &bmi, DIB_RGB_COLORS, &pDib, 0, 0);
GdiFlush();
HGDIOBJ old = SelectObject(memDC, hBmp);
// ImageList_Draw WindowsXP
ImageList_SetBkColor(hImgList, 0x0);
ImageList_Draw(hImgList, stSHFileInfo.iIcon, memDC, 0, 0, ILD_NORMAL);
SelectObject(memDC, old);
DeleteDC(memDC);
cImgList.Attach(hImgList);
hIcon = cImgList.ExtractIcon(stSHFileInfo.iIcon);
cImgList.Detach();
if (hIcon != 0) {
// Bitmap::FromHICON 0~255
item.icon = Bitmap::FromHICON(hIcon);
item.w = iconWidth;
item.h = iconHeight;
Gdiplus::RectF rc(float(2), float(2), float(iconSpacingWidth - 4), fcy);
Gdiplus::Bitmap * nameIcon = new Bitmap(NAME_WIDTH, NAME_HEIGHT, &g);
Gdiplus::Graphics * g2 = Gdiplus::Graphics::FromImage(nameIcon);
g2->Clear(Gdiplus::Color(Gdiplus::ARGB(0)));
g2->DrawString(item.name, item.name.GetLength(), &font_i, rc, &sf, &br_t);
item.nameIcon = nameIcon;
item.nameW = NAME_WIDTH;
item.nameH = NAME_HEIGHT;
delete g2;
}
DestroyIcon(hIcon);
DeleteObject(hBmp);
DestroyIcon(stSHFileInfo.hIcon);
}
return TRUE;
}
BOOL InitShellFolder()
{
HRESULT hRslt = SHGetDesktopFolder(&folder);
if (FAILED(hRslt)) {
return FALSE;
}
CComPtr<IEnumIDList> ids;
hRslt = folder->EnumObjects(0, SHCONTF_FOLDERS | SHCONTF_NONFOLDERS, &ids);
if (FAILED(hRslt)) {
return FALSE;
}
CAtlList<XShellItem> items;
for (;;) {
ITEMIDLIST* id = 0;
ULONG cIds = 0;
hRslt = ids->Next(1, &id, &cIds);
if (hRslt != S_OK) {
break;
}
CStringW name;
STRRET str = { 0};
hRslt = folder->GetDisplayNameOf(id, SHGDN_NORMAL | SHGDN_INFOLDER, &str);
if (SUCCEEDED(hRslt)) {
LPWSTR pname = 0;
StrRetToStrW(&str, id, &pname);
name = pname;
CoTaskMemFree(pname);
}
XShellItem item;
item.itemId = id;
item.name = name;
items.AddTail(item);
}
SIZE_T iItem = 0;
SIZE_T cItems = items.GetCount();
itemArray.SetCount(cItems);
POSITION pos = items.GetHeadPosition();
while (pos != 0) {
XShellItem& si = items.GetNext(pos);
itemArray[iItem] = si;
iItem++;
}
HDC hDC = CreateCompatibleDC(0);
Graphics g(hDC);
g.Clear(Color(0, 0, 0, 0));
ICONMETRICS im = { 0};
im.cbSize = sizeof(im);
SystemParametersInfo(SPI_GETICONMETRICS, sizeof(im), &im, 0);
SolidBrush br_t(Color(255, 255, 255));
Font font_i(hDC, &(im.lfFont));
float fcy = font_i.GetHeight(&g) * 2 + 2;
DeleteDC(hDC);
Gdiplus::StringFormat sf(Gdiplus::StringFormat::GenericTypographic());
sf.SetAlignment(Gdiplus::StringAlignmentCenter);
sf.SetTrimming(Gdiplus::StringTrimmingEllipsisWord);
iconSpacingWidth = im.iHorzSpacing + OFFSET_WIDTH;
iconSpacingHeight = im.iVertSpacing + OFFSET_HEIGHT;
int iconWidth = GetSystemMetrics(SM_CXICON);
int iconHeight = GetSystemMetrics(SM_CYICON);
for (SIZE_T i = 0; i < cItems; i++) {
XShellItem& item = itemArray[i];
// SHGetFileInfo
HICON hIcon = 0;
HIMAGELIST hImgList;
SHFILEINFO stSHFileInfo;
CImageList cImgList;
// 获取图标
hImgList = (HIMAGELIST)::SHGetFileInfo(
(LPCWSTR) item.itemId,
0,
&stSHFileInfo,
sizeof(SHFILEINFO),
SHGFI_PIDL | SHGFI_ICON | SHGFI_LARGEICON | SHGFI_SYSICONINDEX);
// DIBSection 8bit
BITMAPINFO bmi;
BITMAPINFOHEADER& bmih = bmi.bmiHeader;
bmih.biSize = sizeof(bmih);
bmih.biWidth = ICON_WIDTH;
bmih.biHeight = -ICON_HEIGHT; // BMP反转
bmih.biPlanes = 1;
bmih.biBitCount = 32;
bmih.biCompression = BI_RGB;
bmih.biSizeImage = 0;
bmih.biXPelsPerMeter = 0;
bmih.biYPelsPerMeter = 0;
bmih.biClrUsed = 0;
bmih.biClrImportant = 0;
HDC memDC = CreateCompatibleDC(0);
void* pDib = 0;
HBITMAP hBmp = CreateDIBSection(memDC, &bmi, DIB_RGB_COLORS, &pDib, 0, 0);
GdiFlush();
HGDIOBJ old = SelectObject(memDC, hBmp);
// ImageList_Draw WindowsXP
ImageList_SetBkColor(hImgList, 0x0);
ImageList_Draw(hImgList, stSHFileInfo.iIcon, memDC, 0, 0, ILD_NORMAL);
SelectObject(memDC, old);
DeleteDC(memDC);
cImgList.Attach(hImgList);
hIcon = cImgList.ExtractIcon(stSHFileInfo.iIcon);
cImgList.Detach();
if (hIcon != 0) {
// Bitmap::FromHICON 0~255
item.icon = Bitmap::FromHICON(hIcon);
item.w = iconWidth;
item.h = iconHeight;
Gdiplus::RectF rc(float(2), float(2), float(iconSpacingWidth - 4), fcy);
Gdiplus::Bitmap * nameIcon = new Bitmap(NAME_WIDTH, NAME_HEIGHT, &g);
Gdiplus::Graphics * g2 = Gdiplus::Graphics::FromImage(nameIcon);
g2->Clear(Gdiplus::Color(Gdiplus::ARGB(0)));
g2->DrawString(item.name, item.name.GetLength(), &font_i, rc, &sf, &br_t);
item.nameIcon = nameIcon;
item.nameW = NAME_WIDTH;
item.nameH = NAME_HEIGHT;
delete g2;
}
DestroyIcon(hIcon);
DeleteObject(hBmp);
DestroyIcon(stSHFileInfo.hIcon);
}
return TRUE;
}
注意这里面并没有设置图标对象的位置,因为当窗口改变大小的时候,相应地也要调整图标的描绘位置,所以图标位置是在SetShellItemPosition()中动态调整的.
// 根据窗口大小设置图标位置
void SetShellItemPosition()
{
int iconWidth = GetSystemMetrics(SM_CXICON);
int iconHeight = GetSystemMetrics(SM_CYICON);
windows xp怎样将经常使用的程序像windows7那样放在快速启动栏下呢?
void SetShellItemPosition()
{
int iconWidth = GetSystemMetrics(SM_CXICON);
int iconHeight = GetSystemMetrics(SM_CYICON);
windows xp怎样将经常使用的程序像windows7那样放在快速启动栏下呢?
windows10如何把gif图片放在电脑桌面上,可以移动的,谢谢