Problem:
How do I activate the Active Desktop (active Desktop) in an application? In general, users can right-click on the desktop and choose Active Desktop =〉 "view by Web page" to turn on/off the Active Desktop feature. Is there a function that can be invoked in a program to implement operations on the Active Desktop? In addition, how do you determine that the user activates or cancels the Active Desktop?
Answer:
Before you answer this question, let me give you an important warning. That is, if you are going to switch Active Desktop features, please ensure that the user's permission! It's best to use large fonts to clearly show: "Do you really want to activate the Active Desktop?" "Without such a hint, it would be rude to the user," he said. Some users do not want a program to decide whether to start the Active Desktop. If the user really likes Web features and does not want to lose the Active Desktop. They will also tolerate the resulting decline in performance.
Well, so many stern warnings. Now suppose you have a good reason to turn on or off the Active Desktop. Maybe you're writing a new shell. To activate or cancel the Active Desktop, you need to use IActiveDesktop, which is a COM interface to the Active Desktop. The list of methods for this interface is listed below:
IActiveDesktop Interface Method Table
Method |
function and use |
Adddesktopitem |
Add a desktop item. |
Adddesktopitemwithui |
Use a user interface to add a desktop item to the Active Desktop. |
Addurl |
Adds a desktop item that is associated with the specified URL. |
Applychange |
Performs modifications to the Active Desktop. This function must be called to make the modification effective. Used to activate or cancel the Active Desktop. |
Generatedesktopitemhtml |
Produces a generic HTML page that contains a given desktop item. |
Getdesktopitem |
Gets the specified desktop item. |
Getdesktopitembyid |
Gets the desktop item that matches the given ID. |
Getdesktopitembysource |
Get a desktop item with the source URL. |
Getdesktopitemcount |
Or a count of desktop items. |
Getdesktopitemoptions |
Check to see if the Active Desktop is turned on or off. Shgetsettings performance is better. Used to activate or cancel the Active Desktop. |
Getpattern |
Gets the style that is currently in use. |
Getwallpaper |
Gets the wallpaper that is currently in use. For Active Desktop only. Standard mode (desktop shutdown), use SystemParametersInfo. |
Getwallpaperoptions |
Get wallpaper options. For Active Desktop only. Standard mode (desktop shutdown), use SystemParametersInfo. |
Modifydesktopitem |
Modify desktop items. |
Removedesktopitem |
Deletes the specified desktop item from the desktop. |
Setdesktopitemoptions |
Turns Active Desktop on or off. |
Setpattern |
Set the Active Desktop style. |
SetWallpaper |
Sets the Active Desktop wallpaper. For Active Desktop only. Standard mode (desktop shutdown), use SystemParametersInfo. |
Setwallpaperoptions |
Set wallpaper options. For Active Desktop only. Standard mode (desktop shutdown), use SystemParametersInfo. |
With IActiveDesktop, you can add and remove desktop items (HTML pages, images, URLs, or ActiveX controls), set up and get wallpaper (Active Desktop only, use the SystemParametersInfo function in standard mode), and other useful features. The function you can use to turn on or off the Active Desktop is setdesktopitemoptions. But first, consider-how do you get the IActiveDesktop interface? Create an instance using a method that typically uses COM:
//IActiveDesktop* pAD;
HRESULT hr = ::CoCreateInstance(
CLSID_ActiveDesktop,
NULL, // 不支持聚合,也就是说没有外部Unknown
CLSCTX_INPROC_SERVER,
IID_IActiveDesktop,
(void**)&pAD);
Don't forget to call CoInitialize in your startup code, such as the InitInstance function that MFC applies. Once you have the activedesktop pointer, you can call its method.
Activate Active Desktop
COMPONENTSOPT opt;
opt.dwSize = sizeof(opt);
opt.fActiveDesktop =
opt.fEnableComponents = TRUE;
HRESULT hr = pAD->SetDesktopItemOptions(&opt,0);