又是IActiveDesktop的用法,我只能给38分了,谁有例程吗?

iamshuke 2001-08-15 09:27:15
为什么编译时
IActiveDesktop * pActiveDesktop;
CoCreateInstance(CLSID_ActiveDesktop, NULL, CLSCTX_INPROC_SERVER,
IID_IActiveDesktop, (void**)&pActiveDesktop);没错,而一到pActiveDesktop->SetWallpaper()就出现如下错误呢?error C2027: use of undefined type 'IActiveDesktop'。
我装有Platform SDK(Windows 2000 Beta 3 RC)。谁有这样的例程,请给我一份. MAIL: henu@371.net。多谢了。
...全文
415 10 打赏 收藏 转发到动态 举报
写回复
用AI写文章
10 条回复
切换为时间正序
请发表友善的回复…
发表回复
iamshuke 2001-08-21
  • 打赏
  • 举报
回复
多谢众众,来信收到,问题已解决.
iamshuke 2001-08-20
  • 打赏
  • 举报
回复
yyz_xyz(众众)你好。源码给你发去了,请帮忙看一下,源码写的有问题,主要是因为本来我们公司是不能发信时带附件的(服务器装有什么软件,怕公司源码外泄),所以我今天只是随便写了一段试一下,没想到竟发出去了。不过这段代码多少还是能代表点问题的。对了,我发现#import"..\\Shell32.dll"在98下不可用,说什么装入失败, 2000下可以。
yyz_xyz 2001-08-20
  • 打赏
  • 举报
回复
为了你这个问题,可真把我累坏了,在看到shlobj.h时,还以为定义宏_WINNINET,不过试过之后也不行。

请在你的Afxstd.h文件后面中加入#import "D:\\winnt\\system32\\Shell32.dll"。当然要换成你的Shell32.dll所在路径了。到于shlobj.h头文件则要不要都可以了。反正我是不要它了!

如果还不行,把源码发到我的信箱让我看一下:
xyz.yyz@yeah.net
iamshuke 2001-08-20
  • 打赏
  • 举报
回复
惨惨惨,为了多给这道题加分,我把我的参与分都换成可用分了,我还以为可用分越多能给的分就越多呢,谁知会是这样。短期内是不能加分了,不过还望各位大侠继续努力呀!!!
iamshuke 2001-08-19
  • 打赏
  • 举报
回复
不是的、不是的、不是的。现在不是使用中的问题,而是根本连 编译 都通不过, 就像是在使用一个未知的数据类型。好像是少了什么头文件,我包含了以下头文件,可还是不行。它X的,不会是操作系统的问题吧? 遇到这种现象的可不只我一个人。还望各位大侠指点迷津。

#include <atlconv.h>
#include <windows.h>
#include <WININET.H >
#include <afxdisp.h>
#include <comcat.h>
#include <olectl.h>

#include <shellapi.h>
#include <comdef.h>
#include <shlobj.h>


prog_st 2001-08-18
  • 打赏
  • 举报
回复

Using the Active Desktop Object
This article contains information on the ActiveDesktop object that is part of the Microsoft® Windows® Shell API. This object, through its IActiveDesktop interface, enables you to add, remove, and change items on the desktop.

Overview of the Active Desktop Interface
The Active Desktop is a feature of Microsoft Internet Explorer 4.0 that enables you to include HTML documents and items (such as ActiveX® Controls and Java applets) directly to your desktop. The IActiveDesktop interface, which is part of the Windows Shell API, is used to programmatically add, remove, and modify the items on the desktop. Active Desktop items can also be added using a Channel Definition Format (CDF) file.

Accessing the Active Desktop
To access the Active Desktop, a client application would need to create an instance of the ActiveDesktop object (CLSID_ActiveDesktop) with the CoCreateInstance function and retrieve a pointer to the object's IActiveDesktop interface.

The following sample shows how to retrieve a pointer to the IActiveDesktop interface.

HRESULT hr;
IActiveDesktop *pActiveDesktop;

//Create an instance of the Active Desktop
hr = CoCreateInstance(CLSID_ActiveDesktop, NULL, CLSCTX_INPROC_SERVER,
IID_IActiveDesktop, (void**)&pActiveDesktop);

//Insert code to call the IActiveDesktop methods

// Call the Release method
pActiveDesktop->Release();


Adding a Desktop Item
There are three methods you can use to add a desktop item: IActiveDesktop::AddDesktopItem, IActiveDesktop::AddDesktopItemWithUI, and IActiveDesktop::AddUrl. Each desktop item added to the Active Desktop must have a different source URL.

The IActiveDesktop::AddDesktopItemWithUI and IActiveDesktop::AddUrl both provide the option to display the various user interfaces that can be displayed before adding a desktop item to the Active Desktop. The interfaces verify whether users want to add the desktop item to their Active Desktop. The interfaces also notify users of any security risks that are warranted by the URL security zone settings, and they ask users if they would like to create a subscription for this desktop item. Both methods also provide a way of suppressing the user interfaces. The IActiveDesktop::AddDesktopItem method requires a call to IActiveDesktop::ApplyChanges in order to update the registry. For the IActiveDesktop::AddDesktopItemWithUI, the client application must immediately release the IActiveDesktop interface and then use the CoCreateInstance function to retrieve an interface to an instance of the ActiveDesktop object that includes the newly added desktop item.

The IActiveDesktop::AddDesktopItem method adds the specified desktop item to the Active Desktop without any user interface, unless the URL security zone settings prevent it. If the URL security zone settings do not allow the desktop item to be added without prompting the user, the method fails. IActiveDesktop::AddDesktopItem also requires a call to IActiveDesktop::ApplyChanges in order to update the registry.

The following sample demonstrates how to add a desktop item with the IActiveDesktop::AddDesktopItem method.

HRESULT hr;
IActiveDesktop *pActiveDesktop;
COMPONENT compDesktopItem;

//Create an instance of the Active Desktop
hr = CoCreateInstance(CLSID_ActiveDesktop, NULL, CLSCTX_INPROC_SERVER,
IID_IActiveDesktop, (void**)&pActiveDesktop);

// Initialize the COMPONENT structure
compDesktopItem.dwSize = sizeof(COMPONENT);

// Insert code that adds the information about the desktop item to the COMPONENT structure

// Add the desktop item
pActiveDesktop->AddDesktopItem(&compDesktopItem,0);

// Save the changes to the registry
pActiveDesktop->ApplyChanges(AD_APPLY_ALL);

Enumerating the Desktop Items
To enumerate the desktop items currently installed on the Active Desktop, the client application needs to retrieve the total number of desktop items installed using the IActiveDesktop::GetDesktopItemCount method and then creating a loop that retrieves the COMPONENT structure for each desktop item by calling the IActiveDesktop::GetDesktopItem method using the desktop item index.

The following sample demonstrates one way to enumerate the desktop items.

HRESULT hr;
IActiveDesktop *pActiveDesktop;
COMPONENT compDesktopItem;
int intCount;
int intIndex = 0;

//Create an instance of the Active Desktop
hr = CoCreateInstance(CLSID_ActiveDesktop, NULL, CLSCTX_INPROC_SERVER,
IID_IActiveDesktop, (void**)&pActiveDesktop);

pActiveDesktop->GetDesktopItemCount(&intCount,0);

compDesktopItem.dwSize = sizeof(COMPONENT);

while(intIndex<=(intCount-1))
{
//get the COMPONENT structure for the current desktop item
pActiveDesktop->GetDesktopItem(intIndex, &compDesktopItem,0);

//Insert code that processes the structure

//Increment the index
intIndex++;

//Insert code to clean-up structure for next component
}

// Call the Release method
pActiveDesktop->Release();

///////////////////////////////////////////////////////////////////////
Requirements
Version 4.71 and later of Shell32.dll

Windows NT/2000: Requires Windows 2000 (or Windows NT 4.0 with Internet Explorer 4.0 or later).
Windows 95/98/Me: Requires Windows 98 (or Windows 95 with Internet Explorer 4.0 or later).
Header: Declared in Shlobj.h.
///////////////////////////////////////////////////////////////////////
iamshuke 2001-08-18
  • 打赏
  • 举报
回复
ddeng, 不是的, 我根本连编译都通不过。提示说未知类型'IActiveDesktop', 可是奇怪的是为什么定义时不报错,而到使用时就报错了呢?如果是未知数据类型,应该定义时就通不过了呀,我在网上见到有人问过这样的问题,现象和我是一样的。真是百思不得其解,急死人了。对了,你哪个Shlobj是个什么东东?我#include<Shlobj.h>后还说是未知类型。如果你能给我一个能正常编译通过的例程,可就真是救我(和其他弟兄们)于水深火热之中了。多谢了!拜托了!
ddeng 2001-08-16
  • 打赏
  • 举报
回复
检查一下CoCreateInstance的返回结果,看CoCreateInstance是否成功:

IActiveDesktop* pIADesk = NULL;
HRESULT hr = ::CoCreateInstance(Shlobj::CLSID_ActiveDesktop,
NULL,
CLSCTX_INPROC_SERVER,
IID_IActiveDesktop,
(void**)&pIADesk);
if(SUCCEEDED(hr)) {
pIADesk->SetWallpaper(FileName, 0);
pIADesk->ApplyChanges(AD_APPLY_ALL|AD_APPLY_FORCE);
pIADesk->Release();
}
ddeng 2001-08-16
  • 打赏
  • 举报
回复
检查一下CoCreateInstance的返回结果,看CoCreateInstance是否成功:

IActiveDesktop* pIADesk = NULL;
HRESULT hr = ::CoCreateInstance(Shlobj::CLSID_ActiveDesktop,
NULL,
CLSCTX_INPROC_SERVER,
IID_IActiveDesktop,
(void**)&pIADesk);
if(SUCCEEDED(hr)) {
pIADesk->SetWallpaper(FileName, 0);
pIADesk->ApplyChanges(AD_APPLY_ALL|AD_APPLY_FORCE);
pIADesk->Release();
}
iamshuke 2001-08-16
  • 打赏
  • 举报
回复
救命啊!!!!!!!!

16,472

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC相关问题讨论
社区管理员
  • 基础类社区
  • Web++
  • encoderlee
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

        VC/MFC社区版块或许是CSDN最“古老”的版块了,记忆之中,与CSDN的年龄几乎差不多。随着时间的推移,MFC技术渐渐的偏离了开发主流,若干年之后的今天,当我们面对着微软的这个经典之笔,内心充满着敬意,那些曾经的记忆,可以说代表着二十年前曾经的辉煌……
        向经典致敬,或许是老一代程序员内心里面难以释怀的感受。互联网大行其道的今天,我们期待着MFC技术能够恢复其曾经的辉煌,或许这个期待会永远成为一种“梦想”,或许一切皆有可能……
        我们希望这个版块可以很好的适配Web时代,期待更好的互联网技术能够使得MFC技术框架得以重现活力,……

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